diff --git a/mwui-stencil/src/components.d.ts b/mwui-stencil/src/components.d.ts index a67a59c8..678b2fd3 100644 --- a/mwui-stencil/src/components.d.ts +++ b/mwui-stencil/src/components.d.ts @@ -1491,11 +1491,11 @@ declare namespace LocalJSX { /** * Emits an event when value of input changes */ - onMwChipListInputChange?: (event: MwChipInputCustomEvent) => void; + onInputChange?: (event: MwChipInputCustomEvent) => void; /** * Emits an event when its value changes */ - onMwChipListValueChanged?: (event: MwChipInputCustomEvent) => void; + onValueChanged?: (event: MwChipInputCustomEvent) => void; /** * Amount of currently selected options */ diff --git a/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.stories.tsx b/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.stories.tsx index d77f893d..714963fc 100644 --- a/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.stories.tsx +++ b/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.stories.tsx @@ -58,10 +58,10 @@ const IconTemplate = args => ` >
- - - - + + + +
`; diff --git a/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.tsx b/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.tsx index 73b3ed60..ef5d6327 100644 --- a/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.tsx +++ b/mwui-stencil/src/components/mw-autocomplete/mw-autocomplete.tsx @@ -80,7 +80,7 @@ export class MwAutocomplete { /** * Currently selected options */ - @Prop({ reflect: true, mutable: false }) selected: string[] = []; + @Prop({ reflect: true, mutable: true }) selected: string[] = []; @Watch("selected") onSelectedChange(selected: string[]): void { if (!this.canAddToValues()) { @@ -116,8 +116,8 @@ export class MwAutocomplete { this.hasIconStartSlot = !!this.hostElement.querySelector("[slot='icon-start']"); } - private onInputChange = (event: MwChipInputCustomEvent | MwTextfieldCustomEvent): void => { - this.filterDropdownOptions(event.detail); + private onInputChange = (event: MwChipInputCustomEvent | MwTextfieldCustomEvent | InputEvent): void => { + this.filterDropdownOptions((event.target as HTMLMwChipInputElement).value); this.isDropdownOpen = true; }; @@ -138,22 +138,22 @@ export class MwAutocomplete { this.removeDropdownFilter(); }; - private setItemDisabledState(selected: string[]): void { + private setItemDisabledState = (selected: string[]): void => { this.hostElement.querySelectorAll("mw-menu-item").forEach(item => { const isDisabled = selected.includes(item.getAttribute("value")); item.setAttribute("disabled", `${isDisabled}`); }); - } + }; - private handleChipListValueChange(event: MwChipInputCustomEvent): void { + private handleChipListValueChange = (event: MwChipInputCustomEvent): void => { this.selected = event.detail; - } + }; - private filterDropdownOptions = (value: string): void => { + private filterDropdownOptions = (value: string | number): void => { let hasNoSuggestions = true; this.hostElement.querySelectorAll("mw-menu-item").forEach(item => { - if (item.value.toLowerCase().includes(value.toLowerCase())) { + if (item.value.toLowerCase().includes(value.toString().toLowerCase())) { item.style.display = "unset"; hasNoSuggestions = false; } else { @@ -173,9 +173,9 @@ export class MwAutocomplete { }); }; - private canAddToValues(): boolean { + private canAddToValues = (): boolean => { return !this.maximum || this.selected?.length < this.maximum; - } + }; render() { return ( @@ -201,8 +201,8 @@ export class MwAutocomplete { selectedChips={this.selected} onFocus={this.onFocus} onBlur={this.onBlur} - onMwChipListValueChanged={this.handleChipListValueChange.bind(this)} - onMwChipListInputChange={this.onInputChange.bind(this)} + onValueChanged={this.handleChipListValueChange} + onInput={this.onInputChange} slot="anchor" > {this.hasIconStartSlot && ( diff --git a/mwui-stencil/src/components/mw-chip-input/mw-chip-input.tsx b/mwui-stencil/src/components/mw-chip-input/mw-chip-input.tsx index 838673aa..3dce050b 100644 --- a/mwui-stencil/src/components/mw-chip-input/mw-chip-input.tsx +++ b/mwui-stencil/src/components/mw-chip-input/mw-chip-input.tsx @@ -14,12 +14,12 @@ export class MwChipInput { /** * Emits an event when its value changes */ - @Event({ bubbles: true, composed: false, eventName: "mwChipListValueChanged" }) valueChanged: EventEmitter; + @Event({ bubbles: true, composed: true, eventName: "valueChanged" }) valueChanged: EventEmitter; /** * Emits an event when value of input changes */ - @Event({ bubbles: true, composed: false, eventName: "mwChipListInputChange" }) inputChange: EventEmitter; + @Event({ bubbles: true, composed: true }) inputChange: EventEmitter; /** * input field name */ @@ -143,6 +143,11 @@ export class MwChipInput { this.focused = false; }; + private onRemoveSelection = (value: string): void => { + this._selection.deselect(value); + this.onValueChange(); + }; + private addMultiValue = (value: string): void => { if (value.trim()?.length === 0) { return; @@ -162,18 +167,18 @@ export class MwChipInput { this.onValueChange(); }; - private onValueChange(): void { + private onValueChange = (): void => { this.selected = this._selection.selected; this.valueChanged.emit(this.selected); - } + }; - private handleInputChange(): void { + private handleInputChange = (): void => { this.inputChange.emit(this.inputElement.value); - } + }; - private canAddToValues(): boolean { + private canAddToValues = (): boolean => { return !this.maximum || this.selected?.length < this.maximum; - } + }; render() { const { @@ -187,7 +192,6 @@ export class MwChipInput { name, clearMultiValues, selected, - handleInputChange, required, hasError, inline, @@ -229,7 +233,7 @@ export class MwChipInput {
{selected?.map(v => ( - + this.onRemoveSelection(v)} showClose={true} value={v} selected={true} toggleable={false} disabled={disabled}> {v} ))} @@ -246,7 +250,7 @@ export class MwChipInput { name={name} value={this.value} disabled={disabled} - onInput={handleInputChange.bind(this)} + onInput={this.handleInputChange} /> )}
diff --git a/mwui-stencil/src/index.html b/mwui-stencil/src/index.html index b9619ff1..8141bec1 100644 --- a/mwui-stencil/src/index.html +++ b/mwui-stencil/src/index.html @@ -463,12 +463,12 @@

Dropdown

- - + + - - - + + +
@@ -480,43 +480,43 @@

Autocomplete

- - - - - - - - + + + + + + + +
- - - - - - - - + + + + + + + +
- - - - + + + +
- - - - + + + +