@@ -25,9 +25,6 @@ import "./ha-svg-icon";
2525export class HaGenericPicker extends LitElement {
2626 @property ( { attribute : false } ) public hass ?: HomeAssistant ;
2727
28- // eslint-disable-next-line lit/no-native-attributes
29- @property ( { type : Boolean } ) public autofocus = false ;
30-
3128 @property ( { type : Boolean } ) public disabled = false ;
3229
3330 @property ( { type : Boolean } ) public required = false ;
@@ -49,8 +46,11 @@ export class HaGenericPicker extends LitElement {
4946 @property ( { attribute : "hide-clear-icon" , type : Boolean } )
5047 public hideClearIcon = false ;
5148
52- @property ( { attribute : false , type : Array } )
53- public getItems ?: ( ) => PickerComboBoxItem [ ] ;
49+ @property ( { attribute : false } )
50+ public getItems ?: (
51+ searchString ?: string ,
52+ section ?: string
53+ ) => ( PickerComboBoxItem | string ) [ ] ;
5454
5555 @property ( { attribute : false , type : Array } )
5656 public getAdditionalItems ?: ( searchString ?: string ) => PickerComboBoxItem [ ] ;
@@ -64,8 +64,11 @@ export class HaGenericPicker extends LitElement {
6464 @property ( { attribute : false } )
6565 public searchFn ?: PickerComboBoxSearchFn < PickerComboBoxItem > ;
6666
67- @property ( { attribute : "not-found-label" , type : String } )
68- public notFoundLabel ?: string ;
67+ @property ( { attribute : false } )
68+ public notFoundLabel ?: string | ( ( search : string ) => string ) ;
69+
70+ @property ( { attribute : "empty-label" } )
71+ public emptyLabel ?: string ;
6972
7073 @property ( { attribute : "popover-placement" } )
7174 public popoverPlacement :
@@ -85,6 +88,25 @@ export class HaGenericPicker extends LitElement {
8588 /** If set picker shows an add button instead of textbox when value isn't set */
8689 @property ( { attribute : "add-button-label" } ) public addButtonLabel ?: string ;
8790
91+ /** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
92+ @property ( { attribute : false } ) public sections ?: (
93+ | {
94+ id : string ;
95+ label : string ;
96+ }
97+ | "separator"
98+ ) [ ] ;
99+
100+ @property ( { attribute : false } ) public sectionTitleFunction ?: ( listInfo : {
101+ firstIndex : number ;
102+ lastIndex : number ;
103+ firstItem : PickerComboBoxItem | string ;
104+ secondItem : PickerComboBoxItem | string ;
105+ itemsCount : number ;
106+ } ) => string | undefined ;
107+
108+ @property ( { attribute : "selected-section" } ) public selectedSection ?: string ;
109+
88110 @query ( ".container" ) private _containerElement ?: HTMLDivElement ;
89111
90112 @query ( "ha-picker-combo-box" ) private _comboBox ?: HaPickerComboBox ;
@@ -97,6 +119,11 @@ export class HaGenericPicker extends LitElement {
97119
98120 @state ( ) private _openedNarrow = false ;
99121
122+ static shadowRootOptions = {
123+ ...LitElement . shadowRootOptions ,
124+ delegatesFocus : true ,
125+ } ;
126+
100127 private _narrow = false ;
101128
102129 // helper to set new value after closing picker, to avoid flicker
@@ -189,16 +216,19 @@ export class HaGenericPicker extends LitElement {
189216 <ha- picker- combo- box
190217 .hass = ${ this . hass }
191218 .allowCustomValue = ${ this . allowCustomValue }
192- .label = ${ this . searchLabel ??
193- ( this . hass ?. localize ( "ui.common.search" ) || "Search" ) }
219+ .label = ${ this . searchLabel }
194220 .value = ${ this . value }
195221 @value-changed = ${ this . _valueChanged }
196222 .rowRenderer = ${ this . rowRenderer }
197223 .notFoundLabel = ${ this . notFoundLabel }
224+ .emptyLabel = ${ this . emptyLabel }
198225 .getItems = ${ this . getItems }
199226 .getAdditionalItems = ${ this . getAdditionalItems }
200227 .searchFn = ${ this . searchFn }
201228 .mode = ${ dialogMode ? "dialog" : "popover" }
229+ .sections = ${ this . sections }
230+ .sectionTitleFunction = ${ this . sectionTitleFunction }
231+ .selectedSection = ${ this . selectedSection }
202232 > </ ha- picker- combo- box>
203233 ` ;
204234 }
0 commit comments