File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,8 @@ export class UUISelectElement extends FormControlMixin(LitElement) {
158
158
@state ( )
159
159
private _disabledGroups : string [ ] = [ ] ;
160
160
161
+ private _values : string [ ] = [ ] ;
162
+
161
163
@query ( '#native' )
162
164
protected _input ! : HTMLSelectElement ;
163
165
@@ -212,9 +214,16 @@ export class UUISelectElement extends FormControlMixin(LitElement) {
212
214
willUpdate ( changedProperties : Map < string | number | symbol , unknown > ) {
213
215
if ( changedProperties . has ( 'options' ) ) {
214
216
this . _extractGroups ( ) ;
217
+ this . _values = this . options . map ( option => option . value ) ;
215
218
const selected = this . options . find ( option => option . selected ) ;
216
219
this . value = selected ? selected . value : '' ;
217
220
}
221
+
222
+ if ( changedProperties . has ( 'value' ) ) {
223
+ this . value = this . _values . includes ( this . value as string )
224
+ ? this . value
225
+ : '' ;
226
+ }
218
227
if ( changedProperties . has ( 'disabledGroups' ) ) this . _createDisabledGroups ( ) ;
219
228
}
220
229
Original file line number Diff line number Diff line change @@ -75,6 +75,14 @@ describe('UUISelect in Form', () => {
75
75
expect ( element . value ) . to . be . equal ( 'orange' ) ;
76
76
} ) ;
77
77
78
+ it ( 'if value is set to a string that is not in the options array the value is empty string' , async ( ) => {
79
+ element . value = 'something silly' ;
80
+ await elementUpdated ( element ) ;
81
+ const formData = new FormData ( formElement ) ;
82
+ expect ( element . value ) . to . be . equal ( '' ) ;
83
+ expect ( formData . get ( 'bar' ) ) . to . be . equal ( '' ) ;
84
+ } ) ;
85
+
78
86
it ( 'form output' , ( ) => {
79
87
const formData = new FormData ( formElement ) ;
80
88
expect ( formData . get ( 'bar' ) ) . to . be . equal ( 'orange' ) ;
You can’t perform that action at this time.
0 commit comments