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 click on Enter and Space when using key modifiers (CP: #6404) #6523

Merged
merged 1 commit into from
Sep 25, 2023
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
4 changes: 4 additions & 0 deletions packages/button/src/vaadin-button-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export const ButtonMixin = (superClass) =>
_onKeyDown(event) {
super._onKeyDown(event);

if (event.altKey || event.shiftKey || event.ctrlKey || event.metaKey) {
return;
}

if (this._activeKeys.includes(event.key)) {
event.preventDefault();

Expand Down
18 changes: 18 additions & 0 deletions packages/button/test/button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ describe('vaadin-button', () => {
expect(spy.called).to.be.false;
});

const modifiers = ['Shift', 'Control', 'Alt'];
if (navigator.platform === 'MacIntel') {
modifiers.push('Meta');
}

modifiers.forEach((modifier) => {
it(`should not fire click event on ${key} when using modifier ${modifier}`, async () => {
const spy = sinon.spy();
element.addEventListener('click', spy);

await sendKeys({ down: modifier });
await sendKeys({ down: key });

expect(spy.called).to.be.false;
await sendKeys({ up: modifier });
});
});

it(`should prevent default behaviour for keydown event on ${key}`, async () => {
const spy = sinon.spy();
element.addEventListener('keydown', spy);
Expand Down