Skip to content

Commit

Permalink
[BUGFIX] Le PixSearchInput est sujet à des suppressions de caractèr…
Browse files Browse the repository at this point in the history
…es (PIX-11403)

 #550
  • Loading branch information
pix-service-auto-merge authored Mar 8, 2024
2 parents 41c34d3 + ea11586 commit cf9bc3a
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 92 deletions.
4 changes: 2 additions & 2 deletions addon/components/pix-search-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class="pix-search-input__input"
name={{@inputName}}
placeholder={{@placeholder}}
value={{@value}}
oninput={{this.onSearch}}
value={{this.initialValue}}
{{on "input" this.onSearch}}
...attributes
/>
</div>
Expand Down
23 changes: 15 additions & 8 deletions addon/components/pix-search-input.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import debounce from 'lodash.debounce';
import { debounceTask } from 'ember-lifeline';

export default class PixSearchInput extends Component {
initialValue = this.args.value;

constructor() {
super(...arguments);

this.debounceTimeBeforeSearch = parseInt(this.args.debounceTimeInMs);
if (isNaN(this.debounceTimeBeforeSearch)) {
if (Number.isNaN(this.debounceTimeBeforeSearch)) {
throw new Error('ERROR in PixSearchInput component, @debounceTimeInMs param is not provided');
}
if (!this.args.triggerFiltering) {
Expand All @@ -21,10 +23,6 @@ export default class PixSearchInput extends Component {
}

this.searchInputId = this.args.id || guidFor(this);
this.debouncedTriggerFiltering = debounce(
this.args.triggerFiltering,
this.debounceTimeBeforeSearch,
);
}

get label() {
Expand All @@ -35,8 +33,17 @@ export default class PixSearchInput extends Component {
return this.args.label ? null : this.args.ariaLabel;
}

debouncedTriggerFiltering(value) {
this.args.triggerFiltering(this.searchInputId, value);
}

@action
async onSearch(event) {
await this.debouncedTriggerFiltering(this.searchInputId, event.target.value);
onSearch(event) {
debounceTask(
this,
'debouncedTriggerFiltering',
event.target.value,
this.debounceTimeBeforeSearch,
);
}
}
Loading

0 comments on commit cf9bc3a

Please sign in to comment.