2024-07-26 18:16:49 +02:00
|
|
|
import {LitElement, nothing, PropertyValues, TemplateResult} from "lit";
|
2024-02-15 18:13:01 +01:00
|
|
|
import {html, literal, StaticValue} from "lit/static-html.js";
|
2024-08-22 14:35:36 +02:00
|
|
|
import {Et2Tree, TreeItemData} from "./Et2Tree";
|
2024-02-13 01:19:24 +01:00
|
|
|
import {Et2WidgetWithSelectMixin} from "../Et2Select/Et2WidgetWithSelectMixin";
|
|
|
|
import {property} from "lit/decorators/property.js";
|
|
|
|
import {classMap} from "lit/directives/class-map.js";
|
2024-02-13 17:33:07 +01:00
|
|
|
import {state} from "lit/decorators/state.js";
|
2024-02-13 01:19:24 +01:00
|
|
|
import {HasSlotController} from "../Et2Widget/slot";
|
|
|
|
import {map} from "lit/directives/map.js";
|
2024-08-22 14:35:36 +02:00
|
|
|
import {SlPopup, SlRemoveEvent, SlTreeItem} from "@shoelace-style/shoelace";
|
2024-02-13 01:19:24 +01:00
|
|
|
import shoelace from "../Styles/shoelace";
|
|
|
|
import styles from "./Et2TreeDropdown.styles";
|
2024-02-13 17:33:07 +01:00
|
|
|
import {Et2Tag} from "../Et2Select/Tag/Et2Tag";
|
2024-09-18 16:11:25 +02:00
|
|
|
import {SearchMixin, SearchResult, SearchResultElement, SearchResultsInterface} from "../Et2Widget/SearchMixin";
|
2024-02-22 22:33:22 +01:00
|
|
|
import {Et2InputWidgetInterface} from "../Et2InputWidget/Et2InputWidget";
|
2024-07-26 18:16:49 +02:00
|
|
|
import {Required} from "../Validators/Required";
|
2024-09-18 16:11:25 +02:00
|
|
|
import {SelectOption} from "../Et2Select/FindSelectOptions";
|
2024-02-22 22:33:22 +01:00
|
|
|
|
|
|
|
|
2024-08-22 14:35:36 +02:00
|
|
|
interface TreeSearchResults extends SearchResultsInterface<TreeItemData>
|
2024-02-22 22:33:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
type Constructor<T = {}> = new (...args : any[]) => T;
|
2024-02-13 01:19:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @summary A tree that is hidden in a dropdown
|
|
|
|
*
|
|
|
|
* @dependency sl-dropdown
|
|
|
|
* @dependency et2-tree
|
|
|
|
* @dependency et2-tag
|
|
|
|
*
|
|
|
|
* @slot label - The input's label. Alternatively, you can use the `label` attribute.
|
2024-02-20 17:56:07 +01:00
|
|
|
* @slot prefix - Used to prepend a presentational icon or similar element to the combobox.
|
|
|
|
* @slot suffix - Used to append a presentational icon or similar element to the input.
|
|
|
|
* @slot expand-icon - The icon to show when the control is expanded and collapsed. Rotates on open and close.
|
2024-02-13 01:19:24 +01:00
|
|
|
* @slot help-text - Text that describes how to use the input. Alternatively, you can use the `help-text` attribute.
|
|
|
|
*
|
|
|
|
* @event change - Emitted when the control's value changes.
|
|
|
|
* @event sl-show - Emitted when the suggestion menu opens.
|
|
|
|
* @event sl-after-show - Emitted after the suggestion menu opens and all animations are complete.
|
|
|
|
* @event sl-hide - Emitted when the suggestion menu closes.
|
|
|
|
* @event sl-after-hide - Emitted after the suggestion menu closes and all animations are complete.
|
|
|
|
*
|
|
|
|
* @csspart form-control - The form control that wraps the label, input, and help text.
|
2024-06-18 11:09:06 +02:00
|
|
|
* @since 23.1.x
|
2024-02-13 01:19:24 +01:00
|
|
|
*/
|
|
|
|
|
2024-08-22 14:35:36 +02:00
|
|
|
export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidgetInterface & typeof LitElement, TreeItemData, TreeSearchResults>(Et2WidgetWithSelectMixin(LitElement))
|
2024-02-13 01:19:24 +01:00
|
|
|
{
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
shoelace,
|
2024-02-22 22:33:22 +01:00
|
|
|
super.styles,
|
2024-02-13 01:19:24 +01:00
|
|
|
styles
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
/**
|
|
|
|
* List of properties that get translated
|
|
|
|
* @returns object
|
|
|
|
*/
|
|
|
|
static get translate()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.translate,
|
|
|
|
placeholder: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
/** Placeholder text to show as a hint when the select is empty. */
|
|
|
|
@property() placeholder = "";
|
|
|
|
|
|
|
|
@property({type: Boolean, reflect: true}) multiple = false;
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
/** Adds a clear button when the dropdown is not empty. */
|
|
|
|
@property({type: Boolean}) clearable = false;
|
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
/** The component's help text. If you need to display HTML, use the `help-text` slot instead. */
|
|
|
|
@property({attribute: 'help-text'}) helpText = "";
|
|
|
|
|
2024-08-22 14:18:32 +02:00
|
|
|
/** "JSON URL or menuaction to be called for nodes marked with child=1, but not having children, getSelectedNode() contains node-id" */
|
2024-04-22 16:52:47 +02:00
|
|
|
@property({type: String})
|
2024-08-22 14:18:32 +02:00
|
|
|
autoloading: string = "";
|
2024-04-22 16:52:47 +02:00
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
/**
|
|
|
|
* Indicates whether the dropdown is open. You can toggle this attribute to show and hide the tree, or you can
|
|
|
|
* use the `show()` and `hide()` methods and this attribute will reflect the open state.
|
|
|
|
*/
|
|
|
|
@property({type: Boolean, reflect: true}) open = false;
|
|
|
|
|
2024-02-27 19:22:55 +01:00
|
|
|
/**
|
|
|
|
* Actions (passed to the tree)
|
|
|
|
* @type {{}}
|
|
|
|
*/
|
|
|
|
@property({type: Object}) actions = {};
|
|
|
|
|
2024-08-22 14:18:32 +02:00
|
|
|
/**
|
|
|
|
* If true, only leafs (NOT folders) are selectable
|
|
|
|
*/
|
2024-08-22 10:52:24 +02:00
|
|
|
@property()
|
2024-08-22 12:54:27 +02:00
|
|
|
set leafOnly(_leafOnly: boolean)
|
|
|
|
{
|
|
|
|
this.updateComplete.then(() => {
|
|
|
|
const tree = this._tree
|
|
|
|
if (tree)
|
|
|
|
{
|
|
|
|
tree.leafOnly = _leafOnly;
|
|
|
|
tree.requestUpdate("leafOnly")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2024-08-22 14:18:32 +02:00
|
|
|
get leafOnly()
|
|
|
|
{
|
|
|
|
return this._tree?.leafOnly;
|
|
|
|
}
|
2024-08-22 10:52:24 +02:00
|
|
|
|
2024-08-21 20:45:38 +02:00
|
|
|
@state() currentTag: Et2Tag;
|
2024-02-13 01:19:24 +01:00
|
|
|
|
2024-02-22 22:33:22 +01:00
|
|
|
// We show search results in the same dropdown
|
|
|
|
@state() treeOrSearch : "tree" | "search" = "tree";
|
|
|
|
|
2024-08-22 12:54:27 +02:00
|
|
|
private get _popup(): SlPopup
|
|
|
|
{
|
|
|
|
return this.shadowRoot?.querySelector("sl-popup")
|
|
|
|
}
|
|
|
|
|
|
|
|
private get _tree(): Et2Tree
|
|
|
|
{
|
|
|
|
return this.shadowRoot?.querySelector("et2-tree")
|
|
|
|
}
|
2024-02-13 01:19:24 +01:00
|
|
|
|
2024-02-13 17:33:07 +01:00
|
|
|
private get _tags() : Et2Tag[] { return Array.from(this.shadowRoot.querySelectorAll("et2-tag"));}
|
|
|
|
|
2024-02-22 22:33:22 +01:00
|
|
|
protected readonly hasSlotController = new HasSlotController(<LitElement><unknown>this, "help-text", "label");
|
2024-02-13 01:19:24 +01:00
|
|
|
private __value : string[];
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
protected displayLabel = '';
|
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.__value = [];
|
2024-02-27 00:54:07 +01:00
|
|
|
|
|
|
|
this.handleDocumentClick = this.handleDocumentClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
2024-09-18 16:11:25 +02:00
|
|
|
document.addEventListener("click", this.handleDocumentClick);
|
2024-02-27 00:54:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
disconnectedCallback()
|
|
|
|
{
|
|
|
|
super.disconnectedCallback();
|
2024-09-18 16:11:25 +02:00
|
|
|
document.removeEventListener("click", this.handleDocumentClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
willUpdate(changedProperties)
|
|
|
|
{
|
|
|
|
super.willUpdate(changedProperties);
|
|
|
|
|
|
|
|
// Child tree not updating when our emptyLabel changes
|
|
|
|
if(this._tree && (changedProperties.has("select_options") || changedProperties.has("emptyLabel")))
|
|
|
|
{
|
|
|
|
let options = this.multiple || !this.emptyLabel ? this.select_options : [{
|
|
|
|
value: "",
|
|
|
|
label: this.emptyLabel
|
|
|
|
}, ...this.select_options];
|
|
|
|
|
|
|
|
this._tree._selectOptions = <TreeItemData[]>options;
|
|
|
|
this._tree.requestUpdate("_selectOptions");
|
|
|
|
}
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
|
2024-07-26 18:16:49 +02:00
|
|
|
updated(changedProperties : PropertyValues)
|
2024-02-23 18:49:16 +01:00
|
|
|
{
|
2024-07-26 18:16:49 +02:00
|
|
|
super.updated(changedProperties);
|
|
|
|
|
|
|
|
// required changed, add / remove validator
|
|
|
|
if(changedProperties.has('required'))
|
|
|
|
{
|
|
|
|
// Remove all existing Required validators (avoids duplicates)
|
|
|
|
this.validators = (this.validators || []).filter((validator) => !(validator instanceof Required))
|
|
|
|
if(this.required)
|
|
|
|
{
|
|
|
|
this.validators.push(new Required());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(changedProperties.has("value"))
|
|
|
|
{
|
|
|
|
// Base off this.value, not this.getValue(), to ignore readonly
|
|
|
|
this.classList.toggle("hasValue", !(this.value == null || this.value == ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass aria-attributes to our input node
|
|
|
|
if(changedProperties.has('ariaLabel') || changedProperties.has('ariaDescription'))
|
|
|
|
{
|
|
|
|
this._setAriaAttributes();
|
|
|
|
}
|
|
|
|
|
2024-02-23 18:49:16 +01:00
|
|
|
// @ts-ignore Popup sometimes loses the anchor which breaks the sizing
|
|
|
|
this._popup.handleAnchorChange();
|
|
|
|
}
|
2024-07-26 18:16:49 +02:00
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
/** Selected tree leaves */
|
|
|
|
@property()
|
|
|
|
set value(new_value : string | string[])
|
|
|
|
{
|
2024-08-21 13:05:06 +02:00
|
|
|
if(!new_value)new_value="";
|
2024-08-22 14:35:36 +02:00
|
|
|
// @ts-ignore handling invalid number type gracefully
|
|
|
|
if(typeof new_value === 'number')
|
|
|
|
{
|
|
|
|
new_value = ""+new_value;
|
|
|
|
}
|
2024-02-13 01:19:24 +01:00
|
|
|
if(typeof new_value === "string")
|
|
|
|
{
|
|
|
|
new_value = new_value.split(",")
|
|
|
|
}
|
|
|
|
const oldValue = this.__value;
|
2024-02-22 22:33:22 +01:00
|
|
|
// Filter to make sure there are no trailing commas or duplicates
|
|
|
|
this.__value = Array.from(new Set(<string[]>new_value.filter(v => v)));
|
2024-09-18 16:11:25 +02:00
|
|
|
|
|
|
|
this.displayLabel = "";
|
|
|
|
if(!this.multiple)
|
|
|
|
{
|
|
|
|
const option = this.optionSearch(this.__value[0], this.select_options, 'value', 'children');
|
|
|
|
if(option)
|
|
|
|
{
|
|
|
|
this.displayLabel = option.label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
this.requestUpdate("value", oldValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
get value() : string | string[]
|
|
|
|
{
|
|
|
|
return this.multiple ? this.__value : (
|
|
|
|
this.__value?.length ? this.__value[0] : ""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-21 20:45:38 +02:00
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
get select_options() : SelectOption[]
|
|
|
|
{
|
|
|
|
return super.select_options;
|
|
|
|
}
|
2024-08-21 20:45:38 +02:00
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
set select_options(new_options : SelectOption[])
|
2024-02-13 17:33:07 +01:00
|
|
|
{
|
2024-09-18 16:11:25 +02:00
|
|
|
super.select_options = new_options;
|
2024-02-13 17:33:07 +01:00
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
// Overridden so we can update displayLabel in the case where value got set before selectOptions
|
|
|
|
if(this.value && !this.multiple)
|
2024-02-13 17:33:07 +01:00
|
|
|
{
|
2024-09-18 16:11:25 +02:00
|
|
|
const option = this.optionSearch(typeof this.value == "string" ? this.value : this.value[0], this.select_options, 'value', 'children');
|
|
|
|
if(option)
|
|
|
|
{
|
|
|
|
this.displayLabel = option.label;
|
|
|
|
}
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
/** Sets focus on the control. */
|
|
|
|
focus(options? : FocusOptions)
|
|
|
|
{
|
|
|
|
this.handleFocus();
|
|
|
|
}
|
|
|
|
|
2024-02-13 17:33:07 +01:00
|
|
|
/** Removes focus from the control. */
|
|
|
|
blur()
|
|
|
|
{
|
2024-09-18 16:11:25 +02:00
|
|
|
this.handleBlur();
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Shows the tree. */
|
|
|
|
async show()
|
|
|
|
{
|
2024-09-18 16:11:25 +02:00
|
|
|
if(this.readonly || this.disabled)
|
2024-02-13 17:33:07 +01:00
|
|
|
{
|
|
|
|
this.open = false;
|
|
|
|
this.requestUpdate("open", true);
|
2024-09-18 16:11:25 +02:00
|
|
|
return this.updateComplete;
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.open = true;
|
|
|
|
this.requestUpdate("open", false)
|
|
|
|
return this.updateComplete
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Hides the tree. */
|
|
|
|
async hide()
|
|
|
|
{
|
|
|
|
if(!this.open || this.disabled)
|
|
|
|
{
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.open = false;
|
|
|
|
this._popup.active = false;
|
2024-02-22 22:33:22 +01:00
|
|
|
this._searchNode.value = "";
|
2024-02-13 17:33:07 +01:00
|
|
|
this.requestUpdate("open");
|
|
|
|
return this.updateComplete
|
|
|
|
}
|
|
|
|
|
|
|
|
private setCurrentTag(tag : Et2Tag)
|
|
|
|
{
|
|
|
|
this._tags.forEach(t =>
|
|
|
|
{
|
|
|
|
t.tabIndex = -1;
|
|
|
|
if(t.current)
|
|
|
|
{
|
|
|
|
t.current = false;
|
|
|
|
t.requestUpdate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.currentTag = tag;
|
|
|
|
if(tag)
|
|
|
|
{
|
|
|
|
this.currentTag.tabIndex = 0;
|
|
|
|
this.currentTag.current = true;
|
|
|
|
this.currentTag.requestUpdate();
|
|
|
|
this.currentTag.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 22:33:22 +01:00
|
|
|
|
|
|
|
startSearch()
|
|
|
|
{
|
|
|
|
super.startSearch();
|
|
|
|
|
|
|
|
// Show the dropdown, that's where the results will go
|
2024-07-10 21:13:55 +02:00
|
|
|
this.open = true;
|
2024-02-22 22:33:22 +01:00
|
|
|
|
|
|
|
// Hide the tree
|
|
|
|
this.treeOrSearch = "search";
|
|
|
|
}
|
|
|
|
|
2024-02-23 18:49:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If you have a local list of options, you can search through them on the client and include them in the results.
|
|
|
|
*
|
|
|
|
* This is done independently from the server-side search, and the results are merged.
|
|
|
|
*
|
|
|
|
* @param {string} search
|
|
|
|
* @param {object} options
|
|
|
|
* @returns {Promise<any[]>}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected localSearch<DataType extends SearchResult>(search : string, searchOptions : object, localOptions : DataType[] = []) : Promise<DataType[]>
|
|
|
|
{
|
|
|
|
return super.localSearch(search, searchOptions, this.select_options);
|
|
|
|
}
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
/**
|
|
|
|
* Toggles a search result's selected state
|
|
|
|
* Overridden to handle multiple attribute so only 1 result is selected
|
|
|
|
*/
|
|
|
|
protected toggleResultSelection(result : HTMLElement & SearchResultElement, force? : boolean)
|
|
|
|
{
|
|
|
|
if(!this.multiple)
|
|
|
|
{
|
|
|
|
this._resultNodes.forEach(t => t.selected = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.toggleResultSelection(result, force);
|
|
|
|
}
|
|
|
|
|
2024-02-22 22:33:22 +01:00
|
|
|
protected searchResultSelected()
|
|
|
|
{
|
|
|
|
super.searchResultSelected();
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
const oldValue = [...this.value];
|
2024-02-22 22:33:22 +01:00
|
|
|
if(this.multiple && typeof this.value !== "undefined")
|
|
|
|
{
|
2024-07-10 21:13:55 +02:00
|
|
|
// Add in the new result(s), no duplicates
|
|
|
|
this.value = [...new Set([...this.value, ...this.selectedResults.map(el => el.value)])];
|
2024-02-22 22:33:22 +01:00
|
|
|
}
|
|
|
|
else if(typeof this.value !== "undefined")
|
|
|
|
{
|
|
|
|
// Just replace our value with whatever they chose
|
|
|
|
this.value = this.selectedResults[0]?.value ?? "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done with search, show the tree
|
|
|
|
this.treeOrSearch = "tree";
|
2024-09-18 16:11:25 +02:00
|
|
|
|
|
|
|
// Close the dropdown, move on
|
|
|
|
if(!this.multiple || this.egw().preference("select_multiple_close") == "close")
|
|
|
|
{
|
|
|
|
this.blur();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._tree.value = <string[]>this.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update values
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event("change", {bubbles: true}));
|
|
|
|
});
|
|
|
|
this._tree.requestUpdate("value", oldValue);
|
|
|
|
this.requestUpdate("value", oldValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleClearClick(event : MouseEvent)
|
|
|
|
{
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
if(this.value.length > 0)
|
|
|
|
{
|
|
|
|
this.value = [];
|
|
|
|
this.displayInput.focus({preventScroll: true});
|
|
|
|
|
|
|
|
// Emit after update
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.emit('sl-clear');
|
|
|
|
this.emit('sl-input');
|
|
|
|
this.emit('sl-change');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleClearMouseDown(event : MouseEvent)
|
|
|
|
{
|
|
|
|
// Don't lose focus or propagate events when clicking the clear button
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2024-02-22 22:33:22 +01:00
|
|
|
}
|
|
|
|
|
2024-02-13 17:33:07 +01:00
|
|
|
/**
|
|
|
|
* Keyboard events that the search input did not grab
|
2024-09-18 22:05:58 +02:00
|
|
|
* (tags, option navigation)
|
2024-02-13 17:33:07 +01:00
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} event
|
|
|
|
*/
|
|
|
|
handleComboboxKeyDown(event : KeyboardEvent)
|
|
|
|
{
|
|
|
|
// Navigate between tags
|
|
|
|
if(this.currentTag && (["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)))
|
|
|
|
{
|
|
|
|
let nextTagIndex = this._tags.indexOf(this.currentTag);
|
|
|
|
const tagCount = this._tags.length
|
|
|
|
switch(event.key)
|
|
|
|
{
|
|
|
|
case 'ArrowLeft':
|
|
|
|
nextTagIndex--;
|
|
|
|
break;
|
|
|
|
case 'ArrowRight':
|
|
|
|
nextTagIndex++;
|
|
|
|
break;
|
|
|
|
case 'Home':
|
|
|
|
nextTagIndex = 0;
|
|
|
|
break;
|
|
|
|
case 'End':
|
|
|
|
nextTagIndex = this._tags.length - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nextTagIndex = Math.max(0, nextTagIndex);
|
|
|
|
if(nextTagIndex < tagCount && this._tags[nextTagIndex])
|
|
|
|
{
|
|
|
|
this.setCurrentTag(this._tags[nextTagIndex]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Arrow back to search, or got lost
|
2024-02-22 22:33:22 +01:00
|
|
|
this._searchNode.focus();
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Remove tag
|
|
|
|
if(event.target instanceof Et2Tag && ["Delete", "Backspace"].includes(event.key))
|
|
|
|
{
|
|
|
|
const tags = this._tags;
|
|
|
|
let index = tags.indexOf(event.target);
|
|
|
|
event.target.dispatchEvent(new CustomEvent('sl-remove', {bubbles: true}));
|
|
|
|
index += event.key == "Delete" ? 1 : -1;
|
|
|
|
if(index >= 0 && index < tags.length)
|
|
|
|
{
|
|
|
|
this.setCurrentTag(this._tags[index]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-22 22:33:22 +01:00
|
|
|
this._searchNode.focus();
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
2024-09-18 22:05:58 +02:00
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Close popup if focus is on tree
|
|
|
|
if(["Escape"].includes(event.key))
|
|
|
|
{
|
|
|
|
this.hide();
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 00:54:07 +01:00
|
|
|
protected handleDocumentClick(event)
|
|
|
|
{
|
|
|
|
if(event.target == this || event.composedPath().includes(this))
|
|
|
|
{
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(this.open)
|
|
|
|
{
|
|
|
|
event.preventDefault();
|
|
|
|
this.hide()
|
|
|
|
}
|
2024-10-08 01:02:18 +02:00
|
|
|
if(this.hasFocus)
|
|
|
|
{
|
|
|
|
this.blur();
|
|
|
|
}
|
2024-09-18 16:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private handleFocus()
|
|
|
|
{
|
2024-10-30 18:31:58 +01:00
|
|
|
if(this.disabled || this.readonly)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2024-09-18 16:11:25 +02:00
|
|
|
this.hasFocus = true;
|
|
|
|
// Should not be needed, but not firing the update
|
|
|
|
this.requestUpdate("hasFocus");
|
|
|
|
|
|
|
|
this.updateComplete.then(() =>
|
2024-02-27 00:54:07 +01:00
|
|
|
{
|
2024-09-18 16:11:25 +02:00
|
|
|
if(this._searchNode)
|
|
|
|
{
|
|
|
|
this._searchNode.focus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._tree.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dispatchEvent(new Event("sl-focus"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleBlur()
|
|
|
|
{
|
|
|
|
this.open = false;
|
|
|
|
this.treeOrSearch = "tree";
|
|
|
|
this.hasFocus = false;
|
|
|
|
this.resultsOpen = false;
|
|
|
|
this._popup.active = false;
|
|
|
|
// Should not be needed, but not firing the update
|
|
|
|
this.requestUpdate("resultsOpen");
|
|
|
|
this.requestUpdate("open");
|
|
|
|
this.requestUpdate("hasFocus");
|
|
|
|
this._searchNode?.blur();
|
|
|
|
|
|
|
|
clearTimeout(this._searchTimeout);
|
|
|
|
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event("sl-blur"));
|
|
|
|
})
|
|
|
|
}
|
2024-02-27 00:54:07 +01:00
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
protected handleClick(event)
|
|
|
|
{
|
|
|
|
// Open if clicking somewhere in the widget
|
|
|
|
if(event.target.classList.contains("tree-dropdown__combobox"))
|
|
|
|
{
|
|
|
|
event.stopPropagation();
|
|
|
|
this.show();
|
|
|
|
this.handleFocus();
|
|
|
|
}
|
2024-02-27 00:54:07 +01:00
|
|
|
}
|
|
|
|
|
2024-10-10 18:35:50 +02:00
|
|
|
private handleSearchFocus(event)
|
2024-02-13 17:33:07 +01:00
|
|
|
{
|
|
|
|
this.hasFocus = true;
|
|
|
|
// Should not be needed, but not firing the update
|
|
|
|
this.requestUpdate("hasFocus");
|
|
|
|
|
|
|
|
// Reset tags to not take focus
|
|
|
|
this.setCurrentTag(null);
|
|
|
|
|
2024-10-10 18:35:50 +02:00
|
|
|
// Don't show if only tabbed into
|
|
|
|
if(!event.relatedTarget)
|
|
|
|
{
|
|
|
|
this.show();
|
|
|
|
}
|
2024-09-18 16:11:25 +02:00
|
|
|
}
|
|
|
|
|
2024-09-18 19:32:12 +02:00
|
|
|
private handleInternalBlur(event)
|
2024-09-18 16:11:25 +02:00
|
|
|
{
|
|
|
|
// Focus lost to some other internal component - ignore it
|
2024-09-18 19:32:12 +02:00
|
|
|
let o = event.relatedTarget;
|
|
|
|
while(o)
|
2024-09-18 16:11:25 +02:00
|
|
|
{
|
2024-09-18 19:32:12 +02:00
|
|
|
if(o == this.shadowRoot)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
o = o.parentNode;
|
2024-09-18 16:11:25 +02:00
|
|
|
}
|
|
|
|
this.handleBlur();
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSearchKeyDown(event)
|
|
|
|
{
|
2024-02-22 22:33:22 +01:00
|
|
|
super.handleSearchKeyDown(event);
|
2024-02-13 17:33:07 +01:00
|
|
|
|
2024-09-18 22:05:58 +02:00
|
|
|
// Hide popup if focus is on search
|
|
|
|
if(["Escape"].includes(event.key))
|
|
|
|
{
|
|
|
|
this.hide();
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
2024-10-10 18:35:50 +02:00
|
|
|
// Show options if popup is closed on arrow down or space
|
|
|
|
if((event.key == "ArrowDown" || event.key == " " && this._searchNode.value == "") && !this.open && !this.resultsOpen)
|
2024-09-18 16:11:25 +02:00
|
|
|
{
|
|
|
|
this.show();
|
2024-09-18 19:32:12 +02:00
|
|
|
event.stopPropagation();
|
2024-10-10 18:35:50 +02:00
|
|
|
event.preventDefault();
|
2024-09-18 19:32:12 +02:00
|
|
|
}
|
|
|
|
// Move to tree if popup is open & tree is showing
|
|
|
|
else if(event.key == "ArrowDown" && this.treeOrSearch == "tree")
|
|
|
|
{
|
|
|
|
this._tree.focus();
|
|
|
|
event.stopPropagation();
|
2024-09-18 16:11:25 +02:00
|
|
|
}
|
|
|
|
|
2024-02-13 17:33:07 +01:00
|
|
|
// Left at beginning goes to tags
|
2024-02-22 22:33:22 +01:00
|
|
|
if(this._searchNode.selectionStart == 0 && event.key == "ArrowLeft")
|
2024-02-13 17:33:07 +01:00
|
|
|
{
|
|
|
|
this.hide();
|
|
|
|
this._tags.forEach(t => t.tabIndex = 0);
|
|
|
|
if(this._tags.length > 0)
|
|
|
|
{
|
|
|
|
this.setCurrentTag(this._tags[this._tags.length - 1]);
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected handleLabelClick()
|
|
|
|
{
|
2024-02-22 22:33:22 +01:00
|
|
|
this._searchNode.focus();
|
2024-02-13 17:33:07 +01:00
|
|
|
}
|
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
handleTagRemove(event : SlRemoveEvent, value : string)
|
|
|
|
{
|
|
|
|
// Find the tag value and remove it from current value
|
2024-02-13 17:33:07 +01:00
|
|
|
let valueArray = this.getValueAsArray();
|
2024-02-14 01:15:23 +01:00
|
|
|
const oldValue = valueArray.slice(0);
|
2024-02-13 17:33:07 +01:00
|
|
|
const index = valueArray.indexOf(value);
|
|
|
|
valueArray.splice(index, 1);
|
|
|
|
this.value = valueArray;
|
2024-02-14 01:15:23 +01:00
|
|
|
this.requestUpdate("value", oldValue);
|
|
|
|
// TODO: Clean up this scope violation
|
|
|
|
// sl-tree-item is not getting its selected attribute updated
|
2024-08-22 14:35:36 +02:00
|
|
|
Array.from(this._tree._tree.querySelectorAll('sl-tree-item')).forEach((e : SlTreeItem) =>
|
2024-02-14 01:15:23 +01:00
|
|
|
{
|
|
|
|
if(this.value.includes(e.id))
|
|
|
|
{
|
|
|
|
e.setAttribute("selected", "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e.removeAttribute("selected");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._tree.requestUpdate();
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event("change", {bubbles: true}));
|
|
|
|
});
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTreeChange(event)
|
|
|
|
{
|
2024-02-14 18:42:17 +01:00
|
|
|
const oldValue = this.value.slice(0);
|
|
|
|
|
|
|
|
// For single value, we can just grab selected from the tree. For multiple, we need to manage it.
|
|
|
|
if(!this.multiple)
|
|
|
|
{
|
2024-08-21 20:45:38 +02:00
|
|
|
this.value = event?.detail?.selection?.map(i => i.id || i.value) ?? []
|
2024-02-14 18:42:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-21 20:45:38 +02:00
|
|
|
const id = event?.detail?.selection?.map(i => i.id || i.value).pop();
|
2024-02-14 23:26:39 +01:00
|
|
|
if(id && !this.value.includes(id))
|
2024-02-14 18:42:17 +01:00
|
|
|
{
|
|
|
|
// Copy so LitElement knows it changed
|
|
|
|
this.value = [...this.value, id];
|
|
|
|
}
|
|
|
|
}
|
2024-09-18 16:11:25 +02:00
|
|
|
this.requestUpdate("value", oldValue);
|
2024-02-13 18:40:00 +01:00
|
|
|
|
2024-02-14 01:15:23 +01:00
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event("change", {bubbles: true}));
|
|
|
|
});
|
2024-09-18 16:11:25 +02:00
|
|
|
if(!this.multiple || this.egw().preference("select_multiple_close") == "close")
|
2024-02-13 18:40:00 +01:00
|
|
|
{
|
2024-09-18 16:11:25 +02:00
|
|
|
this.blur();
|
2024-02-13 18:40:00 +01:00
|
|
|
}
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
handleTriggerClick(event)
|
2024-02-13 01:19:24 +01:00
|
|
|
{
|
2024-10-30 18:31:58 +01:00
|
|
|
if(this.disabled || this.readonly)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
event.stopPropagation();
|
|
|
|
|
2024-02-13 17:33:07 +01:00
|
|
|
this.hasFocus = true;
|
2024-02-13 01:19:24 +01:00
|
|
|
if(this.open)
|
|
|
|
{
|
|
|
|
this._popup.active = false;
|
2024-02-22 22:33:22 +01:00
|
|
|
this._searchNode.value = "";
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._popup.active = true;
|
|
|
|
}
|
|
|
|
this.open = this._popup.active;
|
2024-02-22 22:33:22 +01:00
|
|
|
this.treeOrSearch = "tree";
|
2024-02-13 18:40:00 +01:00
|
|
|
this.requestUpdate("open");
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
2024-09-05 22:53:34 +02:00
|
|
|
this._tree.style.minWidth = getComputedStyle(this).width;
|
2024-09-18 16:11:25 +02:00
|
|
|
this.focus();
|
2024-02-13 18:40:00 +01:00
|
|
|
})
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the icon for the select option
|
|
|
|
*
|
|
|
|
* @param option
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected iconTemplate(option)
|
|
|
|
{
|
2024-02-15 18:41:40 +01:00
|
|
|
if(!option.icon && !option.im0)
|
2024-02-13 01:19:24 +01:00
|
|
|
{
|
|
|
|
return html``;
|
|
|
|
}
|
|
|
|
|
|
|
|
return html`
|
2024-02-22 22:33:22 +01:00
|
|
|
<et2-image slot="prefix" part="icon" src="${option.icon ?? option.im0}"></et2-image>`
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inputTemplate()
|
|
|
|
{
|
2024-09-20 00:07:12 +02:00
|
|
|
let placeholder = "";
|
2024-09-18 18:08:36 +02:00
|
|
|
let image : symbol | TemplateResult = nothing;
|
2024-09-20 00:07:12 +02:00
|
|
|
if(this.disabled || this.readonly || (!this.open && this.multiple && this.value.length > 0))
|
2024-09-18 16:11:25 +02:00
|
|
|
{
|
|
|
|
placeholder = "";
|
|
|
|
}
|
2024-10-10 18:35:50 +02:00
|
|
|
else if(this.hasFocus)
|
2024-09-20 00:07:12 +02:00
|
|
|
{
|
|
|
|
placeholder = this.egw().lang("Search");
|
|
|
|
}
|
2024-09-18 16:11:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
placeholder = this.emptyLabel || this.placeholder;
|
|
|
|
}
|
2024-09-18 18:08:36 +02:00
|
|
|
if(!this.multiple && this.value && !this.open)
|
|
|
|
{
|
|
|
|
const option = this.optionSearch(this.value, this.select_options, 'value', 'children');
|
|
|
|
image = option ? this.iconTemplate(option?.option ?? option) : null;
|
|
|
|
}
|
2024-10-30 18:31:58 +01:00
|
|
|
if(this.disabled || this.readonly)
|
|
|
|
{
|
|
|
|
return html`${image}${this.displayLabel || this.emptyLabel || placeholder}`;
|
|
|
|
}
|
2024-02-13 01:19:24 +01:00
|
|
|
return html`
|
2024-09-18 18:08:36 +02:00
|
|
|
${image}
|
2024-02-13 01:19:24 +01:00
|
|
|
<input id="search" type="text" part="input"
|
2024-02-22 22:33:22 +01:00
|
|
|
class="tree-dropdown__search search__input"
|
2024-02-13 01:19:24 +01:00
|
|
|
autocomplete="off"
|
2024-09-18 16:11:25 +02:00
|
|
|
spellcheck="false"
|
|
|
|
autocapitalize="off"
|
|
|
|
aria-controls="listbox"
|
|
|
|
aria-expanded=${this.open ? 'true' : 'false'}
|
|
|
|
aria-haspopup="listbox"
|
|
|
|
aria-labelledby="label"
|
|
|
|
aria-disabled=${this.disabled ? 'true' : 'false'}
|
|
|
|
aria-describedby="help-text"
|
|
|
|
role="combobox"
|
|
|
|
|
2024-02-13 01:19:24 +01:00
|
|
|
?disabled=${this.disabled}
|
|
|
|
?readonly=${this.readonly}
|
2024-09-18 16:11:25 +02:00
|
|
|
placeholder="${placeholder}"
|
2024-02-13 01:19:24 +01:00
|
|
|
tabindex="0"
|
2024-09-18 16:11:25 +02:00
|
|
|
.value=${this.hasFocus ? "" : this.displayLabel}
|
2024-02-13 01:19:24 +01:00
|
|
|
@keydown=${this.handleSearchKeyDown}
|
2024-09-18 19:32:12 +02:00
|
|
|
@blur=${this.handleInternalBlur}
|
2024-02-13 01:19:24 +01:00
|
|
|
@focus=${this.handleSearchFocus}
|
|
|
|
@paste=${this.handlePaste}
|
2024-09-18 16:11:25 +02:00
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="tree-dropdown__value-input"
|
|
|
|
type="text"
|
|
|
|
?disabled=${this.disabled}
|
|
|
|
?required=${this.required}
|
|
|
|
.value=${Array.isArray(this.value) ? this.value.join(', ') : this.value}
|
|
|
|
tabindex="-1"
|
|
|
|
aria-hidden="true"
|
|
|
|
@focus=${this.handleFocus}
|
|
|
|
@blur=${this.handleBlur}
|
2024-02-13 01:19:24 +01:00
|
|
|
/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2024-02-28 22:59:39 +01:00
|
|
|
styleTemplate() : TemplateResult
|
|
|
|
{
|
|
|
|
return html``;
|
|
|
|
}
|
|
|
|
|
2024-02-15 18:13:01 +01:00
|
|
|
/**
|
|
|
|
* Tag used for rendering tags when multiple=true
|
|
|
|
* Used for creating, finding & filtering options.
|
|
|
|
* @see createTagNode()
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
public get tagTag() : StaticValue
|
|
|
|
{
|
|
|
|
return literal`et2-tag`;
|
|
|
|
}
|
|
|
|
|
2024-09-18 16:11:25 +02:00
|
|
|
/**
|
|
|
|
* Shows the currently selected values as tags when multiple=true
|
|
|
|
*
|
|
|
|
* @returns {TemplateResult}
|
|
|
|
*/
|
2024-02-13 01:19:24 +01:00
|
|
|
tagsTemplate()
|
|
|
|
{
|
|
|
|
const value = this.getValueAsArray();
|
2024-09-18 16:11:25 +02:00
|
|
|
return html`
|
|
|
|
<div part="tags" class="tree-dropdown__tags">
|
|
|
|
${map(value, (value, index) =>
|
|
|
|
{
|
|
|
|
// Deal with value that is not in options
|
|
|
|
const option = this.optionSearch(value, this.select_options, 'value', 'children');
|
|
|
|
return option ? this.tagTemplate(option) : nothing;
|
|
|
|
})}
|
|
|
|
</div>`;
|
2024-02-13 01:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tagTemplate(option : TreeItemData)
|
|
|
|
{
|
|
|
|
const readonly = (this.readonly || option && typeof (option.disabled) != "undefined" && option.disabled);
|
|
|
|
const isEditable = false && !readonly;
|
2024-02-14 01:15:23 +01:00
|
|
|
const image = option ? this.iconTemplate(option?.option ?? option) : null;
|
|
|
|
const isValid = true;
|
2024-02-15 18:13:01 +01:00
|
|
|
const tagName = this.tagTag;
|
2024-02-13 01:19:24 +01:00
|
|
|
return html`
|
2024-02-15 18:13:01 +01:00
|
|
|
<${tagName}
|
2024-02-13 01:19:24 +01:00
|
|
|
part="tag"
|
|
|
|
exportparts="
|
|
|
|
base:tag__base,
|
|
|
|
content:tag__content,
|
|
|
|
remove-button:tag__remove-button,
|
|
|
|
remove-button__base:tag__remove-button__base,
|
|
|
|
icon:icon
|
|
|
|
"
|
|
|
|
class=${"tree_tag " + option.class ?? ""}
|
|
|
|
tabindex="-1"
|
2024-02-14 01:15:23 +01:00
|
|
|
variant=${isValid ? nothing : "danger"}
|
2024-02-13 01:19:24 +01:00
|
|
|
size=${this.size || "medium"}
|
2024-02-22 22:33:22 +01:00
|
|
|
title=${option.title}
|
2024-02-13 01:19:24 +01:00
|
|
|
?removable=${!readonly}
|
|
|
|
?readonly=${readonly}
|
|
|
|
?editable=${isEditable}
|
2024-08-22 14:35:36 +02:00
|
|
|
.value=${option.value || option.id}
|
|
|
|
@sl-remove=${(e : SlRemoveEvent) => this.handleTagRemove(e, option.value || option.id)}
|
2024-02-13 01:19:24 +01:00
|
|
|
@change=${this.handleTagEdit}
|
|
|
|
@dblclick=${this._handleDoubleClick}
|
|
|
|
@click=${typeof this.onTagClick == "function" ? (e) => this.onTagClick(e, e.target) : nothing}
|
|
|
|
>
|
|
|
|
${image ?? nothing}
|
2024-02-14 23:26:39 +01:00
|
|
|
${(option.label ?? option.text).trim()}
|
2024-02-15 18:13:01 +01:00
|
|
|
</${tagName}>
|
2024-02-13 01:19:24 +01:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
public render()
|
|
|
|
{
|
|
|
|
const hasLabelSlot = this.hasSlotController.test('label');
|
|
|
|
const hasHelpTextSlot = this.hasSlotController.test('help-text');
|
|
|
|
const hasLabel = this.label ? true : !!hasLabelSlot;
|
2024-02-27 00:54:07 +01:00
|
|
|
const hasValue = this.value && this.value.length > 0;
|
2024-02-13 01:19:24 +01:00
|
|
|
const hasHelpText = this.helpText ? true : !!hasHelpTextSlot;
|
2024-09-18 16:11:25 +02:00
|
|
|
const hasClearIcon = this.clearable && !this.disabled && this.value.length > 0;
|
2024-08-25 11:02:12 +02:00
|
|
|
const isPlaceholderVisible = (this.placeholder || this.emptyLabel) && this.value.length === 0 && !this.disabled && !this.readonly;
|
2024-09-18 16:11:25 +02:00
|
|
|
let options = this.multiple || !this.emptyLabel ? this.select_options : [{
|
|
|
|
value: "",
|
|
|
|
label: this.emptyLabel
|
|
|
|
}, ...this.select_options];
|
2024-02-13 01:19:24 +01:00
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
part="form-control"
|
|
|
|
class=${classMap({
|
|
|
|
'form-control': true,
|
|
|
|
'form-control--medium': true,
|
|
|
|
'form-control--has-label': hasLabel,
|
|
|
|
'form-control--has-help-text': hasHelpText
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<label
|
|
|
|
id="label"
|
|
|
|
part="form-control-label"
|
|
|
|
class="form-control__label"
|
|
|
|
aria-hidden=${hasLabel ? 'false' : 'true'}
|
|
|
|
>
|
|
|
|
<slot name="label">${this.label}</slot>
|
|
|
|
</label>
|
|
|
|
<div part="form-control-input" class="form-control-input">
|
|
|
|
<sl-popup
|
|
|
|
class=${classMap({
|
|
|
|
"tree-dropdown": true,
|
|
|
|
input: true,
|
|
|
|
'tree-dropdown--open': this.open,
|
|
|
|
'tree-dropdown--disabled': this.disabled,
|
|
|
|
'tree-dropdown--readonly': this.readonly,
|
|
|
|
'tree-dropdown--focused': this.hasFocus,
|
2024-09-18 16:11:25 +02:00
|
|
|
'tree-dropdown--multiple': this.multiple,
|
2024-02-13 01:19:24 +01:00
|
|
|
'tree-dropdown--placeholder-visible': isPlaceholderVisible,
|
2024-02-27 00:54:07 +01:00
|
|
|
'tree-dropdown--searching': this.treeOrSearch == "search",
|
|
|
|
'tree-dropdown--has-value': hasValue
|
2024-02-13 01:19:24 +01:00
|
|
|
})}
|
|
|
|
flip
|
|
|
|
shift
|
2024-09-05 22:53:34 +02:00
|
|
|
auto-size="both"
|
2024-02-13 01:19:24 +01:00
|
|
|
auto-size-padding="10"
|
|
|
|
?active=${this.open}
|
|
|
|
placement=${this.placement || "bottom"}
|
2024-08-22 16:48:18 +02:00
|
|
|
strategy="fixed"
|
2024-02-13 01:19:24 +01:00
|
|
|
?disabled=${this.disabled}
|
2024-10-30 18:31:58 +01:00
|
|
|
?readonly=${this.readonly}
|
2024-10-10 18:35:50 +02:00
|
|
|
@sl-after-hide=${() => {this.resultsOpen = false;}}
|
2024-02-13 01:19:24 +01:00
|
|
|
>
|
|
|
|
<div
|
2024-07-26 18:16:49 +02:00
|
|
|
part="combobox control"
|
2024-02-13 01:19:24 +01:00
|
|
|
class="tree-dropdown__combobox"
|
|
|
|
slot="anchor"
|
|
|
|
@keydown=${this.handleComboboxKeyDown}
|
2024-09-18 16:11:25 +02:00
|
|
|
@click=${this.handleClick}
|
2024-02-13 01:19:24 +01:00
|
|
|
>
|
|
|
|
<slot part="prefix" name="prefix" class="tree-dropdown__prefix"></slot>
|
2024-09-18 16:11:25 +02:00
|
|
|
${this.multiple ? this.tagsTemplate() : nothing}
|
|
|
|
${this.inputTemplate()}
|
|
|
|
${hasClearIcon
|
|
|
|
? html`
|
|
|
|
<button
|
|
|
|
part="clear-button"
|
|
|
|
class="select__clear"
|
|
|
|
type="button"
|
|
|
|
aria-label=${this.localize.term('clearEntry')}
|
|
|
|
@mousedown=${this.handleClearMouseDown}
|
|
|
|
@click=${this.handleClearClick}
|
|
|
|
tabindex="-1"
|
|
|
|
>
|
|
|
|
<slot name="clear-icon">
|
|
|
|
<sl-icon name="x-circle-fill" library="system"></sl-icon>
|
|
|
|
</slot>
|
|
|
|
</button>
|
|
|
|
`
|
|
|
|
: ''}
|
2024-02-13 01:19:24 +01:00
|
|
|
<slot part="suffix" name="suffix" class="tree-dropdown__suffix"></slot>
|
2024-02-13 18:40:00 +01:00
|
|
|
<slot name="expand-icon" part="expand-icon" class="tree-dropdown__expand-icon"
|
|
|
|
@click=${this.handleTriggerClick}>
|
|
|
|
<sl-icon library="system" name="chevron-down" aria-hidden="true"></sl-icon>
|
|
|
|
</slot>
|
2024-02-13 01:19:24 +01:00
|
|
|
</div>
|
2024-02-22 22:33:22 +01:00
|
|
|
${this.searchResultsTemplate()}
|
2024-02-13 01:19:24 +01:00
|
|
|
<et2-tree
|
2024-02-27 19:22:55 +01:00
|
|
|
.id=${this.id + "_tree"}
|
|
|
|
._parent=${this}
|
2024-02-13 01:19:24 +01:00
|
|
|
class="tree-dropdown__tree"
|
2024-09-05 22:53:34 +02:00
|
|
|
exportparts="label"
|
2024-02-13 01:19:24 +01:00
|
|
|
?readonly=${this.readonly}
|
|
|
|
?disabled=${this.disabled}
|
2024-02-14 18:42:17 +01:00
|
|
|
value=${this.multiple ? nothing : this.value}
|
2024-09-18 16:11:25 +02:00
|
|
|
._selectOptions=${options}
|
2024-02-27 01:03:57 +01:00
|
|
|
.actions=${this.actions}
|
2024-02-28 22:59:39 +01:00
|
|
|
.styleTemplate=${() => this.styleTemplate()}
|
2024-04-22 16:52:47 +02:00
|
|
|
.autoloading="${this.autoloading}"
|
2024-08-22 10:52:24 +02:00
|
|
|
?leafOnly = ${this.leafOnly}
|
2024-02-13 01:19:24 +01:00
|
|
|
|
2024-09-18 19:32:12 +02:00
|
|
|
@blur=${this.handleInternalBlur}
|
2024-09-20 17:19:34 +02:00
|
|
|
@et2-click=${(e) =>
|
|
|
|
{
|
|
|
|
// Always hide the popup when a tree item is clicked
|
2024-10-08 23:13:23 +02:00
|
|
|
// this.hide();
|
2024-09-20 17:19:34 +02:00
|
|
|
}}
|
2024-09-18 22:05:58 +02:00
|
|
|
@keydown=${this.handleComboboxKeyDown}
|
2024-02-13 18:40:00 +01:00
|
|
|
@sl-selection-change=${this.handleTreeChange}
|
2024-02-13 01:19:24 +01:00
|
|
|
>
|
|
|
|
</et2-tree>
|
|
|
|
</sl-popup>
|
|
|
|
</div>
|
2024-02-27 19:22:55 +01:00
|
|
|
<div
|
|
|
|
part="form-control-help-text"
|
|
|
|
id="help-text"
|
|
|
|
class="form-control__help-text"
|
|
|
|
aria-hidden=${hasHelpText ? 'false' : 'true'}
|
|
|
|
>
|
|
|
|
<slot name="help-text">${this.helpText}</slot>
|
|
|
|
</div>
|
2024-02-13 01:19:24 +01:00
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 22:33:22 +01:00
|
|
|
// @ts-ignore Type problems because of Et2WidgetWithSelectMixin
|
2024-02-15 18:13:01 +01:00
|
|
|
customElements.define("et2-tree-dropdown", Et2TreeDropdown);
|