@@ -13,8 +13,16 @@ import { ContentSwitcherOption } from "./content-switcher-option.directive";
1313import { isFocusInLastItem , isFocusInFirstItem } from "./../common/tab.service" ;
1414
1515/**
16+ * The content switcher can be used for toggling between distinct options.
17+ * Similar to tabs, but without an associated content panel
1618 *
17- *
19+ * ```html
20+ * <ibm-content-switcher (selected)="selected($event)">
21+ * <button ibmContentOption>First section</button>
22+ * <button ibmContentOption>Second section</button>
23+ * <button ibmContentOption>Third section</button>
24+ * </ibm-content-switcher>
25+ * ```
1826 */
1927@Component ( {
2028 selector : "ibm-content-switcher" ,
@@ -28,16 +36,27 @@ import { isFocusInLastItem, isFocusInFirstItem } from "./../common/tab.service";
2836 `
2937} )
3038export class ContentSwitcher implements AfterViewInit {
39+ /**
40+ * aria-label for the content switcher. Should be set to something descriptive
41+ */
3142 @Input ( ) label = "content switcher" ;
3243
44+ /**
45+ * Emits the activated `ContentSwitcherOption`
46+ */
3347 @Output ( ) selected = new EventEmitter ( ) ;
3448
3549 @ContentChildren ( ContentSwitcherOption ) options : QueryList < ContentSwitcherOption > ;
3650
3751 constructor ( protected elementRef : ElementRef ) { }
3852
3953 ngAfterViewInit ( ) {
40- this . options . first . active = true ;
54+ const firstActive = this . options . find ( option => option . active ) ;
55+ // delay setting active until the DOM has settled
56+ if ( ! firstActive ) {
57+ setTimeout ( ( ) => this . options . first . active = true ) ;
58+ }
59+ // subscribe to each item, emit when one is selected, and reset the active states
4160 this . options . forEach ( option => {
4261 option . selected . subscribe ( _ => {
4362 const active = option ;
@@ -53,7 +72,7 @@ export class ContentSwitcher implements AfterViewInit {
5372
5473 @HostListener ( "keydown" , [ "$event" ] )
5574 hostkeys ( event : KeyboardEvent ) {
56- const buttonList = Array . from < any > ( this . elementRef . nativeElement . querySelectorAll ( ".bx--content-switcher-btn " ) ) ;
75+ const buttonList = Array . from < any > ( this . elementRef . nativeElement . querySelectorAll ( "[ibmContentOption] " ) ) ;
5776
5877 switch ( event . key ) {
5978 case "Right" : // IE specific value
0 commit comments