@@ -232,20 +232,24 @@ export class BaseDropdown extends FASTElement {
232232
233233 notifier . notify ( 'multiple' ) ;
234234
235- Updates . enqueue ( ( ) => {
236- this . options . forEach ( option => {
237- option . disabled = option . disabledAttribute || this . disabled ;
238- option . name = this . name ;
239- } ) ;
240-
241- this . enabledOptions
242- . filter ( x => x . defaultSelected )
243- . forEach ( ( x , i ) => {
244- x . selected = this . multiple || i === 0 ;
235+ waitForConnectedDescendants (
236+ next ,
237+ ( ) => {
238+ this . options . forEach ( option => {
239+ option . disabled = option . disabledAttribute || this . disabled ;
240+ option . name = this . name ;
245241 } ) ;
246242
247- this . setValidity ( ) ;
248- } ) ;
243+ this . enabledOptions
244+ . filter ( x => x . defaultSelected )
245+ . forEach ( ( x , i ) => {
246+ x . selected = this . multiple || i === 0 ;
247+ } ) ;
248+
249+ this . setValidity ( ) ;
250+ } ,
251+ { idleCallback : true } ,
252+ ) ;
249253
250254 if ( AnchorPositioningCSSSupported ) {
251255 // The `anchor-name` property seems to not be isolated between instances in Safari Technology Preview 220 (18.4).
@@ -801,6 +805,12 @@ export class BaseDropdown extends FASTElement {
801805 return true ;
802806 }
803807
808+ /**
809+ * Guard flag to prevent reentrant calls to `insertControl`.
810+ * @internal
811+ */
812+ private _insertingControl = false ;
813+
804814 /**
805815 * Inserts the control element based on the dropdown type.
806816 *
@@ -809,6 +819,11 @@ export class BaseDropdown extends FASTElement {
809819 * This method can be overridden in derived classes to provide custom control elements, though this is not recommended.
810820 */
811821 protected insertControl ( ) : void {
822+ if ( this . _insertingControl ) {
823+ return ;
824+ }
825+
826+ this . _insertingControl = true ;
812827 this . controlSlot ?. assignedNodes ( ) . forEach ( x => this . removeChild ( x ) ) ;
813828
814829 if ( this . type === DropdownType . combobox ) {
@@ -817,6 +832,7 @@ export class BaseDropdown extends FASTElement {
817832 }
818833
819834 dropdownButtonTemplate . render ( this , this ) ;
835+ this . _insertingControl = false ;
820836 }
821837
822838 /**
@@ -930,7 +946,9 @@ export class BaseDropdown extends FASTElement {
930946 */
931947 public selectOption ( index : number = this . selectedIndex , shouldEmit : boolean = false ) : void {
932948 this . listbox . selectOption ( index ) ;
933- this . control . value = this . displayValue ;
949+ if ( this . control ) {
950+ this . control . value = this . displayValue ;
951+ }
934952
935953 this . setValidity ( ) ;
936954
@@ -951,20 +969,22 @@ export class BaseDropdown extends FASTElement {
951969 * @internal
952970 */
953971 public setValidity ( flags ?: Partial < ValidityState > , message ?: string , anchor ?: HTMLElement ) : void {
954- if ( this . $fastController . isConnected ) {
955- if ( this . disabled || ! this . required ) {
956- this . elementInternals . setValidity ( { } ) ;
957- return ;
958- }
959-
960- const valueMissing = this . required && this . listbox . selectedOptions . length === 0 ;
972+ if ( ! this . elementInternals ) {
973+ return ;
974+ }
961975
962- this . elementInternals . setValidity (
963- { valueMissing, ...flags } ,
964- message ?? this . validationMessage ,
965- anchor ?? this . control ,
966- ) ;
976+ if ( this . disabled || ! this . required ) {
977+ this . elementInternals . setValidity ( { } ) ;
978+ return ;
967979 }
980+
981+ const valueMissing = this . required && this . listbox . selectedOptions . length === 0 ;
982+
983+ this . elementInternals . setValidity (
984+ { valueMissing, ...flags } ,
985+ message ?? this . validationMessage ,
986+ anchor ?? this . control ,
987+ ) ;
968988 }
969989
970990 /**
0 commit comments