Skip to content

Commit 0a7e982

Browse files
committed
refactor(aria/menu): Add accessors for pattern properties
1 parent 900c13a commit 0a7e982

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/aria/menu/menu.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ import {Directionality} from '@angular/cdk/bidi';
4545
exportAs: 'ngMenuTrigger',
4646
host: {
4747
'class': 'ng-menu-trigger',
48-
'[attr.tabindex]': '_pattern.tabindex()',
49-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
50-
'[attr.aria-expanded]': '_pattern.expanded()',
48+
'[attr.tabindex]': '_pattern.tabIndex()',
49+
'[attr.aria-haspopup]': 'hasPopup()',
50+
'[attr.aria-expanded]': 'expanded()',
5151
'[attr.aria-controls]': '_pattern.menu()?.id()',
5252
'(click)': '_pattern.onClick()',
5353
'(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
element: computed(() => this._elementRef.nativeElement),
@@ -109,7 +115,7 @@ export class MenuTrigger<V> {
109115
'role': 'menu',
110116
'class': 'ng-menu',
111117
'[attr.id]': '_pattern.id()',
112-
'[attr.data-visible]': '_pattern.isVisible()',
118+
'[attr.data-visible]': 'isVisible()',
113119
'(keydown)': '_pattern.onKeydown($event)',
114120
'(mouseover)': '_pattern.onMouseOver($event)',
115121
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -174,8 +180,11 @@ export class Menu<V> {
174180
*/
175181
readonly items = () => this._items().map(i => i._pattern);
176182

183+
/** Whether the menu or any of its child elements are currently focused. */
184+
readonly isFocused = computed(() => this._pattern.isFocused());
185+
177186
/** Whether the menu is visible. */
178-
isVisible = computed(() => this._pattern.isVisible());
187+
readonly isVisible = computed(() => this._pattern.isVisible());
179188

180189
/** A callback function triggered when a menu item is selected. */
181190
onSelect = output<V>();
@@ -294,6 +303,9 @@ export class MenuBar<V> {
294303
/** The delay in seconds before the typeahead buffer is cleared. */
295304
readonly typeaheadDelay = input<number>(0.5);
296305

306+
/** Whether the menubar or any of its child elements are currently focused. */
307+
readonly isFocused = computed(() => this._pattern.isFocused());
308+
297309
/** The menu ui pattern instance. */
298310
readonly _pattern: MenuBarPattern<V>;
299311

@@ -340,10 +352,10 @@ export class MenuBar<V> {
340352
'role': 'menuitem',
341353
'class': 'ng-menu-item',
342354
'(focusin)': 'onFocusIn()',
343-
'[attr.tabindex]': '_pattern.tabindex()',
344-
'[attr.data-active]': '_pattern.isActive()',
345-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
346-
'[attr.aria-expanded]': '_pattern.expanded()',
355+
'[attr.tabindex]': '_pattern.tabIndex()',
356+
'[attr.data-active]': 'isActive()',
357+
'[attr.aria-haspopup]': 'hasPopup()',
358+
'[attr.aria-expanded]': 'expanded()',
347359
'[attr.aria-disabled]': '_pattern.disabled()',
348360
'[attr.aria-controls]': '_pattern.submenu()?.id()',
349361
},
@@ -381,9 +393,18 @@ export class MenuItem<V> {
381393
/** The submenu associated with the menu item. */
382394
readonly submenu = input<Menu<V> | undefined>(undefined);
383395

396+
/** Whether the menu item is active. */
397+
readonly isActive = computed(() => this._pattern.isActive());
398+
384399
/** Whether the menu item has been focused. */
385400
readonly hasBeenFocused = signal(false);
386401

402+
/** Whether the menuis expanded. */
403+
readonly expanded = computed(() => this._pattern.expanded());
404+
405+
/** Whether the menu item has a popup. */
406+
readonly hasPopup = computed(() => this._pattern.hasPopup());
407+
387408
/** The menu item ui pattern instance. */
388409
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
389410
id: this.id,

0 commit comments

Comments
 (0)