From 8e4d7c6b017121754fb74d29e49c5393cc5bc5f0 Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Thu, 26 Sep 2024 15:03:09 +0200 Subject: [PATCH] fix: prevent opening select on click or keydown when disabled (#7874) (#7877) Co-authored-by: Serhii Kulykov --- packages/select/src/vaadin-select-base-mixin.js | 6 +++++- packages/select/test/select.common.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/select/src/vaadin-select-base-mixin.js b/packages/select/src/vaadin-select-base-mixin.js index e332d4f7bb..7996e3e13a 100644 --- a/packages/select/src/vaadin-select-base-mixin.js +++ b/packages/select/src/vaadin-select-base-mixin.js @@ -293,6 +293,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(); @@ -313,7 +317,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; diff --git a/packages/select/test/select.common.js b/packages/select/test/select.common.js index 65a4ee1aad..5bc41ffb13 100644 --- a/packages/select/test/select.common.js +++ b/packages/select/test/select.common.js @@ -510,15 +510,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; }); });