Skip to content

Commit a303e71

Browse files
committed
refactor(multiple): use effect for setting contentVisible
1 parent 963b4ba commit a303e71

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

src/aria/accordion/accordion-panel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Directive, afterRenderEffect, computed, inject, input} from '@angular/core';
9+
import {Directive, effect, computed, inject, input} from '@angular/core';
1010
import {_IdGenerator} from '@angular/cdk/a11y';
1111
import {DeferredContentAware, AccordionTriggerPattern} from '../private';
1212

@@ -65,8 +65,8 @@ export class AccordionPanel {
6565
_pattern?: AccordionTriggerPattern;
6666

6767
constructor() {
68-
// Connect the panel's hidden state to the DeferredContentAware's visibility.
69-
afterRenderEffect(() => {
68+
effect(() => {
69+
// Connect the panel's hidden state to the DeferredContentAware's visibility.
7070
this._deferredContentAware.contentVisible.set(this.visible());
7171
});
7272
}

src/aria/combobox/combobox.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import {
10-
afterRenderEffect,
10+
Directive,
11+
ElementRef,
1112
booleanAttribute,
1213
computed,
1314
contentChild,
14-
Directive,
15-
ElementRef,
15+
effect,
1616
inject,
1717
input,
1818
signal,
@@ -134,13 +134,13 @@ export class Combobox<V> {
134134
});
135135

136136
constructor() {
137-
afterRenderEffect(() => {
137+
effect(() => {
138138
if (this.alwaysExpanded()) {
139139
this._pattern.expanded.set(true);
140140
}
141141
});
142142

143-
afterRenderEffect(() => {
143+
effect(() => {
144144
if (
145145
!this._deferredContentAware?.contentVisible() &&
146146
(this._pattern.isFocused() || this.alwaysExpanded())

src/aria/menu/menu.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
*/
88

99
import {
10+
Directive,
11+
ElementRef,
1012
afterRenderEffect,
1113
booleanAttribute,
1214
computed,
1315
contentChildren,
14-
Directive,
15-
ElementRef,
16+
effect,
1617
inject,
1718
input,
1819
output,
@@ -154,7 +155,7 @@ export class Menu<V> {
154155
itemSelected: (value: V) => this.itemSelected.emit(value),
155156
});
156157

157-
afterRenderEffect(() => {
158+
effect(() => {
158159
const parent = this.parent();
159160
if (parent instanceof MenuItem && parent.parent instanceof MenuBar) {
160161
this._deferredContentAware?.contentVisible.set(true);

src/aria/tabs/tab-panel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
computed,
1212
Directive,
1313
ElementRef,
14+
effect,
1415
inject,
1516
input,
16-
afterRenderEffect,
1717
OnInit,
1818
OnDestroy,
1919
} from '@angular/core';
@@ -90,7 +90,7 @@ export class TabPanel implements OnInit, OnDestroy {
9090
});
9191

9292
constructor() {
93-
afterRenderEffect(() => this._deferredContentAware.contentVisible.set(this.visible()));
93+
effect(() => this._deferredContentAware.contentVisible.set(this.visible()));
9494
}
9595

9696
ngOnInit() {

src/aria/tree/tree-item.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {
1010
Directive,
1111
ElementRef,
12-
afterRenderEffect,
1312
booleanAttribute,
1413
computed,
1514
inject,
@@ -20,6 +19,7 @@ import {
2019
OnInit,
2120
OnDestroy,
2221
afterNextRender,
22+
effect,
2323
} from '@angular/core';
2424
import {_IdGenerator} from '@angular/cdk/a11y';
2525
import {ComboboxTreePattern, TreeItemPattern, DeferredContentAware} from '../private';
@@ -128,11 +128,12 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
128128
this.preserveContent.set(true);
129129
}
130130
});
131-
// Connect the group's hidden state to the DeferredContentAware's visibility.
132-
afterRenderEffect(() => {
133-
this.tree()._pattern instanceof ComboboxTreePattern
134-
? this.contentVisible.set(true)
135-
: this.contentVisible.set(this._pattern.expanded());
131+
132+
effect(() => {
133+
// Connect the group's hidden state to the DeferredContentAware's visibility.
134+
this.contentVisible.set(
135+
this.tree()._pattern instanceof ComboboxTreePattern || this._pattern.expanded(),
136+
);
136137
});
137138
}
138139

0 commit comments

Comments
 (0)