Skip to content

Commit

Permalink
✨ (search-bar): Add reset event
Browse files Browse the repository at this point in the history
This event is emitted when the reset btn is clicked
  • Loading branch information
EmilienLeroy committed Sep 8, 2023
1 parent 83ccd05 commit a8a32cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/search-bar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (!customElements.get('kami-transition')) {
* @fires change - Emitted when the search is updated
* @fires sort - Emitted when the sort button is clicked
* @fires clear - Emitted when the search input is clear
* @fires reset - Emitted when the reset button is clicked
*/
@customElement('kami-search-bar')
export default class KamiSearchBar extends LitElement {
Expand Down Expand Up @@ -152,6 +153,10 @@ export default class KamiSearchBar extends LitElement {
}));
}

private emitResetEvent() {
this.dispatchEvent(new CustomEvent('reset'));
}

private emitClearEvent() {
this.dispatchEvent(new CustomEvent('clear'));
}
Expand All @@ -173,9 +178,10 @@ export default class KamiSearchBar extends LitElement {
}
}

private onClear() {
private onReset() {
this.value = '';
this.searchEl.value = '';
this.emitResetEvent();
this.emitClearEvent();
}

Expand Down Expand Up @@ -208,7 +214,7 @@ export default class KamiSearchBar extends LitElement {
<div class="kami-search-bar__action">
<kami-transition transition="slide-x" duration="200" from="10" to="1" show="${this.value !== ''}">
<div @click="${this.onClear}" class="kami-search-bar__close">
<div @click="${this.onReset}" class="kami-search-bar__close">
${this.renderIcon(mdiClose)}
</div>
</kami-transition>
Expand Down

0 comments on commit a8a32cc

Please sign in to comment.