Skip to content

Commit 88f364c

Browse files
committed
refactor(aria/menu): Add accessors for pattern properties
1 parent 1150865 commit 88f364c

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/aria/menu/menu.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import {Directionality} from '@angular/cdk/bidi';
4545
host: {
4646
'class': 'ng-menu-trigger',
4747
'[attr.tabindex]': '_pattern.tabIndex()',
48-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
49-
'[attr.aria-expanded]': '_pattern.expanded()',
48+
'[attr.aria-haspopup]': 'hasPopup()',
49+
'[attr.aria-expanded]': 'expanded()',
5050
'[attr.aria-controls]': '_pattern.menu()?.id()',
5151
'(click)': '_pattern.onClick()',
5252
'(keydown)': '_pattern.onKeydown($event)',
@@ -70,6 +70,12 @@ export class MenuTrigger<V> {
7070
/** Whether the menu item has been focused. */
7171
readonly hasBeenFocused = signal(false);
7272

73+
/** Whether the menu is expanded. */
74+
readonly expanded = computed(() => this._pattern.expanded());
75+
76+
/** Whether the menu trigger has a popup. */
77+
readonly hasPopup = computed(() => this._pattern.hasPopup());
78+
7379
/** The menu trigger ui pattern instance. */
7480
_pattern: MenuTriggerPattern<V> = new MenuTriggerPattern({
7581
textDirection: this.textDirection,
@@ -110,7 +116,7 @@ export class MenuTrigger<V> {
110116
'role': 'menu',
111117
'class': 'ng-menu',
112118
'[attr.id]': '_pattern.id()',
113-
'[attr.data-visible]': '_pattern.isVisible()',
119+
'[attr.data-visible]': 'isVisible()',
114120
'(keydown)': '_pattern.onKeydown($event)',
115121
'(mouseover)': '_pattern.onMouseOver($event)',
116122
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -170,8 +176,11 @@ export class Menu<V> {
170176
*/
171177
readonly items = () => this._items().map(i => i._pattern);
172178

179+
/** Whether the menu or any of its child elements are currently focused. */
180+
readonly isFocused = computed(() => this._pattern.isFocused());
181+
173182
/** Whether the menu is visible. */
174-
isVisible = computed(() => this._pattern.isVisible());
183+
readonly isVisible = computed(() => this._pattern.isVisible());
175184

176185
/** A callback function triggered when a menu item is selected. */
177186
onSelect = output<V>();
@@ -285,6 +294,9 @@ export class MenuBar<V> {
285294
/** The delay in seconds before the typeahead buffer is cleared. */
286295
readonly typeaheadDelay = input<number>(0.5);
287296

297+
/** Whether the menubar or any of its child elements are currently focused. */
298+
readonly isFocused = computed(() => this._pattern.isFocused());
299+
288300
/** The menu ui pattern instance. */
289301
readonly _pattern: MenuBarPattern<V>;
290302

@@ -332,9 +344,9 @@ export class MenuBar<V> {
332344
'class': 'ng-menu-item',
333345
'(focusin)': 'onFocusIn()',
334346
'[attr.tabindex]': '_pattern.tabIndex()',
335-
'[attr.data-active]': '_pattern.isActive()',
336-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
337-
'[attr.aria-expanded]': '_pattern.expanded()',
347+
'[attr.data-active]': 'isActive()',
348+
'[attr.aria-haspopup]': 'hasPopup()',
349+
'[attr.aria-expanded]': 'expanded()',
338350
'[attr.aria-disabled]': '_pattern.disabled()',
339351
'[attr.aria-controls]': '_pattern.submenu()?.id()',
340352
},
@@ -372,9 +384,18 @@ export class MenuItem<V> {
372384
/** The submenu associated with the menu item. */
373385
readonly submenu = input<Menu<V> | undefined>(undefined);
374386

387+
/** Whether the menu item is active. */
388+
readonly isActive = computed(() => this._pattern.isActive());
389+
375390
/** Whether the menu item has been focused. */
376391
readonly hasBeenFocused = signal(false);
377392

393+
/** Whether the menuis expanded. */
394+
readonly expanded = computed(() => this._pattern.expanded());
395+
396+
/** Whether the menu item has a popup. */
397+
readonly hasPopup = computed(() => this._pattern.hasPopup());
398+
378399
/** The menu item ui pattern instance. */
379400
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
380401
id: this.id,

0 commit comments

Comments
 (0)