Skip to content

Commit 4b7ec7d

Browse files
committed
fix(aria/menu): use computed for menu item patterns, with trigger on visible
1 parent 91a4932 commit 4b7ec7d

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/aria/menu/menu.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ export class Menu<V> {
119119
readonly _pattern: MenuPattern<V>;
120120

121121
/**
122-
* The menu items as a writable signal.
123-
*
124-
* TODO(wagnermaciel): This would normally be a computed, but using a computed causes a bug where
125-
* sometimes the items array is empty. The bug can be reproduced by switching this to use a
126-
* computed and then quickly opening and closing menus in the dev app.
122+
* The menu item patterns for the menu items that are direct children of this menu, passed
123+
* to the menu pattern.
127124
*/
128-
private readonly _itemPatterns = () => this._items().map(i => i._pattern);
125+
private readonly _itemPatterns = computed(() => {
126+
// Needed to properly trigger recompute without contentChildren returning partial list.
127+
this._pattern.visible();
128+
129+
return this._items().map(i => i._pattern);
130+
});
129131

130132
/** Whether the menu is visible. */
131133
readonly visible = computed(() => this._pattern.visible());

0 commit comments

Comments
 (0)