Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear filter when clicking matching value #3688

Merged
merged 2 commits into from
Apr 18, 2022

Conversation

web-padawan
Copy link
Member

Description

The issue with not clearing the input was coming from the fact that by default, clear() method only sets 'value' to empty string. However, it was already empty for an internal combo-box, so the observer to reset input value wasn't triggered.

Updated to manually set inputElement.value to empty string. Also, added logic to reset filter property, so that the component shows all the items after clicking / pressing Enter on the matching item in the dropdown.

Fixes #3644

Type of change

  • Bugfix

Copy link
Contributor

@vursen vursen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified by manual testing that the PR solves the issue.

The only thing I'm not sure that I totally understand: what is the difference between the clear and _clear methods? They are both in the same scope.

/**
* @param {!Event} event
* @protected
*/
_onChange(event) {
super._onChange(event);
if (this._isClearButton(event)) {
this._clear();
}
}

/**
* @protected
* @override
*/
clear() {
super.clear();
if (this.inputElement) {
this.inputElement.value = '';
}
}

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan
Copy link
Member Author

web-padawan commented Apr 18, 2022

what is the difference between the clear and _clear methods?

Good point. It looks like clear() method coming from InputMixin does not detect and dispatch change event, which makes sense because programmatic value updates should not do that. And _clear method does dispatch change.

BTW, there is a similar __clear()method in InputControlMixin. Because of the way how combo-box should behave, it does not use that method but instead overrides event listeners for Esc and clear button click 🙈

@web-padawan web-padawan merged commit df76091 into master Apr 18, 2022
@web-padawan web-padawan deleted the fix/mcb-clear-filter branch April 18, 2022 13:02
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 23.1.0.alpha3 and is also targeting the upcoming stable 23.1.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[multi-select-combo-box] Selecting a value does not clear the input
3 participants