Skip to content

Commit 03147eb

Browse files
authored
fix: prevent opening select on click or keydown when disabled (#7874)
1 parent a2a810a commit 03147eb

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎packages/select/src/vaadin-select-base-mixin.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ export const SelectBaseMixin = (superClass) =>
304304
* @private
305305
*/
306306
_onClick(event) {
307+
if (this.disabled) {
308+
return;
309+
}
310+
307311
// Prevent parent components such as `vaadin-grid`
308312
// from handling the click event after it bubbles.
309313
event.preventDefault();
@@ -324,7 +328,7 @@ export const SelectBaseMixin = (superClass) =>
324328
* @override
325329
*/
326330
_onKeyDown(e) {
327-
if (e.target === this.focusElement && !this.readonly && !this.opened) {
331+
if (e.target === this.focusElement && !this.readonly && !this.disabled && !this.opened) {
328332
if (/^(Enter|SpaceBar|\s|ArrowDown|Down|ArrowUp|Up)$/u.test(e.key)) {
329333
e.preventDefault();
330334
this.opened = true;

‎packages/select/test/select.common.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,24 @@ describe('vaadin-select', () => {
499499
});
500500

501501
describe('disabled', () => {
502-
it('should disable the button and disable opening if select is disabled', async () => {
502+
beforeEach(async () => {
503503
select.disabled = true;
504504
await nextUpdate(select);
505+
});
506+
507+
it('should disable the value button element when disabled', () => {
505508
expect(valueButton.disabled).to.be.true;
509+
});
506510

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

517+
it('should not open on value button click when disabled', () => {
510518
click(valueButton);
519+
expect(select.opened).to.be.false;
511520
expect(select._overlayElement.opened).to.be.false;
512521
});
513522
});

0 commit comments

Comments
 (0)