Skip to content

Commit d8841fc

Browse files
committed
refactor(multiple): make patterns instance private
Makes the instance of the UI pattern private in the Aria components. Note that we can't actually mark them as `private`, because they're referenced between components.
1 parent 2f6da55 commit d8841fc

File tree

38 files changed

+282
-289
lines changed

38 files changed

+282
-289
lines changed

src/aria/accordion/accordion.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ import {
4444
host: {
4545
'class': 'ng-accordion-panel',
4646
'role': 'region',
47-
'[attr.id]': 'pattern.id()',
48-
'[attr.aria-labelledby]': 'pattern.accordionTrigger()?.id()',
49-
'[attr.inert]': 'pattern.hidden() ? true : null',
47+
'[attr.id]': '_pattern.id()',
48+
'[attr.aria-labelledby]': '_pattern.accordionTrigger()?.id()',
49+
'[attr.inert]': '_pattern.hidden() ? true : null',
5050
},
5151
})
5252
export class AccordionPanel {
@@ -64,7 +64,7 @@ export class AccordionPanel {
6464
signal(undefined);
6565

6666
/** The UI pattern instance for this panel. */
67-
readonly pattern: AccordionPanelPattern = new AccordionPanelPattern({
67+
readonly _pattern: AccordionPanelPattern = new AccordionPanelPattern({
6868
id: () => this._id,
6969
value: this.value,
7070
accordionTrigger: () => this.accordionTrigger(),
@@ -73,7 +73,7 @@ export class AccordionPanel {
7373
constructor() {
7474
// Connect the panel's hidden state to the DeferredContentAware's visibility.
7575
afterRenderEffect(() => {
76-
this._deferredContentAware.contentVisible.set(!this.pattern.hidden());
76+
this._deferredContentAware.contentVisible.set(!this._pattern.hidden());
7777
});
7878
}
7979
}
@@ -87,17 +87,17 @@ export class AccordionPanel {
8787
exportAs: 'ngAccordionTrigger',
8888
host: {
8989
'class': 'ng-accordion-trigger',
90-
'[attr.data-active]': 'pattern.active()',
90+
'[attr.data-active]': '_pattern.active()',
9191
'role': 'button',
92-
'[id]': 'pattern.id()',
93-
'[attr.aria-expanded]': 'pattern.expanded()',
94-
'[attr.aria-controls]': 'pattern.controls()',
95-
'[attr.aria-disabled]': 'pattern.disabled()',
92+
'[id]': '_pattern.id()',
93+
'[attr.aria-expanded]': '_pattern.expanded()',
94+
'[attr.aria-controls]': '_pattern.controls()',
95+
'[attr.aria-disabled]': '_pattern.disabled()',
9696
'[attr.disabled]': 'hardDisabled() ? true : null',
97-
'[attr.tabindex]': 'pattern.tabindex()',
98-
'(keydown)': 'pattern.onKeydown($event)',
99-
'(pointerdown)': 'pattern.onPointerdown($event)',
100-
'(focusin)': 'pattern.onFocus($event)',
97+
'[attr.tabindex]': '_pattern.tabindex()',
98+
'(keydown)': '_pattern.onKeydown($event)',
99+
'(pointerdown)': '_pattern.onPointerdown($event)',
100+
'(focusin)': '_pattern.onFocus($event)',
101101
},
102102
})
103103
export class AccordionTrigger {
@@ -121,18 +121,18 @@ export class AccordionTrigger {
121121
*
122122
* TODO(ok7sai): Consider move this to UI patterns.
123123
*/
124-
readonly hardDisabled = computed(() => this.pattern.disabled() && this.pattern.tabindex() < 0);
124+
readonly hardDisabled = computed(() => this._pattern.disabled() && this._pattern.tabindex() < 0);
125125

126126
/** The accordion panel pattern controlled by this trigger. This is set by AccordionGroup. */
127127
readonly accordionPanel: WritableSignal<AccordionPanelPattern | undefined> = signal(undefined);
128128

129129
/** The UI pattern instance for this trigger. */
130-
readonly pattern: AccordionTriggerPattern = new AccordionTriggerPattern({
130+
readonly _pattern: AccordionTriggerPattern = new AccordionTriggerPattern({
131131
id: () => this._id,
132132
value: this.value,
133133
disabled: this.disabled,
134134
element: () => this._elementRef.nativeElement,
135-
accordionGroup: computed(() => this._accordionGroup.pattern),
135+
accordionGroup: computed(() => this._accordionGroup._pattern),
136136
accordionPanel: this.accordionPanel,
137137
});
138138
}
@@ -177,12 +177,12 @@ export class AccordionGroup {
177177
wrap = input(false, {transform: booleanAttribute});
178178

179179
/** The UI pattern instance for this accordion group. */
180-
readonly pattern: AccordionGroupPattern = new AccordionGroupPattern({
180+
readonly _pattern: AccordionGroupPattern = new AccordionGroupPattern({
181181
...this,
182182
// TODO(ok7sai): Consider making `activeItem` an internal state in the pattern and call
183183
// `setDefaultState` in the CDK.
184184
activeItem: signal(undefined),
185-
items: computed(() => this._triggers().map(trigger => trigger.pattern)),
185+
items: computed(() => this._triggers().map(trigger => trigger._pattern)),
186186
expandedIds: this.value,
187187
// TODO(ok7sai): Investigate whether an accordion should support horizontal mode.
188188
orientation: () => 'vertical',
@@ -197,9 +197,9 @@ export class AccordionGroup {
197197

198198
for (const trigger of triggers) {
199199
const panel = panels.find(p => p.value() === trigger.value());
200-
trigger.accordionPanel.set(panel?.pattern);
200+
trigger.accordionPanel.set(panel?._pattern);
201201
if (panel) {
202-
panel.accordionTrigger.set(trigger.pattern);
202+
panel.accordionTrigger.set(trigger._pattern);
203203
}
204204
}
205205
});

src/aria/combobox/combobox.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import {toSignal} from '@angular/core/rxjs-interop';
3737
},
3838
],
3939
host: {
40-
'[attr.data-expanded]': 'pattern.expanded()',
41-
'(input)': 'pattern.onInput($event)',
42-
'(keydown)': 'pattern.onKeydown($event)',
43-
'(pointerup)': 'pattern.onPointerup($event)',
44-
'(focusin)': 'pattern.onFocusIn()',
45-
'(focusout)': 'pattern.onFocusOut($event)',
40+
'[attr.data-expanded]': '_pattern.expanded()',
41+
'(input)': '_pattern.onInput($event)',
42+
'(keydown)': '_pattern.onKeydown($event)',
43+
'(pointerup)': '_pattern.onPointerup($event)',
44+
'(focusin)': '_pattern.onFocusIn()',
45+
'(focusout)': '_pattern.onFocusOut($event)',
4646
},
4747
})
4848
export class Combobox<V> {
@@ -82,7 +82,7 @@ export class Combobox<V> {
8282
readonly firstMatch = input<V | undefined>(undefined);
8383

8484
/** The combobox ui pattern. */
85-
readonly pattern = new ComboboxPattern<any, V>({
85+
readonly _pattern = new ComboboxPattern<any, V>({
8686
...this,
8787
textDirection: this.textDirection,
8888
disabled: this.disabled,
@@ -95,13 +95,13 @@ export class Combobox<V> {
9595

9696
constructor() {
9797
afterRenderEffect(() => {
98-
if (!this._deferredContentAware?.contentVisible() && this.pattern.isFocused()) {
98+
if (!this._deferredContentAware?.contentVisible() && this._pattern.isFocused()) {
9999
this._deferredContentAware?.contentVisible.set(true);
100100
}
101101
});
102102

103103
afterRenderEffect(() => {
104-
if (!this._hasBeenFocused() && this.pattern.isFocused()) {
104+
if (!this._hasBeenFocused() && this._pattern.isFocused()) {
105105
this._hasBeenFocused.set(true);
106106
}
107107
});
@@ -114,12 +114,12 @@ export class Combobox<V> {
114114
host: {
115115
'role': 'combobox',
116116
'[value]': 'value()',
117-
'[attr.aria-expanded]': 'combobox.pattern.expanded()',
118-
'[attr.aria-activedescendant]': 'combobox.pattern.activedescendant()',
119-
'[attr.aria-controls]': 'combobox.pattern.popupId()',
120-
'[attr.aria-haspopup]': 'combobox.pattern.hasPopup()',
121-
'[attr.aria-autocomplete]': 'combobox.pattern.autocomplete()',
122-
'[attr.readonly]': 'combobox.pattern.readonly()',
117+
'[attr.aria-expanded]': 'combobox._pattern.expanded()',
118+
'[attr.aria-activedescendant]': 'combobox._pattern.activedescendant()',
119+
'[attr.aria-controls]': 'combobox._pattern.popupId()',
120+
'[attr.aria-haspopup]': 'combobox._pattern.hasPopup()',
121+
'[attr.aria-autocomplete]': 'combobox._pattern.autocomplete()',
122+
'[attr.readonly]': 'combobox._pattern.readonly()',
123123
},
124124
})
125125
export class ComboboxInput {
@@ -133,16 +133,16 @@ export class ComboboxInput {
133133
value = model<string>('');
134134

135135
constructor() {
136-
(this.combobox.pattern.inputs.inputEl as WritableSignal<HTMLInputElement>).set(
136+
(this.combobox._pattern.inputs.inputEl as WritableSignal<HTMLInputElement>).set(
137137
this._elementRef.nativeElement,
138138
);
139-
this.combobox.pattern.inputs.inputValue = this.value;
139+
this.combobox._pattern.inputs.inputValue = this.value;
140140

141141
/** Focuses & selects the first item in the combobox if the user changes the input value. */
142142
afterRenderEffect(() => {
143143
this.value();
144144
this.combobox.popup()?.controls()?.items();
145-
untracked(() => this.combobox.pattern.onFilter());
145+
untracked(() => this.combobox._pattern.onFilter());
146146
});
147147
}
148148
}

src/aria/grid/grid.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ import {GridPattern, GridRowPattern, GridCellPattern, GridCellWidgetPattern} fro
2929
host: {
3030
'class': 'grid',
3131
'role': 'grid',
32-
'[tabindex]': 'pattern.tabIndex()',
33-
'[attr.aria-disabled]': 'pattern.disabled()',
34-
'[attr.aria-activedescendant]': 'pattern.activeDescendant()',
35-
'(keydown)': 'pattern.onKeydown($event)',
36-
'(pointerdown)': 'pattern.onPointerdown($event)',
37-
'(pointermove)': 'pattern.onPointermove($event)',
38-
'(pointerup)': 'pattern.onPointerup($event)',
39-
'(focusin)': 'pattern.onFocusIn()',
40-
'(focusout)': 'pattern.onFocusOut($event)',
32+
'[tabindex]': '_pattern.tabIndex()',
33+
'[attr.aria-disabled]': '_pattern.disabled()',
34+
'[attr.aria-activedescendant]': '_pattern.activeDescendant()',
35+
'(keydown)': '_pattern.onKeydown($event)',
36+
'(pointerdown)': '_pattern.onPointerdown($event)',
37+
'(pointermove)': '_pattern.onPointermove($event)',
38+
'(pointerup)': '_pattern.onPointerup($event)',
39+
'(focusin)': '_pattern.onFocusIn()',
40+
'(focusout)': '_pattern.onFocusOut($event)',
4141
},
4242
})
4343
export class Grid {
@@ -49,7 +49,7 @@ export class Grid {
4949

5050
/** The UI patterns for the rows in the grid. */
5151
private readonly _rowPatterns: Signal<GridRowPattern[]> = computed(() =>
52-
this._rows().map(r => r.pattern),
52+
this._rows().map(r => r._pattern),
5353
);
5454

5555
/** The host native element. */
@@ -74,15 +74,15 @@ export class Grid {
7474
readonly colWrap = input<'continuous' | 'loop' | 'nowrap'>('loop');
7575

7676
/** The UI pattern for the grid. */
77-
readonly pattern = new GridPattern({
77+
readonly _pattern = new GridPattern({
7878
...this,
7979
rows: this._rowPatterns,
8080
getCell: e => this._getCell(e),
8181
});
8282

8383
constructor() {
84-
afterRenderEffect(() => this.pattern.resetStateEffect());
85-
afterRenderEffect(() => this.pattern.focusEffect());
84+
afterRenderEffect(() => this._pattern.resetStateEffect());
85+
afterRenderEffect(() => this._pattern.focusEffect());
8686
}
8787

8888
/** Gets the cell pattern for a given element. */
@@ -123,14 +123,14 @@ export class GridRow {
123123

124124
/** The UI patterns for the cells in this row. */
125125
private readonly _cellPatterns: Signal<GridCellPattern[]> = computed(() =>
126-
this._cells().map(c => c.pattern),
126+
this._cells().map(c => c._pattern),
127127
);
128128

129129
/** The parent grid. */
130130
private readonly _grid = inject(Grid);
131131

132132
/** The parent grid UI pattern. */
133-
readonly grid = computed(() => this._grid.pattern);
133+
readonly grid = computed(() => this._grid._pattern);
134134

135135
/** The host native element. */
136136
readonly element = computed(() => this._elementRef.nativeElement);
@@ -142,7 +142,7 @@ export class GridRow {
142142
readonly rowIndex = input<number>();
143143

144144
/** The UI pattern for the grid row. */
145-
readonly pattern = new GridRowPattern({
145+
readonly _pattern = new GridRowPattern({
146146
...this,
147147
cells: this._cellPatterns,
148148
});
@@ -155,17 +155,17 @@ export class GridRow {
155155
host: {
156156
'class': 'grid-cell',
157157
'[attr.role]': 'role()',
158-
'[attr.id]': 'pattern.id()',
159-
'[attr.rowspan]': 'pattern.rowSpan()',
160-
'[attr.colspan]': 'pattern.colSpan()',
161-
'[attr.data-active]': 'pattern.active()',
162-
'[attr.aria-disabled]': 'pattern.disabled()',
163-
'[attr.aria-rowspan]': 'pattern.rowSpan()',
164-
'[attr.aria-colspan]': 'pattern.colSpan()',
165-
'[attr.aria-rowindex]': 'pattern.ariaRowIndex()',
166-
'[attr.aria-colindex]': 'pattern.ariaColIndex()',
167-
'[attr.aria-selected]': 'pattern.ariaSelected()',
168-
'[tabindex]': 'pattern.tabIndex()',
158+
'[attr.id]': '_pattern.id()',
159+
'[attr.rowspan]': '_pattern.rowSpan()',
160+
'[attr.colspan]': '_pattern.colSpan()',
161+
'[attr.data-active]': '_pattern.active()',
162+
'[attr.aria-disabled]': '_pattern.disabled()',
163+
'[attr.aria-rowspan]': '_pattern.rowSpan()',
164+
'[attr.aria-colspan]': '_pattern.colSpan()',
165+
'[attr.aria-rowindex]': '_pattern.ariaRowIndex()',
166+
'[attr.aria-colindex]': '_pattern.ariaColIndex()',
167+
'[attr.aria-selected]': '_pattern.ariaSelected()',
168+
'[tabindex]': '_pattern.tabIndex()',
169169
},
170170
})
171171
export class GridCell {
@@ -177,7 +177,7 @@ export class GridCell {
177177

178178
/** The UI pattern for the widget in this cell. */
179179
private readonly _widgetPattern: Signal<GridCellWidgetPattern | undefined> = computed(
180-
() => this._widgets()?.pattern,
180+
() => this._widgets()?._pattern,
181181
);
182182

183183
/** The parent row. */
@@ -214,11 +214,11 @@ export class GridCell {
214214
readonly selectable = input<boolean>(true);
215215

216216
/** The UI pattern for the grid cell. */
217-
readonly pattern = new GridCellPattern({
217+
readonly _pattern = new GridCellPattern({
218218
...this,
219219
id: () => this._id,
220220
grid: this._row.grid,
221-
row: () => this._row.pattern,
221+
row: () => this._row._pattern,
222222
widget: this._widgetPattern,
223223
});
224224
}
@@ -229,8 +229,8 @@ export class GridCell {
229229
exportAs: 'ngGridCellWidget',
230230
host: {
231231
'class': 'grid-cell-widget',
232-
'[attr.data-active]': 'pattern.active()',
233-
'[tabindex]': 'pattern.tabIndex()',
232+
'[attr.data-active]': '_pattern.active()',
233+
'[tabindex]': '_pattern.tabIndex()',
234234
},
235235
})
236236
export class GridCellWidget {
@@ -247,9 +247,9 @@ export class GridCellWidget {
247247
readonly activate = model<boolean>(false);
248248

249249
/** The UI pattern for the grid cell widget. */
250-
readonly pattern = new GridCellWidgetPattern({
250+
readonly _pattern = new GridCellWidgetPattern({
251251
...this,
252-
cell: () => this._cell.pattern,
252+
cell: () => this._cell._pattern,
253253
});
254254

255255
/** Focuses the widget. */

0 commit comments

Comments
 (0)