Et2TreeDropdown

- Better handling of horizontal space
- Single select closes dropdown immediately
- Selecting tree item actually changes value
This commit is contained in:
nathan 2024-02-13 10:40:00 -07:00
parent c53e122564
commit 51f23a0dcf
2 changed files with 42 additions and 21 deletions

View File

@ -41,8 +41,9 @@ export default css`
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: nowrap;
align-items: center; align-items: flex-start;
justify-content: space-between;
gap: 0.1rem 0.5rem; gap: 0.1rem 0.5rem;
background-color: var(--sl-input-background-color); background-color: var(--sl-input-background-color);
@ -53,6 +54,7 @@ export default css`
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));
overflow-y: auto; overflow-y: auto;
overflow-x: hidden;
padding-block: 0; padding-block: 0;
padding-inline: var(--sl-input-spacing-medium); padding-inline: var(--sl-input-spacing-medium);
padding-top: 0.1rem; padding-top: 0.1rem;
@ -80,18 +82,18 @@ export default css`
/* Trigger */ /* Trigger */
.tree-dropdown__trigger { .tree-dropdown__expand-icon {
max-width: initial; height: var(--sl-input-height-medium);
min-width: initial; flex: 0 0 auto;
flex: 0 0 1em;
order: 21;
margin-left: auto;
}
.tree-dropdown__trigger::part(base) {
border: none;
display: flex; display: flex;
align-items: center; align-items: center;
transition: var(--sl-transition-medium) rotate ease;
rotate: 0;
margin-inline-start: var(--sl-spacing-small);
}
.tree-dropdown--open .tree-dropdown__expand-icon {
rotate: -180deg;
} }
/* End trigger */ /* End trigger */
@ -100,6 +102,15 @@ export default css`
order: 1; order: 1;
} }
/* Tags */
.tree-dropdown__tags {
display: flex;
flex-wrap: wrap;
}
/* End tags */
/* Search box */ /* Search box */
:host([readonly]) .tree-dropdown__search { :host([readonly]) .tree-dropdown__search {
@ -107,7 +118,7 @@ export default css`
} }
.tree-dropdown__search { .tree-dropdown__search {
flex: 1 1 auto; flex: 1 1 7em;
order: 10; order: 10;
min-width: 7em; min-width: 7em;
border: none; border: none;

View File

@ -243,6 +243,7 @@ export class Et2TreeDropdown extends Et2WidgetWithSelectMixin(LitElement)
this.hasFocus = true; this.hasFocus = true;
// Should not be needed, but not firing the update // Should not be needed, but not firing the update
this.requestUpdate("hasFocus"); this.requestUpdate("hasFocus");
this.show();
// Reset tags to not take focus // Reset tags to not take focus
this.setCurrentTag(null); this.setCurrentTag(null);
@ -325,8 +326,13 @@ export class Et2TreeDropdown extends Et2WidgetWithSelectMixin(LitElement)
handleTreeChange(event) handleTreeChange(event)
{ {
const oldValue = this.value; const oldValue = this.value;
this.value = this._tree.value; this.value = this._tree.getValue();
this.requestUpdate("value", oldValue); this.requestUpdate("value", oldValue);
if(!this.multiple)
{
this.hide();
}
} }
handleTriggerClick() handleTriggerClick()
@ -341,6 +347,11 @@ export class Et2TreeDropdown extends Et2WidgetWithSelectMixin(LitElement)
this._popup.active = true; this._popup.active = true;
} }
this.open = this._popup.active; this.open = this._popup.active;
this.requestUpdate("open");
this.updateComplete.then(() =>
{
this._tree.focus();
})
} }
/** /**
@ -477,17 +488,16 @@ export class Et2TreeDropdown extends Et2WidgetWithSelectMixin(LitElement)
<slot part="prefix" name="prefix" class="tree-dropdown__prefix"></slot> <slot part="prefix" name="prefix" class="tree-dropdown__prefix"></slot>
<div part="tags" class="tree-dropdown__tags"> <div part="tags" class="tree-dropdown__tags">
${this.tagsTemplate()} ${this.tagsTemplate()}
</div>
${this.inputTemplate()} ${this.inputTemplate()}
</div>
${this.searching ? html` ${this.searching ? html`
<sl-spinner class="tree-dropdown"></sl-spinner>` : nothing <sl-spinner class="tree-dropdown"></sl-spinner>` : nothing
} }
<slot part="suffix" name="suffix" class="tree-dropdown__suffix"></slot> <slot part="suffix" name="suffix" class="tree-dropdown__suffix"></slot>
<et2-button caret class="tree-dropdown__trigger" <slot name="expand-icon" part="expand-icon" class="tree-dropdown__expand-icon"
@click=${this.handleTriggerClick} @click=${this.handleTriggerClick}>
.noSubmit=${true} <sl-icon library="system" name="chevron-down" aria-hidden="true"></sl-icon>
> </slot>
</et2-button>
</div> </div>
<et2-tree <et2-tree
class="tree-dropdown__tree" class="tree-dropdown__tree"
@ -497,7 +507,7 @@ export class Et2TreeDropdown extends Et2WidgetWithSelectMixin(LitElement)
.value=${this.value} .value=${this.value}
._selectOptions=${this.select_options} ._selectOptions=${this.select_options}
@change=${this.handleTreeChange} @sl-selection-change=${this.handleTreeChange}
> >
</et2-tree> </et2-tree>
</sl-popup> </sl-popup>