Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/aria/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {DeferredContent, DeferredContentAware} from '@angular/aria/deferred-cont
'(click)': '_pattern.onClick()',
'(keydown)': '_pattern.onKeydown($event)',
'(focusout)': '_pattern.onFocusOut($event)',
'(focusin)': 'onFocusIn()',
},
})
export class MenuTrigger<V> {
Expand All @@ -65,6 +66,9 @@ export class MenuTrigger<V> {
/** The menu associated with the trigger. */
menu = input<Menu<V> | undefined>(undefined);

/** Whether the menu item has been focused. */
readonly hasBeenFocused = signal(false);

/** The menu trigger ui pattern instance. */
_pattern: MenuTriggerPattern<V> = new MenuTriggerPattern({
element: computed(() => this._elementRef.nativeElement),
Expand All @@ -74,6 +78,11 @@ export class MenuTrigger<V> {
constructor() {
effect(() => this.menu()?.parent.set(this));
}

/** Marks the menu trigger as having been focused. */
onFocusIn() {
this.hasBeenFocused.set(true);
}
}

/**
Expand Down Expand Up @@ -185,7 +194,14 @@ export class Menu<V> {
});

afterRenderEffect(() => {
this._deferredContentAware?.contentVisible.set(this._pattern.isVisible());
const parent = this.parent();
if (parent instanceof MenuItem && parent.parent instanceof MenuBar) {
this._deferredContentAware?.contentVisible.set(true);
} else {
this._deferredContentAware?.contentVisible.set(
this._pattern.isVisible() || !!this.parent()?.hasBeenFocused(),
);
}
});

// TODO(wagnermaciel): This is a redundancy needed for if the user uses display: none to hide
Expand Down Expand Up @@ -322,6 +338,7 @@ export class MenuBar<V> {
host: {
'role': 'menuitem',
'class': 'ng-menu-item',
'(focusin)': 'onFocusIn()',
'[attr.tabindex]': '_pattern.tabindex()',
'[attr.data-active]': '_pattern.isActive()',
'[attr.aria-haspopup]': '_pattern.hasPopup()',
Expand Down Expand Up @@ -363,6 +380,9 @@ export class MenuItem<V> {
/** The submenu associated with the menu item. */
readonly submenu = input<Menu<V> | undefined>(undefined);

/** Whether the menu item has been focused. */
readonly hasBeenFocused = signal(false);

/** The menu item ui pattern instance. */
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
id: this.id,
Expand All @@ -377,6 +397,11 @@ export class MenuItem<V> {
constructor() {
effect(() => this.submenu()?.parent.set(this));
}

/** Marks the menu item as having been focused. */
onFocusIn() {
this.hasBeenFocused.set(true);
}
}

/** Defers the rendering of the menu content. */
Expand Down
Loading