@@ -713,11 +713,12 @@ export class SelectPanelElement extends HTMLElement {
713
713
itemContent . setAttribute ( this . ariaSelectionType , 'false' )
714
714
}
715
715
} else if ( value && ! this . #selectedItems. has ( value ) && this . isItemChecked ( item ) ) {
716
- this . #hasLoadedData = true
717
716
this . #addSelectedItem( item )
718
717
}
719
718
}
720
719
720
+ this . #hasLoadedData = true
721
+
721
722
if ( ! this . noResults ) return
722
723
723
724
if ( this . #inErrorState( ) ) {
@@ -860,7 +861,8 @@ export class SelectPanelElement extends HTMLElement {
860
861
// interfere with events fired by menu items whose behavior is specified outside the library.
861
862
if ( this . selectVariant !== 'multiple' && this . selectVariant !== 'single' ) return
862
863
863
- const checked = ! this . isItemChecked ( item )
864
+ const currentlyChecked = this . isItemChecked ( item )
865
+ const checked = ! currentlyChecked
864
866
865
867
const activationSuccess = this . dispatchEvent (
866
868
new CustomEvent ( 'beforeItemActivated' , {
@@ -875,22 +877,21 @@ export class SelectPanelElement extends HTMLElement {
875
877
const itemContent = this . #getItemContent( item )
876
878
877
879
if ( this . selectVariant === 'single' ) {
878
- const value = this . selectedItems [ 0 ] ?. value
879
- const element = this . visibleItems . find ( el => this . #getItemContent( el ) ?. getAttribute ( 'data-value' ) === value )
880
+ // disallow unchecking checked item in single-select mode
881
+ if ( ! currentlyChecked ) {
882
+ for ( const el of this . items ) {
883
+ this . #getItemContent( el ) ?. setAttribute ( this . ariaSelectionType , 'false' )
884
+ }
880
885
881
- if ( element ) {
882
- this . #getItemContent( element ) ?. setAttribute ( this . ariaSelectionType , 'false' )
883
- }
886
+ this . #selectedItems. clear ( )
884
887
885
- this . #selectedItems. clear ( )
888
+ if ( checked ) {
889
+ this . #addSelectedItem( item )
890
+ itemContent ?. setAttribute ( this . ariaSelectionType , 'true' )
891
+ }
886
892
887
- // Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
888
- if ( checked ) {
889
- this . #addSelectedItem( item )
890
- itemContent ?. setAttribute ( this . ariaSelectionType , 'true' )
893
+ this . #setDynamicLabel( )
891
894
}
892
-
893
- this . #setDynamicLabel( )
894
895
} else {
895
896
// multi-select mode allows unchecking a checked item
896
897
itemContent ?. setAttribute ( this . ariaSelectionType , `${ checked } ` )
0 commit comments