Skip to content

Commit

Permalink
fix: prevent opening select on click or keydown when disabled (#7874) (
Browse files Browse the repository at this point in the history
…#7876)

Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan authored Sep 26, 2024
1 parent ec239ae commit 0317773
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ export const SelectBaseMixin = (superClass) =>
* @private
*/
_onClick(event) {
if (this.disabled) {
return;
}

// Prevent parent components such as `vaadin-grid`
// from handling the click event after it bubbles.
event.preventDefault();
Expand All @@ -324,7 +328,7 @@ export const SelectBaseMixin = (superClass) =>
* @override
*/
_onKeyDown(e) {
if (e.target === this.focusElement && !this.readonly && !this.opened) {
if (e.target === this.focusElement && !this.readonly && !this.disabled && !this.opened) {
if (/^(Enter|SpaceBar|\s|ArrowDown|Down|ArrowUp|Up)$/u.test(e.key)) {
e.preventDefault();
this.opened = true;
Expand Down
11 changes: 10 additions & 1 deletion packages/select/test/select.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,24 @@ describe('vaadin-select', () => {
});

describe('disabled', () => {
it('should disable the button and disable opening if select is disabled', async () => {
beforeEach(async () => {
select.disabled = true;
await nextUpdate(select);
});

it('should disable the value button element when disabled', () => {
expect(valueButton.disabled).to.be.true;
});

it('should not open on value button Enter when disabled', () => {
enterKeyDown(valueButton);
expect(select.opened).to.be.false;
expect(select._overlayElement.opened).to.be.false;
});

it('should not open on value button click when disabled', () => {
click(valueButton);
expect(select.opened).to.be.false;
expect(select._overlayElement.opened).to.be.false;
});
});
Expand Down

0 comments on commit 0317773

Please sign in to comment.