Skip to content

Commit 0d202d5

Browse files
committed
refactor(aria/tree): change afterRenderEffect to use read/write stages appropriately
1 parent 7116254 commit 0d202d5

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

src/aria/tree/tree.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,36 +170,43 @@ export class Tree<V> {
170170
this._popup?._controls?.set(this._pattern as ComboboxTreePattern<V>);
171171
}
172172

173-
afterRenderEffect(() => {
174-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
175-
const violations = this._pattern.validate();
176-
for (const violation of violations) {
177-
console.error(violation);
173+
// Check for any violationns after the DOM has been updated.
174+
afterRenderEffect({
175+
read: () => {
176+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
177+
const violations = this._pattern.validate();
178+
for (const violation of violations) {
179+
console.error(violation);
180+
}
178181
}
179-
}
182+
},
180183
});
181184

182185
// Resets default focus based on selection state until interacted.
183186
afterRenderEffect({write: () => this._pattern.setDefaultStateEffect()});
184187

185-
afterRenderEffect(() => {
186-
const items = inputs.items();
187-
const activeItem = untracked(() => inputs.activeItem());
188+
afterRenderEffect({
189+
write: () => {
190+
const items = inputs.items();
191+
const activeItem = untracked(() => inputs.activeItem());
188192

189-
if (!items.some(i => i === activeItem) && activeItem) {
190-
this._pattern.treeBehavior.unfocus();
191-
}
193+
if (!items.some(i => i === activeItem) && activeItem) {
194+
this._pattern.treeBehavior.unfocus();
195+
}
196+
},
192197
});
193198

194-
afterRenderEffect(() => {
195-
if (!(this._pattern instanceof ComboboxTreePattern)) return;
199+
afterRenderEffect({
200+
write: () => {
201+
if (!(this._pattern instanceof ComboboxTreePattern)) return;
196202

197-
const items = inputs.items();
198-
const value = untracked(() => this.value());
203+
const items = inputs.items();
204+
const value = untracked(() => this.value());
199205

200-
if (items && value.some(v => !items.some(i => i.value() === v))) {
201-
this.value.set(value.filter(v => items.some(i => i.value() === v)));
202-
}
206+
if (items && value.some(v => !items.some(i => i.value() === v))) {
207+
this.value.set(value.filter(v => items.some(i => i.value() === v)));
208+
}
209+
},
203210
});
204211
}
205212

0 commit comments

Comments
 (0)