Skip to content

Commit 2880397

Browse files
authored
refactor: rename internal method used for clearing the value (#5508)
1 parent fa60a53 commit 2880397

4 files changed

Lines changed: 26 additions & 29 deletions

File tree

‎packages/combo-box/src/vaadin-combo-box-light.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ValidateMixi
198198
super._onChange(event);
199199

200200
if (this._isClearButton(event)) {
201-
this._clear();
201+
this._onClearAction();
202202
}
203203
}
204204
}

‎packages/combo-box/src/vaadin-combo-box-mixin.js‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,19 @@ export const ComboBoxMixin = (subclass) =>
599599
return event.composedPath()[0] === this.clearElement;
600600
}
601601

602+
/** @private */
603+
__onClearButtonMouseDown(event) {
604+
event.preventDefault(); // Prevent native focusout event
605+
this.inputElement.focus();
606+
}
607+
602608
/**
603609
* @param {Event} event
604610
* @protected
605611
*/
606-
_handleClearButtonClick(event) {
612+
_onClearButtonClick(event) {
607613
event.preventDefault();
608-
this._clear();
614+
this._onClearAction();
609615

610616
// De-select dropdown item
611617
if (this.opened) {
@@ -641,15 +647,13 @@ export const ComboBoxMixin = (subclass) =>
641647
}
642648

643649
/** @private */
644-
_onClick(e) {
645-
const path = e.composedPath();
646-
647-
if (this._isClearButton(e)) {
648-
this._handleClearButtonClick(e);
649-
} else if (path.indexOf(this._toggleElement) > -1) {
650-
this._onToggleButtonClick(e);
650+
_onClick(event) {
651+
if (this._isClearButton(event)) {
652+
this._onClearButtonClick(event);
653+
} else if (event.composedPath().includes(this._toggleElement)) {
654+
this._onToggleButtonClick(event);
651655
} else {
652-
this._onHostClick(e);
656+
this._onHostClick(event);
653657
}
654658
}
655659

@@ -827,7 +831,7 @@ export const ComboBoxMixin = (subclass) =>
827831
} else if (this.clearButtonVisible && !this.opened && !!this.value) {
828832
e.stopPropagation();
829833
// The clear button is visible and the overlay is closed, so clear the value.
830-
this._clear();
834+
this._onClearAction();
831835
}
832836
} else if (this.opened) {
833837
// Auto-open is enabled
@@ -845,7 +849,7 @@ export const ComboBoxMixin = (subclass) =>
845849
} else if (this.clearButtonVisible && !!this.value) {
846850
e.stopPropagation();
847851
// The clear button is visible and the overlay is closed, so clear the value.
848-
this._clear();
852+
this._onClearAction();
849853
}
850854
}
851855

@@ -867,7 +871,7 @@ export const ComboBoxMixin = (subclass) =>
867871
* Clears the current value.
868872
* @protected
869873
*/
870-
_clear() {
874+
_onClearAction() {
871875
this.selectedItem = null;
872876

873877
if (this.allowCustomValue) {
@@ -1270,12 +1274,6 @@ export const ComboBoxMixin = (subclass) =>
12701274
}
12711275
}
12721276

1273-
/** @private */
1274-
__onClearButtonMouseDown(event) {
1275-
event.preventDefault(); // Prevent native focusout event
1276-
this.inputElement.focus();
1277-
}
1278-
12791277
/** @private */
12801278
_onFocusout(event) {
12811279
// VoiceOver on iOS fires `focusout` event when moving focus to the item in the dropdown.
@@ -1308,7 +1306,7 @@ export const ComboBoxMixin = (subclass) =>
13081306
}
13091307

13101308
event.preventDefault();
1311-
this._clear();
1309+
this._onClearAction();
13121310
}
13131311

13141312
/**

‎packages/combo-box/src/vaadin-combo-box.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,17 @@ class ComboBox extends ComboBoxDataProviderMixin(
287287
}
288288

289289
/**
290-
* Override method inherited from `InputControlMixin` to handle clear
291-
* button click and stop event from propagating to the host element.
290+
* Override the method from `InputControlMixin`
291+
* to stop event propagation to prevent `ComboBoxMixin`
292+
* from handling this click event also on its own.
293+
*
292294
* @param {Event} event
293295
* @protected
294296
* @override
295297
*/
296298
_onClearButtonClick(event) {
297299
event.stopPropagation();
298-
299-
this._handleClearButtonClick(event);
300+
super._onClearButtonClick(event);
300301
}
301302

302303
/**

‎packages/combo-box/test/basic.test.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,14 @@ describe('Properties', () => {
327327

328328
it('should be null after clearing the value', () => {
329329
comboBox.value = 'foo';
330-
331-
comboBox._clear();
330+
comboBox.$.clearButton.click();
332331

333332
expect(comboBox.selectedItem).to.be.null;
334333
});
335334

336335
it('should not open the overlay after clearing the value', () => {
337336
comboBox.value = 'foo';
338-
339-
comboBox._clear();
337+
comboBox.$.clearButton.click();
340338

341339
expect(overlay.opened).not.to.be.true;
342340
});

0 commit comments

Comments
 (0)