Skip to content

Commit 50354c7

Browse files
committed
fix: updated this.value state management
1 parent 175f56b commit 50354c7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

elements/pf-search-input/pf-search-input.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller
1313
import { InternalsController } from '@patternfly/pfe-core/controllers/internals-controller.js';
1414
import { FloatingDOMController } from '@patternfly/pfe-core/controllers/floating-dom-controller.js';
1515

16-
import { arraysAreEquivalent } from '@patternfly/pfe-core/functions/arraysAreEquivalent.js';
1716
import { observes } from '@patternfly/pfe-core/decorators/observes.js';
1817
import { PfOption } from '../pf-select/pf-option.js';
19-
import { bound } from '@patternfly/pfe-core/decorators.js';
2018
import styles from './pf-search-input.css';
2119

2220
/** Fired when a `<pf-search-input>` element's value changes */
@@ -248,6 +246,8 @@ export class PfSearchInput extends LitElement {
248246

249247
async #onClickCloseButton() {
250248
this._toggleInput!.value = '';
249+
this.#updateValue(this._toggleInput?.value ?? '');
250+
this.#combobox.selected = [];
251251
this.#clickedCloseButton = true;
252252
this._toggleInput?.focus();
253253
}
@@ -260,12 +260,19 @@ export class PfSearchInput extends LitElement {
260260
}
261261

262262
#onChange() {
263-
this.value = this._toggleInput?.value;
263+
this.#updateValue(this._toggleInput?.value ?? '');
264264
if (this.value !== this.#combobox.selected[0]?.value) {
265265
this.#combobox.selected = [];
266266
}
267-
this.#internals.setFormValue(this.value ?? '');
268-
this.dispatchEvent(new PfSearchChangeEvent());
267+
// Will remove after review
268+
// for (const item of this.#combobox.items){
269+
// if (item.hasAttribute('selected')) {
270+
// if(item.value !== this.value){
271+
// this.#setItemSelected(item, false);
272+
// this.requestUpdate();
273+
// }
274+
// }
275+
// }
269276
}
270277

271278
#onSubmit(event: KeyboardEvent) {
@@ -274,6 +281,10 @@ export class PfSearchInput extends LitElement {
274281
}
275282
}
276283

284+
#updateValue(value: string) {
285+
this.value = value;
286+
}
287+
277288
#onKeyDown(event: KeyboardEvent) {
278289
const target = event.target as HTMLElement;
279290
if (target?.getAttribute('aria-disabled') === 'true') {
@@ -296,8 +307,8 @@ export class PfSearchInput extends LitElement {
296307
#setItemSelected(item: PfOption, selected: boolean) {
297308
item.selected = selected;
298309
if (selected) {
299-
this.value = item.value;
300-
this._toggleInput!.value = this.value;
310+
this._toggleInput!.value = item.value;
311+
this.#updateValue(this._toggleInput?.value ?? '');
301312
}
302313
}
303314

0 commit comments

Comments
 (0)