@@ -129,26 +129,11 @@ export class FieldDropdown extends Field<string> {
129129 // If we pass SKIP_SETUP, don't do *anything* with the menu generator.
130130 if ( menuGenerator === Field . SKIP_SETUP ) return ;
131131
132- if ( Array . isArray ( menuGenerator ) ) {
133- this . validateOptions ( menuGenerator ) ;
134- const trimmed = this . trimOptions ( menuGenerator ) ;
135- this . menuGenerator_ = trimmed . options ;
136- this . prefixField = trimmed . prefix || null ;
137- this . suffixField = trimmed . suffix || null ;
138- } else {
139- this . menuGenerator_ = menuGenerator ;
140- }
141-
142- /**
143- * The currently selected option. The field is initialized with the
144- * first option selected.
145- */
146- this . selectedOption = this . getOptions ( false ) [ 0 ] ;
132+ this . setOptions ( menuGenerator ) ;
147133
148134 if ( config ) {
149135 this . configure_ ( config ) ;
150136 }
151- this . setValue ( this . selectedOption [ 1 ] ) ;
152137 if ( validator ) {
153138 this . setValidator ( validator ) ;
154139 }
@@ -417,6 +402,28 @@ export class FieldDropdown extends Field<string> {
417402 return this . generatedOptions ;
418403 }
419404
405+ /**
406+ * Update the options on this dropdown. This will reset the selected item to
407+ * the first item in the list.
408+ *
409+ * @param menuGenerator The array of options or a generator function.
410+ */
411+ setOptions ( menuGenerator : MenuGenerator ) {
412+ if ( Array . isArray ( menuGenerator ) ) {
413+ this . validateOptions ( menuGenerator ) ;
414+ const trimmed = this . trimOptions ( menuGenerator ) ;
415+ this . menuGenerator_ = trimmed . options ;
416+ this . prefixField = trimmed . prefix || null ;
417+ this . suffixField = trimmed . suffix || null ;
418+ } else {
419+ this . menuGenerator_ = menuGenerator ;
420+ }
421+ // The currently selected option. The field is initialized with the
422+ // first option selected.
423+ this . selectedOption = this . getOptions ( false ) [ 0 ] ;
424+ this . setValue ( this . selectedOption [ 1 ] ) ;
425+ }
426+
420427 /**
421428 * Ensure that the input value is a valid language-neutral option.
422429 *
0 commit comments