Commit d62c01e 1 parent a641308 commit d62c01e Copy full SHA for d62c01e
File tree 3 files changed +36
-1
lines changed
3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @crowdstrike/glide-core ' : patch
3
+ ---
4
+
5
+ - Single-select Dropdown now clears its input field when its selected option is removed.
6
+ - Single-select Dropdown now sets the value of its input field to the label of the selected option on first render.
Original file line number Diff line number Diff line change @@ -792,6 +792,33 @@ it('sets the `value` of its `<input>` to the label of the selected option when n
792
792
expect ( input ?. value ) . to . equal ( option ?. label ) ;
793
793
} ) ;
794
794
795
+ it ( 'clears the `value` of its `<input>` when single-select and its selected option is removed' , async ( ) => {
796
+ const component = await fixture < GlideCoreDropdown > (
797
+ html `< glide-core-dropdown label ="Label " filterable >
798
+ < glide-core-dropdown-option
799
+ label ="One "
800
+ selected
801
+ > </ glide-core-dropdown-option >
802
+
803
+ < glide-core-dropdown-option label ="Two "> </ glide-core-dropdown-option >
804
+ </ glide-core-dropdown > ` ,
805
+ ) ;
806
+
807
+ component . querySelector ( 'glide-core-dropdown-option' ) ?. remove ( ) ;
808
+
809
+ // Wait for `#onDefaultSlotChange()`.
810
+ await aTimeout ( 0 ) ;
811
+
812
+ // Now wait for the forced update in `#onDefaultSlotChange()`.
813
+ await component . updateComplete ;
814
+
815
+ const input = component . shadowRoot ?. querySelector < HTMLInputElement > (
816
+ '[data-test="input"]' ,
817
+ ) ;
818
+
819
+ expect ( input ?. value ) . to . be . empty . string ;
820
+ } ) ;
821
+
795
822
it ( 'clears the `value` of its `<input>` when multiselect and an option is selected' , async ( ) => {
796
823
const component = await fixture < GlideCoreDropdown > (
797
824
html `< glide-core-dropdown label ="Label " placeholder ="Placeholder " multiple >
Original file line number Diff line number Diff line change @@ -1276,14 +1276,16 @@ export default class GlideCoreDropdown
1276
1276
if (
1277
1277
! this . multiple &&
1278
1278
this . #inputElementRef. value &&
1279
- this . lastSelectedOption ?. value
1279
+ this . lastSelectedOption
1280
1280
) {
1281
1281
this . #inputElementRef. value . value = this . lastSelectedOption . label ;
1282
1282
this . inputValue = this . lastSelectedOption . label ;
1283
1283
1284
1284
this . isInputOverflow =
1285
1285
this . #inputElementRef. value . scrollWidth >
1286
1286
this . #inputElementRef. value . clientWidth ;
1287
+ } else if ( ! this . multiple && this . #inputElementRef. value ) {
1288
+ this . #inputElementRef. value . value = '' ;
1287
1289
}
1288
1290
}
1289
1291
You can’t perform that action at this time.
0 commit comments