@@ -4,13 +4,16 @@ import {
44 Input ,
55 HostListener ,
66 Output ,
7- EventEmitter
7+ EventEmitter ,
8+ ElementRef ,
9+ OnInit ,
10+ Renderer2
811} from "@angular/core" ;
912
1013@Directive ( {
1114 selector : "[ibmContentOption]"
1215} )
13- export class ContentSwitcherOption {
16+ export class ContentSwitcherOption implements OnInit {
1417 /**
1518 * Used to activate the option. Only one option may be `active` at a time
1619 */
@@ -49,6 +52,8 @@ export class ContentSwitcherOption {
4952
5053 protected _active = false ;
5154
55+ constructor ( private renderer : Renderer2 , private hostElement : ElementRef ) { }
56+
5257 @HostListener ( "click" , [ "$event" ] )
5358 hostClick ( event : MouseEvent ) {
5459 this . onClick . emit ( event ) ;
@@ -66,4 +71,21 @@ export class ContentSwitcherOption {
6671 this . active = true ;
6772 this . selected . emit ( true ) ;
6873 }
74+
75+ /*
76+ * encapsulating the content in a span with bx--content-switcher__label class
77+ * to mimic what is done in the react version
78+ */
79+ ngOnInit ( ) : void {
80+ const hostNativeElement = ( this . hostElement . nativeElement as HTMLElement ) ;
81+ const spanWrapper = this . renderer . createElement ( "span" ) ;
82+ this . renderer . addClass ( spanWrapper , "bx--content-switcher__label" ) ;
83+ const hostChildren : ChildNode [ ] = [ ] ;
84+ hostNativeElement . childNodes . forEach ( node => hostChildren . push ( node ) ) ;
85+ hostChildren . forEach ( node => {
86+ this . renderer . removeChild ( hostNativeElement , node ) ;
87+ this . renderer . appendChild ( spanWrapper , node ) ;
88+ } ) ;
89+ this . renderer . appendChild ( hostNativeElement , spanWrapper ) ;
90+ }
6991}
0 commit comments