@@ -8,6 +8,7 @@ import { toggleState } from '../utils/element-internals.js';
8
8
import { getLanguage } from '../utils/language.js' ;
9
9
import { AnchorPositioningCSSSupported } from '../utils/support.js' ;
10
10
import { uniqueId } from '../utils/unique-id.js' ;
11
+ import { waitForConnectedDescendants } from '../utils/request-idle-callback.js' ;
11
12
import { DropdownType } from './dropdown.options.js' ;
12
13
import { dropdownButtonTemplate , dropdownInputTemplate } from './dropdown.template.js' ;
13
14
@@ -105,7 +106,6 @@ export class BaseDropdown extends FASTElement {
105
106
public controlChanged ( prev : HTMLInputElement | undefined , next : HTMLInputElement | undefined ) : void {
106
107
if ( next ) {
107
108
next . id = next . id || uniqueId ( 'input-' ) ;
108
- this . controlSlot ?. assign ( next ) ;
109
109
}
110
110
}
111
111
@@ -224,7 +224,7 @@ export class BaseDropdown extends FASTElement {
224
224
next . dropdown = this ;
225
225
next . popover = 'manual' ;
226
226
next . tabIndex = - 1 ;
227
- this . listboxSlot . assign ( next ) ;
227
+
228
228
const notifier = Observable . getNotifier ( this ) ;
229
229
notifier . subscribe ( next ) ;
230
230
@@ -252,14 +252,6 @@ export class BaseDropdown extends FASTElement {
252
252
}
253
253
}
254
254
255
- /**
256
- * Reference to the listbox slot element.
257
- *
258
- * @internal
259
- */
260
- @observable
261
- public listboxSlot ! : HTMLSlotElement ;
262
-
263
255
/**
264
256
* Indicates whether the dropdown allows multiple options to be selected.
265
257
*
@@ -693,8 +685,6 @@ export class BaseDropdown extends FASTElement {
693
685
694
686
this . elementInternals . role = 'presentation' ;
695
687
696
- this . addEventListener ( 'connected' , this . listboxConnectedHandler ) ;
697
-
698
688
Updates . enqueue ( ( ) => {
699
689
this . insertControl ( ) ;
700
690
} ) ;
@@ -974,6 +964,24 @@ export class BaseDropdown extends FASTElement {
974
964
}
975
965
}
976
966
967
+ /**
968
+ * Handles the `slotchange` event for the dropdown.
969
+ * Sets the `listbox` property when a valid listbox is assigned to the default slot.
970
+ *
971
+ * @param e - the slot change event
972
+ * @internal
973
+ */
974
+ public slotchangeHandler ( e : Event ) : boolean | void {
975
+ const target = e . target as HTMLSlotElement ;
976
+
977
+ waitForConnectedDescendants ( this , ( ) => {
978
+ const listbox = target . assignedElements ( ) . find ( ( el ) : el is Listbox => isListbox ( el ) ) ;
979
+ if ( listbox ) {
980
+ this . listbox = listbox ;
981
+ }
982
+ } ) ;
983
+ }
984
+
977
985
/**
978
986
* Updates the freeform option with the provided value.
979
987
*
@@ -1009,20 +1017,6 @@ export class BaseDropdown extends FASTElement {
1009
1017
super . disconnectedCallback ( ) ;
1010
1018
}
1011
1019
1012
- /**
1013
- * Handles the connected event for the listbox.
1014
- *
1015
- * @param e - the event object
1016
- * @internal
1017
- */
1018
- private listboxConnectedHandler ( e : Event ) : void {
1019
- const target = e . target as HTMLElement ;
1020
-
1021
- if ( isListbox ( target ) ) {
1022
- this . listbox = target ;
1023
- }
1024
- }
1025
-
1026
1020
/**
1027
1021
* When anchor positioning isn't supported, an intersection observer is used to flip the listbox when it hits the
1028
1022
* viewport bounds. One static observer is used for all dropdowns.
0 commit comments