Enable disabled select options

This commit is contained in:
nathan 2023-02-22 09:51:57 -07:00
parent bf6891d06a
commit f7d44c63cb
3 changed files with 8 additions and 3 deletions

View File

@ -580,7 +580,9 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
return html` return html`
<sl-menu-item value="${option.value}" <sl-menu-item value="${option.value}"
title="${!option.title || this.noLang ? option.title : this.egw().lang(option.title)}" title="${!option.title || this.noLang ? option.title : this.egw().lang(option.title)}"
class="${option.class}" .option=${option}> class="${option.class}" .option=${option}
?disabled=${option.disabled}
>
${this._iconTemplate(option)} ${this._iconTemplate(option)}
${this.noLang ? option.label : this.egw().lang(option.label)} ${this.noLang ? option.label : this.egw().lang(option.label)}
</sl-menu-item>`; </sl-menu-item>`;
@ -623,7 +625,7 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
{ {
tag.size = this.size; tag.size = this.size;
} }
if(this.readonly) if(this.readonly || item.option && typeof (item.option.disabled) != "undefined" && item.option.disabled)
{ {
tag.removable = false; tag.removable = false;
tag.readonly = true; tag.readonly = true;

View File

@ -8,6 +8,9 @@ export interface SelectOption
icon? : string; icon? : string;
// Class applied to node // Class applied to node
class? : string; class? : string;
// Show the option, but it is not selectable.
// If multiple=true and the option is in the value, it is not removable.
disabled? : boolean;
} }
/** /**

View File

@ -1080,7 +1080,7 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
// Reset remaining options. It might be faster to re-create instead. // Reset remaining options. It might be faster to re-create instead.
this._menuItems.forEach((item) => this._menuItems.forEach((item) =>
{ {
item.disabled = false; item.disabled = item.option?.disabled || false;
item.classList.remove("match"); item.classList.remove("match");
item.classList.remove("no-match"); item.classList.remove("no-match");
}); });