import { ChangeDetectionStrategy , Component , Inject , InjectionToken , Input , Optional , ViewEncapsulation , } from '@angular/core' ; import { CanDisable , mixinDisabled } from '../common-behaviors/disabled' ; import { SbbOptionParentComponent , SBB_OPTION_PARENT_COMPONENT } from './option-parent' ; const _SbbOptgroupMixinBase = mixinDisabled ( class { } ) ; let uniqueOptgroupIdCounter = 0 ; /**
 * Injection token that can be used to reference instances of `SbbOptgroup`. It serves as
 * alternative token to the actual `SbbOptgroup` class which could cause unnecessary
 * retention of the class and its component metadata.
 */ export const SBB_OPTGROUP = new InjectionToken < SbbOptgroup > ( 'SbbOptgroup' ) ; @ Component ( { selector : 'sbb-optgroup' , exportAs : 'sbbOptgroup' , templateUrl : './optgroup.html' , encapsulation : ViewEncapsulation . None , changeDetection : ChangeDetectionStrategy . OnPush , inputs : [ 'disabled' ] , host : { class : 'sbb-optgroup sbb-menu-group' , '[attr.role]' : '_inert ? null : "group"' , '[attr.aria-disabled]' : '_inert ? null : disabled.toString()' , '[attr.aria-labelledby]' : '_inert ? null : _labelId' , '[class.sbb-disabled]' : 'disabled' , } , providers : [ { provide : SBB_OPTGROUP , useExisting : SbbOptgroup } ] , } ) export class SbbOptgroup extends _SbbOptgroupMixinBase implements CanDisable { /** Label for the option group. */ @ Input ( ) label : string ; /** Unique id for the underlying label. */ _labelId : string = `sbb-optgroup-label-${ uniqueOptgroupIdCounter ++ }` ; /** Whether the group is in inert a11y mode. */ _inert : boolean ; constructor ( @ Inject ( SBB_OPTION_PARENT_COMPONENT ) @ Optional ( ) parent ? ) { super ( ) ; this . _inert = parent ?. inertGroups ?? false ; } }