Et2TreeDropdown: Single value tag takes full width

This commit is contained in:
nathan 2024-02-26 16:54:07 -07:00
parent abc25683af
commit 0f139fb257
2 changed files with 49 additions and 2 deletions

View File

@ -105,6 +105,7 @@ export default css`
display: flex; display: flex;
flex: 2 1 auto; flex: 2 1 auto;
flex-wrap: wrap; flex-wrap: wrap;
align-content: center;
gap: 0.1rem 0.5rem; gap: 0.1rem 0.5rem;
min-height: var(--sl-input-height-medium); min-height: var(--sl-input-height-medium);
max-height: calc(var(--height, 5) * var(--sl-input-height-medium)); max-height: calc(var(--height, 5) * var(--sl-input-height-medium));
@ -143,6 +144,18 @@ export default css`
cursor: default; cursor: default;
} }
/* tag takes full width when widget is not multiple and has value and does not have focus */
:host(:not([multiple])) .tree-dropdown--has-value .tree-dropdown__search {
display: none;
}
:host(:not([multiple])) .tree-dropdown--focused .tree-dropdown__search,
:host(:not([multiple])) .tree-dropdown--open .tree-dropdown__search {
display: initial;
flex-grow: 0;
}
.tree-dropdown__suffix { .tree-dropdown__suffix {
order: 20; order: 20;
} }

View File

@ -85,8 +85,22 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
constructor() constructor()
{ {
super(); super();
this.multiple = false;
this.__value = []; this.__value = [];
this.handleDocumentClick = this.handleDocumentClick.bind(this);
}
connectedCallback()
{
super.connectedCallback();
document.addEventListener("click", this.handleDocumentClick);
}
disconnectedCallback()
{
super.disconnectedCallback();
document.removeEventListener("click", this.handleDocumentClick);
} }
updated() updated()
@ -304,6 +318,24 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
} }
} }
protected handleDocumentClick(event)
{
if(event.target == this || event.composedPath().includes(this))
{
return
}
if(this.open)
{
event.preventDefault();
this.hide()
}
else
{
this.blur();
}
}
private handleSearchFocus() private handleSearchFocus()
{ {
this.hasFocus = true; this.hasFocus = true;
@ -519,6 +551,7 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
const hasLabelSlot = this.hasSlotController.test('label'); const hasLabelSlot = this.hasSlotController.test('label');
const hasHelpTextSlot = this.hasSlotController.test('help-text'); const hasHelpTextSlot = this.hasSlotController.test('help-text');
const hasLabel = this.label ? true : !!hasLabelSlot; const hasLabel = this.label ? true : !!hasLabelSlot;
const hasValue = this.value && this.value.length > 0;
const hasHelpText = this.helpText ? true : !!hasHelpTextSlot; const hasHelpText = this.helpText ? true : !!hasHelpTextSlot;
const isPlaceholderVisible = this.placeholder && this.value.length === 0 && !this.disabled && !this.readonly; const isPlaceholderVisible = this.placeholder && this.value.length === 0 && !this.disabled && !this.readonly;
@ -550,7 +583,8 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
'tree-dropdown--readonly': this.readonly, 'tree-dropdown--readonly': this.readonly,
'tree-dropdown--focused': this.hasFocus, 'tree-dropdown--focused': this.hasFocus,
'tree-dropdown--placeholder-visible': isPlaceholderVisible, 'tree-dropdown--placeholder-visible': isPlaceholderVisible,
'tree-dropdown--searching': this.treeOrSearch == "search" 'tree-dropdown--searching': this.treeOrSearch == "search",
'tree-dropdown--has-value': hasValue
})} })}
flip flip
shift shift