@@ -158,36 +158,44 @@ export class Listbox<V> {
158158 this . _popup . _controls . set ( this . _pattern as ComboboxListboxPattern < V > ) ;
159159 }
160160
161- afterRenderEffect ( ( ) => {
162- if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
163- const violations = this . _pattern . validate ( ) ;
164- for ( const violation of violations ) {
165- console . error ( violation ) ;
161+ // Check for any violationns after the DOM has been updated.
162+ afterRenderEffect ( {
163+ read : ( ) => {
164+ if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
165+ const violations = this . _pattern . validate ( ) ;
166+ for ( const violation of violations ) {
167+ console . error ( violation ) ;
168+ }
166169 }
167- }
170+ } ,
168171 } ) ;
169172
170173 afterRenderEffect ( { write : ( ) => this . _pattern . setDefaultStateEffect ( ) } ) ;
171174
172175 // Ensure that if the active item is removed from
173176 // the list, the listbox updates it's focus state.
174- afterRenderEffect ( ( ) => {
175- const items = inputs . items ( ) ;
176- const activeItem = untracked ( ( ) => inputs . activeItem ( ) ) ;
177+ afterRenderEffect ( {
178+ write : ( ) => {
179+ const items = inputs . items ( ) ;
180+ const activeItem = untracked ( ( ) => inputs . activeItem ( ) ) ;
177181
178- if ( ! items . some ( i => i === activeItem ) && activeItem ) {
179- this . _pattern . listBehavior . unfocus ( ) ;
180- }
182+ if ( ! items . some ( i => i === activeItem ) && activeItem ) {
183+ this . _pattern . listBehavior . unfocus ( ) ;
184+ }
185+ } ,
181186 } ) ;
182187
183188 // 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-
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- }
189+ // This needs to be after the render for the value to always be available.
190+ afterRenderEffect ( {
191+ write : ( ) => {
192+ const items = inputs . items ( ) ;
193+ const value = untracked ( ( ) => this . value ( ) ) ;
194+
195+ if ( items && value . some ( v => ! items . some ( i => i . value ( ) === v ) ) ) {
196+ this . value . set ( value . filter ( v => items . some ( i => i . value ( ) === v ) ) ) ;
197+ }
198+ } ,
191199 } ) ;
192200 }
193201
0 commit comments