@@ -12,6 +12,7 @@ import {
1212 computed ,
1313 contentChildren ,
1414 Directive ,
15+ effect ,
1516 ElementRef ,
1617 inject ,
1718 input ,
@@ -158,7 +159,7 @@ export class Listbox<V> {
158159 this . _popup . _controls . set ( this . _pattern as ComboboxListboxPattern < V > ) ;
159160 }
160161
161- afterRenderEffect ( ( ) => {
162+ effect ( ( ) => {
162163 if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
163164 const violations = this . _pattern . validate ( ) ;
164165 for ( const violation of violations ) {
@@ -167,27 +168,31 @@ export class Listbox<V> {
167168 }
168169 } ) ;
169170
170- afterRenderEffect ( { write : ( ) => this . _pattern . setDefaultState ( ) } ) ;
171+ afterRenderEffect ( { write : ( ) => this . _pattern . setDefaultStateEffect ( ) } ) ;
171172
172173 // Ensure that if the active item is removed from
173174 // the list, the listbox updates it's focus state.
174- afterRenderEffect ( ( ) => {
175- const items = inputs . items ( ) ;
176- const activeItem = untracked ( ( ) => inputs . activeItem ( ) ) ;
175+ afterRenderEffect ( {
176+ write : ( ) => {
177+ const items = inputs . items ( ) ;
178+ const activeItem = untracked ( ( ) => inputs . activeItem ( ) ) ;
177179
178- if ( ! items . some ( i => i === activeItem ) && activeItem ) {
179- this . _pattern . listBehavior . unfocus ( ) ;
180- }
180+ if ( ! items . some ( i => i === activeItem ) && activeItem ) {
181+ this . _pattern . listBehavior . unfocus ( ) ;
182+ }
183+ } ,
181184 } ) ;
182185
183186 // Ensure that the value is always in sync with the available options.
184- afterRenderEffect ( ( ) => {
185- const items = inputs . items ( ) ;
186- const value = untracked ( ( ) => this . value ( ) ) ;
187+ afterRenderEffect ( {
188+ write : ( ) => {
189+ const items = inputs . items ( ) ;
190+ const value = untracked ( ( ) => this . value ( ) ) ;
187191
188- if ( items && value . some ( v => ! items . some ( i => i . value ( ) === v ) ) ) {
189- this . value . set ( value . filter ( v => items . some ( i => i . value ( ) === v ) ) ) ;
190- }
192+ if ( items && value . some ( v => ! items . some ( i => i . value ( ) === v ) ) ) {
193+ this . value . set ( value . filter ( v => items . some ( i => i . value ( ) === v ) ) ) ;
194+ }
195+ } ,
191196 } ) ;
192197 }
193198
0 commit comments