mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Allow to sort options in select selector (#17468)
This commit is contained in:
parent
a8debb8daa
commit
b4e2f4b0f5
@ -16,6 +16,7 @@ import "../ha-formfield";
|
||||
import "../ha-radio";
|
||||
import "../ha-select";
|
||||
import "../ha-input-helper-text";
|
||||
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||
|
||||
@customElement("ha-selector-select")
|
||||
export class HaSelectSelector extends LitElement {
|
||||
@ -51,12 +52,25 @@ export class HaSelectSelector extends LitElement {
|
||||
|
||||
if (this.localizeValue && translationKey) {
|
||||
options.forEach((option) => {
|
||||
option.label =
|
||||
this.localizeValue!(`${translationKey}.options.${option.value}`) ||
|
||||
option.label;
|
||||
const localizedLabel = this.localizeValue!(
|
||||
`${translationKey}.options.${option.value}`
|
||||
);
|
||||
if (localizedLabel) {
|
||||
option.label = localizedLabel;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.selector.select?.sort) {
|
||||
options.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(
|
||||
a.label,
|
||||
b.label,
|
||||
this.hass.locale.language
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.selector.select?.custom_value && this._mode === "list") {
|
||||
if (!this.selector.select?.multiple) {
|
||||
return html`
|
||||
|
@ -296,6 +296,7 @@ export interface SelectSelector {
|
||||
mode?: "list" | "dropdown";
|
||||
options: readonly string[] | readonly SelectOption[];
|
||||
translation_key?: string;
|
||||
sort?: boolean;
|
||||
} | null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user