@@ -136,26 +136,11 @@ export class FieldDropdown extends Field<string> {
136136 // If we pass SKIP_SETUP, don't do *anything* with the menu generator.
137137 if ( menuGenerator === Field . SKIP_SETUP ) return ;
138138
139- if ( Array . isArray ( menuGenerator ) ) {
140- this . validateOptions ( menuGenerator ) ;
141- const trimmed = this . trimOptions ( menuGenerator ) ;
142- this . menuGenerator_ = trimmed . options ;
143- this . prefixField = trimmed . prefix || null ;
144- this . suffixField = trimmed . suffix || null ;
145- } else {
146- this . menuGenerator_ = menuGenerator ;
147- }
148-
149- /**
150- * The currently selected option. The field is initialized with the
151- * first option selected.
152- */
153- this . selectedOption = this . getOptions ( false ) [ 0 ] ;
139+ this . setOptions ( menuGenerator ) ;
154140
155141 if ( config ) {
156142 this . configure_ ( config ) ;
157143 }
158- this . setValue ( this . selectedOption [ 1 ] ) ;
159144 if ( validator ) {
160145 this . setValidator ( validator ) ;
161146 }
@@ -414,6 +399,28 @@ export class FieldDropdown extends Field<string> {
414399 return this . generatedOptions ;
415400 }
416401
402+ /**
403+ * Update the options on this dropdown. This will reset the selected item to
404+ * the first item in the list.
405+ *
406+ * @param menuGenerator The array of options or a generator function.
407+ */
408+ setOptions ( menuGenerator : MenuGenerator ) {
409+ if ( Array . isArray ( menuGenerator ) ) {
410+ this . validateOptions ( menuGenerator ) ;
411+ const trimmed = this . trimOptions ( menuGenerator ) ;
412+ this . menuGenerator_ = trimmed . options ;
413+ this . prefixField = trimmed . prefix || null ;
414+ this . suffixField = trimmed . suffix || null ;
415+ } else {
416+ this . menuGenerator_ = menuGenerator ;
417+ }
418+ // The currently selected option. The field is initialized with the
419+ // first option selected.
420+ this . selectedOption = this . getOptions ( false ) [ 0 ] ;
421+ this . setValue ( this . selectedOption [ 1 ] ) ;
422+ }
423+
417424 /**
418425 * Ensure that the input value is a valid language-neutral option.
419426 *
0 commit comments