Skip to content

Commit 1b9cbeb

Browse files
committed
refactor(aria/menu): move hasBeenFocused to pattern
1 parent 26b97a1 commit 1b9cbeb

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/aria/menu/menu.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {Directionality} from '@angular/cdk/bidi';
5151
'(click)': '_pattern.onClick()',
5252
'(keydown)': '_pattern.onKeydown($event)',
5353
'(focusout)': '_pattern.onFocusOut($event)',
54-
'(focusin)': 'onFocusIn()',
54+
'(focusin)': '_pattern.onFocusIn()',
5555
},
5656
})
5757
export class MenuTrigger<V> {
@@ -67,9 +67,6 @@ export class MenuTrigger<V> {
6767
/** The menu associated with the trigger. */
6868
menu = input<Menu<V> | undefined>(undefined);
6969

70-
/** Whether the menu item has been focused. */
71-
readonly hasBeenFocused = signal(false);
72-
7370
/** Whether the menu is expanded. */
7471
readonly expanded = computed(() => this._pattern.expanded());
7572

@@ -86,11 +83,6 @@ export class MenuTrigger<V> {
8683
constructor() {
8784
effect(() => this.menu()?.parent.set(this));
8885
}
89-
90-
/** Marks the menu trigger as having been focused. */
91-
onFocusIn() {
92-
this.hasBeenFocused.set(true);
93-
}
9486
}
9587

9688
/**
@@ -205,7 +197,7 @@ export class Menu<V> {
205197
this._deferredContentAware?.contentVisible.set(true);
206198
} else {
207199
this._deferredContentAware?.contentVisible.set(
208-
this._pattern.isVisible() || !!this.parent()?.hasBeenFocused(),
200+
this._pattern.isVisible() || !!this.parent()?._pattern.hasBeenFocused(),
209201
);
210202
}
211203
});
@@ -339,7 +331,7 @@ export class MenuBar<V> {
339331
host: {
340332
'role': 'menuitem',
341333
'class': 'ng-menu-item',
342-
'(focusin)': 'onFocusIn()',
334+
'(focusin)': '_pattern.onFocusIn()',
343335
'[attr.tabindex]': '_pattern.tabIndex()',
344336
'[attr.data-active]': 'isActive()',
345337
'[attr.aria-haspopup]': 'hasPopup()',
@@ -404,11 +396,6 @@ export class MenuItem<V> {
404396
constructor() {
405397
effect(() => this.submenu()?.parent.set(this));
406398
}
407-
408-
/** Marks the menu item as having been focused. */
409-
onFocusIn() {
410-
this.hasBeenFocused.set(true);
411-
}
412399
}
413400

414401
/** Defers the rendering of the menu content. */

src/aria/private/menu/menu.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ export class MenuTriggerPattern<V> {
578578
/** Whether the menu is expanded. */
579579
expanded = signal(false);
580580

581+
/** Whether the menu trigger has received focus. */
582+
hasBeenFocused = signal(false);
583+
581584
/** The role of the menu trigger. */
582585
role = () => 'button';
583586

@@ -614,6 +617,11 @@ export class MenuTriggerPattern<V> {
614617
this.expanded() ? this.close() : this.open({first: true});
615618
}
616619

620+
/** Handles focusin events for the menu trigger. */
621+
onFocusIn() {
622+
this.hasBeenFocused.set(true);
623+
}
624+
617625
/** Handles focusout events for the menu trigger. */
618626
onFocusOut(event: FocusEvent) {
619627
const element = this.inputs.element();
@@ -679,6 +687,9 @@ export class MenuItemPattern<V> implements ListItem<V> {
679687
/** Whether the menu item is active. */
680688
isActive = computed(() => this.inputs.parent()?.inputs.activeItem() === this);
681689

690+
/** Whether the menu item has received focus. */
691+
hasBeenFocused = signal(false);
692+
682693
/** The tab index of the menu item. */
683694
tabIndex = computed(() => {
684695
if (this.submenu() && this.submenu()?.inputs.activeItem()) {
@@ -756,4 +767,9 @@ export class MenuItemPattern<V> implements ListItem<V> {
756767
}
757768
}
758769
}
770+
771+
/** Handles focusin events for the menu item. */
772+
onFocusIn() {
773+
this.hasBeenFocused.set(true);
774+
}
759775
}

0 commit comments

Comments
 (0)