Skip to content

Commit 72bd58f

Browse files
committed
refactor(aria/menu): use write in afterRenderEffect when setting focus and use computed for patterns
1 parent 2f18048 commit 72bd58f

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/aria/menu/menu-bar.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class MenuBar<V> {
104104
readonly _pattern: MenuBarPattern<V>;
105105

106106
/** The menu items as a writable signal. */
107-
private readonly _itemPatterns = signal<any[]>([]);
107+
private readonly _itemPatterns = computed(() => this._items().map(i => i._pattern));
108108

109109
/** A callback function triggered when a menu item is selected. */
110110
readonly itemSelected = output<V>();
@@ -123,10 +123,6 @@ export class MenuBar<V> {
123123
element: computed(() => this._elementRef.nativeElement),
124124
});
125125

126-
afterRenderEffect(() => {
127-
this._itemPatterns.set(this._items().map(i => i._pattern));
128-
});
129-
130126
afterRenderEffect(() => {
131127
this._pattern.setDefaultStateEffect();
132128
});

src/aria/menu/menu.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ export class Menu<V> {
170170
// submenus. In those cases, the ui pattern is calling focus() before the ui has a chance to
171171
// update the display property. The result is focus() being called on an element that is not
172172
// focusable. This simply retries focusing the element after render.
173-
afterRenderEffect(() => {
174-
if (this._pattern.visible()) {
175-
const activeItem = untracked(() => this._pattern.inputs.activeItem());
176-
this._pattern.listBehavior.goto(activeItem!);
177-
}
173+
afterRenderEffect({
174+
write: () => {
175+
if (this.visible()) {
176+
const activeItem = untracked(() => this._pattern.inputs.activeItem());
177+
this._pattern.listBehavior.goto(activeItem!);
178+
}
179+
},
178180
});
179181

180182
afterRenderEffect(() => {

0 commit comments

Comments
 (0)