/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { UniqueSelectionDispatcher } from '@angular/cdk/collections'; import { Directive, inject } from '@angular/core'; import { CdkMenuItemSelectable } from './menu-item-selectable'; import { CdkMenuItem } from './menu-item'; import * as i0 from "@angular/core"; /** Counter used to set a unique id and name for a selectable item */ let nextId = 0; /** * A directive providing behavior for the "menuitemradio" ARIA role, which behaves similarly to * a conventional radio-button. Any sibling `CdkMenuItemRadio` instances within the same `CdkMenu` * or `CdkMenuGroup` comprise a radio group with unique selection enforced. */ export class CdkMenuItemRadio extends CdkMenuItemSelectable { constructor() { super(); /** The unique selection dispatcher for this radio's `CdkMenuGroup`. */ this._selectionDispatcher = inject(UniqueSelectionDispatcher); /** An ID to identify this radio item to the `UniqueSelectionDispatcher`. */ this._id = `${nextId++}`; this._registerDispatcherListener(); } ngOnDestroy() { super.ngOnDestroy(); this._removeDispatcherListener(); } /** * Toggles the checked state of the radio-button. * @param options Options the configure how the item is triggered * - keepOpen: specifies that the menu should be kept open after triggering the item. */ trigger(options) { super.trigger(options); if (!this.disabled) { this._selectionDispatcher.notify(this._id, ''); } } /** Configure the unique selection dispatcher listener in order to toggle the checked state */ _registerDispatcherListener() { this._removeDispatcherListener = this._selectionDispatcher.listen((id) => { this.checked = this._id === id; }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuItemRadio, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkMenuItemRadio, isStandalone: true, selector: "[cdkMenuItemRadio]", host: { attributes: { "role": "menuitemradio" }, properties: { "class.cdk-menu-item-radio": "true" } }, providers: [ { provide: CdkMenuItemSelectable, useExisting: CdkMenuItemRadio }, { provide: CdkMenuItem, useExisting: CdkMenuItemSelectable }, ], exportAs: ["cdkMenuItemRadio"], usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuItemRadio, decorators: [{ type: Directive, args: [{ selector: '[cdkMenuItemRadio]', exportAs: 'cdkMenuItemRadio', standalone: true, host: { 'role': 'menuitemradio', '[class.cdk-menu-item-radio]': 'true', }, providers: [ { provide: CdkMenuItemSelectable, useExisting: CdkMenuItemRadio }, { provide: CdkMenuItem, useExisting: CdkMenuItemSelectable }, ], }] }], ctorParameters: function () { return []; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS1pdGVtLXJhZGlvLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9tZW51L21lbnUtaXRlbS1yYWRpby50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMseUJBQXlCLEVBQUMsTUFBTSwwQkFBMEIsQ0FBQztBQUNuRSxPQUFPLEVBQUMsU0FBUyxFQUFFLE1BQU0sRUFBWSxNQUFNLGVBQWUsQ0FBQztBQUMzRCxPQUFPLEVBQUMscUJBQXFCLEVBQUMsTUFBTSx3QkFBd0IsQ0FBQztBQUM3RCxPQUFPLEVBQUMsV0FBVyxFQUFDLE1BQU0sYUFBYSxDQUFDOztBQUV4QyxxRUFBcUU7QUFDckUsSUFBSSxNQUFNLEdBQUcsQ0FBQyxDQUFDO0FBRWY7Ozs7R0FJRztBQWNILE1BQU0sT0FBTyxnQkFBaUIsU0FBUSxxQkFBcUI7SUFVekQ7UUFDRSxLQUFLLEVBQUUsQ0FBQztRQVZWLHVFQUF1RTtRQUN0RCx5QkFBb0IsR0FBRyxNQUFNLENBQUMseUJBQXlCLENBQUMsQ0FBQztRQUUxRSw0RUFBNEU7UUFDcEUsUUFBRyxHQUFHLEdBQUcsTUFBT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