Skip to content

Commit

Permalink
fix: ensure "click" on "NumpadEnter" key press
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Sep 20, 2021
1 parent e8d9768 commit 450fa01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/button/src/ButtonBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class ButtonBase extends LikeAnchor(
const { code } = event;
switch (code) {
case 'Enter':
case 'NumpadEnter':
this.click();
break;
default:
Expand Down
26 changes: 21 additions & 5 deletions packages/button/test/button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Button', () => {
await elementUpdated(el);
expect(el).to.not.be.undefined;
expect(el.textContent).to.include('Button');
expect(!((el as unknown) as { hasIcon: boolean }).hasIcon);
expect(!(el as unknown as { hasIcon: boolean }).hasIcon);
await expect(el).to.be.accessible();
});
it('loads default only icon', async () => {
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Button', () => {

await elementUpdated(el);

const labelTestableEl = (el as unknown) as TestableButtonType;
const labelTestableEl = el as unknown as TestableButtonType;

expect(labelTestableEl.hasLabel, 'starts with label').to.be.true;

Expand Down Expand Up @@ -304,6 +304,20 @@ describe('Button', () => {
expect(clickSpy.callCount).to.equal(1);
clickSpy.resetHistory();

el.dispatchEvent(
new KeyboardEvent('keypress', {
bubbles: true,
composed: true,
cancelable: true,
code: 'NumpadEnter',
key: 'NumpadEnter',
})
);

await elementUpdated(el);
expect(clickSpy.callCount).to.equal(1);
clickSpy.resetHistory();

el.dispatchEvent(
new KeyboardEvent('keypress', {
bubbles: true,
Expand Down Expand Up @@ -451,9 +465,11 @@ describe('Button', () => {
);

await elementUpdated(el);
((el as unknown) as {
anchorElement: HTMLAnchorElement;
}).anchorElement.addEventListener('click', (event: Event): void => {
(
el as unknown as {
anchorElement: HTMLAnchorElement;
}
).anchorElement.addEventListener('click', (event: Event): void => {
event.preventDefault();
event.stopPropagation();
clickSpy();
Expand Down

0 comments on commit 450fa01

Please sign in to comment.