Skip to content

Commit 949c8ee

Browse files
andrewseguinAndrew Seguin
andauthored
fix(multiple): allow ids to be inputs (angular#32320)
Co-authored-by: Andrew Seguin <[email protected]>
1 parent f446992 commit 949c8ee

File tree

7 files changed

+13
-26
lines changed

7 files changed

+13
-26
lines changed

src/aria/accordion/accordion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class AccordionPanel {
7171
private readonly _deferredContentAware = inject(DeferredContentAware);
7272

7373
/** A global unique identifier for the panel. */
74-
private readonly _id = inject(_IdGenerator).getId('accordion-trigger-', true);
74+
readonly id = input(inject(_IdGenerator).getId('ng-accordion-panel-', true));
7575

7676
/** A local unique identifier for the panel, used to match with its trigger's `panelId`. */
7777
readonly panelId = input.required<string>();
@@ -85,7 +85,7 @@ export class AccordionPanel {
8585

8686
/** The UI pattern instance for this panel. */
8787
readonly _pattern: AccordionPanelPattern = new AccordionPanelPattern({
88-
id: () => this._id,
88+
id: this.id,
8989
panelId: this.panelId,
9090
accordionTrigger: () => this.accordionTrigger(),
9191
});
@@ -153,7 +153,7 @@ export class AccordionTrigger {
153153
private readonly _accordionGroup = inject(AccordionGroup);
154154

155155
/** A unique identifier for the widget. */
156-
readonly id = input<string>(inject(_IdGenerator).getId('ng-accordion-trigger-', true));
156+
readonly id = input(inject(_IdGenerator).getId('ng-accordion-trigger-', true));
157157

158158
/** The host native element. */
159159
readonly element = computed(() => this._elementRef.nativeElement);

src/aria/grid/grid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export class GridCellWidget {
376376
readonly element = computed(() => this._elementRef.nativeElement);
377377

378378
/** A unique identifier for the widget. */
379-
readonly id = input<string>(inject(_IdGenerator).getId('ng-grid-cell-', true));
379+
readonly id = input(inject(_IdGenerator).getId('ng-grid-cell-widget-', true));
380380

381381
/** The type of widget, which determines how it is activated. */
382382
readonly widgetType = input<'simple' | 'complex' | 'editable'>('simple');

src/aria/listbox/listbox.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ import {ComboboxPopup} from '../combobox';
6565
})
6666
export class Listbox<V> {
6767
/** A unique identifier for the listbox. */
68-
private readonly _generatedId = inject(_IdGenerator).getId('ng-listbox-', true);
69-
70-
// TODO(wagnermaciel): https://github.com/angular/components/pull/30495#discussion_r1972601144.
71-
/** A unique identifier for the listbox. */
72-
protected id = computed(() => this._generatedId);
68+
readonly id = input(inject(_IdGenerator).getId('ng-listbox-', true));
7369

7470
/** A reference to the parent combobox popup, if one exists. */
7571
private readonly _popup = inject<ComboboxPopup<V>>(ComboboxPopup, {
@@ -246,11 +242,7 @@ export class Option<V> {
246242
private readonly _listbox = inject(Listbox);
247243

248244
/** A unique identifier for the option. */
249-
private readonly _generatedId = inject(_IdGenerator).getId('ng-option-', true);
250-
251-
// TODO(wagnermaciel): https://github.com/angular/components/pull/30495#discussion_r1972601144.
252-
/** A unique identifier for the option. */
253-
protected id = computed(() => this._generatedId);
245+
readonly id = input(inject(_IdGenerator).getId('ng-option-', true));
254246

255247
// TODO(wagnermaciel): See if we want to change how we handle this since textContent is not
256248
// reactive. See https://github.com/angular/components/pull/30495#discussion_r1961260216.

src/aria/menu/menu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class Menu<V> {
187187
readonly textDirection = inject(Directionality).valueSignal;
188188

189189
/** The unique ID of the menu. */
190-
readonly id = input<string>(inject(_IdGenerator).getId('ng-menu-', true));
190+
readonly id = input(inject(_IdGenerator).getId('ng-menu-', true));
191191

192192
/** Whether the menu should wrap its items. */
193193
readonly wrap = input(true, {transform: booleanAttribute});
@@ -423,7 +423,7 @@ export class MenuItem<V> {
423423
readonly element: HTMLElement = this._elementRef.nativeElement;
424424

425425
/** The unique ID of the menu item. */
426-
readonly id = input<string>(inject(_IdGenerator).getId('ng-menu-item-', true));
426+
readonly id = input(inject(_IdGenerator).getId('ng-menu-item-', true));
427427

428428
/** The value of the menu item. */
429429
readonly value = input.required<V>();

src/aria/tabs/tabs.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export class Tab implements HasElement, OnInit, OnDestroy {
298298
private readonly _tabList = inject(TabList);
299299

300300
/** A unique identifier for the widget. */
301-
readonly id = input<string>(inject(_IdGenerator).getId('ng-tab-', true));
301+
readonly id = input(inject(_IdGenerator).getId('ng-tab-', true));
302302

303303
/** The host native element. */
304304
readonly element = computed(() => this._elementRef.nativeElement);
@@ -388,7 +388,7 @@ export class TabPanel implements OnInit, OnDestroy {
388388
private readonly _Tabs = inject(Tabs);
389389

390390
/** A global unique identifier for the tab. */
391-
private readonly _id = inject(_IdGenerator).getId('ng-tabpanel-', true);
391+
readonly id = input(inject(_IdGenerator).getId('ng-tabpanel-', true));
392392

393393
/** The Tab UIPattern associated with the tabpanel */
394394
readonly tab = computed(() =>
@@ -404,8 +404,6 @@ export class TabPanel implements OnInit, OnDestroy {
404404
/** The TabPanel UIPattern. */
405405
readonly _pattern: TabPanelPattern = new TabPanelPattern({
406406
...this,
407-
id: () => this._id,
408-
tab: this.tab,
409407
});
410408

411409
constructor() {

src/aria/toolbar/toolbar.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ export class ToolbarWidget<V> implements OnInit, OnDestroy {
198198
private readonly _toolbar = inject(Toolbar);
199199

200200
/** A unique identifier for the widget. */
201-
private readonly _generatedId = inject(_IdGenerator).getId('ng-toolbar-widget-', true);
202-
203-
/** A unique identifier for the widget. */
204-
readonly id = input<string>(this._generatedId);
201+
readonly id = input(inject(_IdGenerator).getId('ng-toolbar-widget-', true));
205202

206203
/** The parent Toolbar UIPattern. */
207204
readonly toolbar = computed(() => this._toolbar._pattern);

src/aria/tree/tree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class Tree<V> {
111111
private readonly _unorderedItems = signal(new Set<TreeItem<V>>());
112112

113113
/** A unique identifier for the tree. */
114-
readonly id = input<string>(inject(_IdGenerator).getId('ng-tree-', true));
114+
readonly id = input(inject(_IdGenerator).getId('ng-tree-', true));
115115

116116
/** The host native element. */
117117
readonly element = computed(() => this._elementRef.nativeElement);
@@ -278,7 +278,7 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
278278
private readonly _group = signal<TreeItemGroup<V> | undefined>(undefined);
279279

280280
/** A unique identifier for the tree item. */
281-
readonly id = input<string>(inject(_IdGenerator).getId('ng-tree-item-', true));
281+
readonly id = input(inject(_IdGenerator).getId('ng-tree-item-', true));
282282

283283
/** The host native element. */
284284
readonly element = computed(() => this._elementRef.nativeElement);

0 commit comments

Comments
 (0)