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: do not open dropdown on helper click #3402

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/combo-box/src/vaadin-combo-box-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ export const ComboBoxMixin = (subclass) =>
}
}

/**
* @param {Event} event
* @protected
*/
_onHostClick(_event) {
if (!this.autoOpenDisabled) {
this.open();
}
}

/** @private */
_onClick(e) {
this._closeOnBlurIsPrevented = true;
Expand All @@ -437,8 +447,8 @@ export const ComboBoxMixin = (subclass) =>
} else {
this.open();
}
} else if (!this.autoOpenDisabled) {
this.open();
} else {
this._onHostClick(e);
}

this._closeOnBlurIsPrevented = false;
Expand Down
13 changes: 13 additions & 0 deletions packages/combo-box/src/vaadin-combo-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ class ComboBox extends ComboBoxDataProviderMixin(

this._handleClearButtonClick(event);
}

/**
* @param {Event} event
* @protected
*/
_onHostClick(event) {
const path = event.composedPath();

// Open dropdown only when clicking on the label or input field
if (path.includes(this._labelNode) || path.includes(this._positionTarget)) {
super._onHostClick(event);
}
}
}

customElements.define(ComboBox.is, ComboBox);
Expand Down
13 changes: 13 additions & 0 deletions packages/combo-box/test/toggling-dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('toggling dropdown', () => {
expect(comboBox.opened).to.be.true;
});

it('should not open the overlay on helper click', () => {
comboBox.helperText = 'Helper Text';
comboBox.querySelector('[slot=helper]').click();
expect(comboBox.opened).to.be.false;
});

it('should not open the overlay on error message click', () => {
comboBox.invalid = true;
comboBox.errorMessage = 'Error message';
comboBox.querySelector('[slot=error-message]').click();
expect(comboBox.opened).to.be.false;
});

it('should open on function call', () => {
comboBox.open();

Expand Down