Skip to content

Commit f260b88

Browse files
committed
refactor(multiple): use write in afterRenderEffect for aria DeferredContent updates
1 parent 9cdc8dd commit f260b88

6 files changed

Lines changed: 46 additions & 32 deletions

File tree

src/aria/accordion/accordion-panel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ export class AccordionPanel {
7272

7373
constructor() {
7474
// Connect the panel's hidden state to the DeferredContentAware's visibility.
75-
afterRenderEffect(() => {
76-
this._deferredContentAware.contentVisible.set(this.visible());
75+
afterRenderEffect({
76+
write: () => {
77+
this._deferredContentAware.contentVisible.set(this.visible());
78+
},
7779
});
7880
}
7981

src/aria/combobox/combobox.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ export class Combobox<V> {
140140
}
141141
});
142142

143-
afterRenderEffect(() => {
144-
if (
145-
!this._deferredContentAware?.contentVisible() &&
146-
(this._pattern.isFocused() || this.alwaysExpanded())
147-
) {
148-
this._deferredContentAware?.contentVisible.set(true);
149-
}
143+
afterRenderEffect({
144+
write: () => {
145+
if (
146+
!this._deferredContentAware?.contentVisible() &&
147+
(this._pattern.isFocused() || this.alwaysExpanded())
148+
) {
149+
this._deferredContentAware?.contentVisible.set(true);
150+
}
151+
},
150152
});
151153
}
152154

src/aria/menu/menu.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,17 @@ export class Menu<V> {
162162
itemSelected: (value: V) => this.itemSelected.emit(value),
163163
});
164164

165-
afterRenderEffect(() => {
166-
const parent = this.parent();
167-
if (parent instanceof MenuItem && parent.parent instanceof MenuBar) {
168-
this._deferredContentAware?.contentVisible.set(true);
169-
} else {
170-
this._deferredContentAware?.contentVisible.set(
171-
this._pattern.visible() || !!this.parent()?._pattern.hasBeenInteracted(),
172-
);
173-
}
165+
afterRenderEffect({
166+
write: () => {
167+
const parent = this.parent();
168+
if (parent instanceof MenuItem && parent.parent instanceof MenuBar) {
169+
this._deferredContentAware?.contentVisible.set(true);
170+
} else {
171+
this._deferredContentAware?.contentVisible.set(
172+
this._pattern.visible() || !!this.parent()?._pattern.hasBeenInteracted(),
173+
);
174+
}
175+
},
174176
});
175177

176178
// Focuses an active menu item when the menu becomes visible. This is needed to

src/aria/private/deferred-content/deferred-content.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ export class DeferredContent implements OnDestroy {
5353
readonly deferredContentAware = signal(this._deferredContentAware);
5454

5555
constructor() {
56-
afterRenderEffect(() => {
57-
if (this.deferredContentAware()?.contentVisible()) {
58-
if (!this._isRendered) {
56+
afterRenderEffect({
57+
write: () => {
58+
if (this.deferredContentAware()?.contentVisible()) {
59+
if (!this._isRendered) {
60+
this._destroyContent();
61+
this._currentViewRef = this._viewContainerRef.createEmbeddedView(this._templateRef);
62+
this._isRendered = true;
63+
}
64+
} else if (!this.deferredContentAware()?.preserveContent()) {
5965
this._destroyContent();
60-
this._currentViewRef = this._viewContainerRef.createEmbeddedView(this._templateRef);
61-
this._isRendered = true;
66+
this._isRendered = false;
6267
}
63-
} else if (!this.deferredContentAware()?.preserveContent()) {
64-
this._destroyContent();
65-
this._isRendered = false;
66-
}
68+
},
6769
});
6870
}
6971

src/aria/tabs/tab-panel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ export class TabPanel implements OnInit, OnDestroy {
9090
});
9191

9292
constructor() {
93-
afterRenderEffect(() => this._deferredContentAware.contentVisible.set(this.visible()));
93+
afterRenderEffect({
94+
write: () => {
95+
this._deferredContentAware.contentVisible.set(this.visible());
96+
},
97+
});
9498
}
9599

96100
ngOnInit() {

src/aria/tree/tree-item.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
128128
}
129129
});
130130
// Connect the group's hidden state to the DeferredContentAware's visibility.
131-
afterRenderEffect(() => {
132-
this.tree()._pattern instanceof ComboboxTreePattern
133-
? this.contentVisible.set(true)
134-
: this.contentVisible.set(this._pattern.expanded());
131+
afterRenderEffect({
132+
write: () => {
133+
this.tree()._pattern instanceof ComboboxTreePattern
134+
? this.contentVisible.set(true)
135+
: this.contentVisible.set(this._pattern.expanded());
136+
},
135137
});
136138
}
137139

0 commit comments

Comments
 (0)