Get taglist selected options showing up

Note the [internal] event listener bound in Et2Taglist.connectedCallback() that re-renders the TaglistSelection every time the taglist's [internal] value changes
This commit is contained in:
nathan 2022-03-04 13:41:37 -07:00
parent 2d3e3f86e1
commit 4bd4402e28
3 changed files with 52 additions and 46 deletions

View File

@ -11,22 +11,27 @@
import {LionOption} from '@lion/listbox';
import {css, html} from "@lion/core";
export class EgwOption extends LionOption {
export class EgwOption extends LionOption
{
static get properties() {
static get properties()
{
return {
...super.properties,
title: {type: String},
icon: {type: String}
};
}
constructor() {
constructor()
{
super();
this.title = '';
this.icon = '';
}
static get styles() {
static get styles()
{
return [
...super.styles,
css`

View File

@ -14,9 +14,11 @@ import {Et2widgetWithSelectMixin} from "../Et2Select/Et2WidgetWithSelectMixin";
import {LionCombobox} from "@lion/combobox";
import {SelectOption} from "../Et2Select/FindSelectOptions";
import {EgwOption} from "./EgwOption";
import {TaglistSelection} from "./TaglistSelection";
// Force the include, we really need this and without it the file will be skipped
const really_import_me = EgwOption;
const really_import_me2 = TaglistSelection;
/**
* Taglist base class implementation
@ -48,10 +50,11 @@ export class Et2Taglist extends Et2widgetWithSelectMixin(LionCombobox)
get slots() {
return {
...super.slots,
"selection-display": () => {
return html `<taglist-selection
slot="selection-display"
style="display: contents;"></taglist-selection>`;
"selection-display": () =>
{
let display = document.createElement("taglist-selection");
display.setAttribute("slot", "selection-display");
return display;
}
}
}
@ -62,6 +65,13 @@ export class Et2Taglist extends Et2widgetWithSelectMixin(LionCombobox)
}
connectedCallback()
{
super.connectedCallback();
this.addEventListener('model-value-changed', () => {this._selectionDisplayNode.requestUpdate();});
}
/**
* Get the node where we're putting the options
*

View File

@ -11,7 +11,6 @@
import {css, html, LitElement} from "@lion/core";
import {TaglistComboBox} from "./TaglistComboBox";
import {taglistStyles} from "./TaglistStyles";
@ -21,10 +20,9 @@ import {taglistStyles} from "./TaglistStyles";
export class TaglistSelection extends LitElement {
static get properties() {
return {
selectedTags: Array,
comboxElement: TaglistComboBox,
canBeClosed: Boolean,
canBeEdited: Boolean
comboxElement: {type: Object},
canBeClosed: {type: Boolean},
canBeEdited: {type: Boolean}
}
};
@ -79,7 +77,8 @@ export class TaglistSelection extends LitElement {
/**
*
*/
get _inputNode() {
get _inputNode()
{
return this._getComboBoxElement()._inputNode;
}
@ -90,7 +89,7 @@ export class TaglistSelection extends LitElement {
_getComboBoxElement()
{
// @ts-ignore
return this.comboboxElement;
return this.parentElement;
}
/**
@ -112,7 +111,6 @@ export class TaglistSelection extends LitElement {
constructor() {
super();
this.selectedTags = [];
this.__handleCloseBtn = this.__handleCloseBtn.bind(this);
this.__handleEditBtn = this.__handleEditBtn.bind(this);
this.__inputOnKeyup = this.__inputOnKeyup.bind(this);
@ -131,15 +129,6 @@ export class TaglistSelection extends LitElement {
}
}
/**
*
* @param changedProperties
*/
onComboboxElementUpdated(changedProperties) {
if (changedProperties.has('modelValue')) {
this.selectedTags = this.__getSelectedTags();
}
}
__handleEditBtn()
{
@ -155,12 +144,13 @@ export class TaglistSelection extends LitElement {
*
* @param option
*/
_selectedTagTemplate(option) {
_selectedTagTemplate(option)
{
return html`
<div class="taglist-selection__tag">
${this._canBeEdited? html`<span class="tag-editBtn" @click="${this.__handleEditBtn}"></span>`:''}
${this.canBeEdited ? html`<span class="tag-editBtn" @click="${this.__handleEditBtn}"></span>` : ''}
<span class="tag-label">${option.value}</span>
${this._canBeClosed? html`<span class="tag-closeBtn" @click="${this.__handleCloseBtn}"></span>`:''}
${this.canBeClosed ? html`<span class="tag-closeBtn" @click="${this.__handleCloseBtn}"></span>` : ''}
</div>
`;
}
@ -171,7 +161,8 @@ export class TaglistSelection extends LitElement {
_selectedTagsTemplate() {
return html`
<div class="taglist-selection__tags">
${this.selectedTags.map((option) => {
${this.__getSelectedTags().map((option) =>
{
return this._selectedTagTemplate(option);
})}
</div>