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

[NumericInput] ❤️ #3204

Merged
merged 15 commits into from
Dec 3, 2018
5 changes: 5 additions & 0 deletions packages/core/src/common/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ export const ARROW_UP = 38;
export const ARROW_RIGHT = 39;
export const ARROW_DOWN = 40;
export const DELETE = 46;

/** Returns whether the key code is `enter` or `space`, the two keys that can click a button. */
export function isKeyboardClick(keyCode: number) {
return keyCode === ENTER || keyCode === SPACE;
}
8 changes: 2 additions & 6 deletions packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
// argument because it is not a supertype of candidate
// 'KeyboardEvent<HTMLElement>'."
protected handleKeyDown = (e: React.KeyboardEvent<any>) => {
if (isKeyboardClick(e.which)) {
if (Keys.isKeyboardClick(e.which)) {
e.preventDefault();
if (e.which !== this.currentKeyDown) {
this.setState({ isActive: true });
Expand All @@ -136,7 +136,7 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
};

protected handleKeyUp = (e: React.KeyboardEvent<any>) => {
if (isKeyboardClick(e.which)) {
if (Keys.isKeyboardClick(e.which)) {
this.setState({ isActive: false });
this.buttonRef.click();
}
Expand All @@ -159,7 +159,3 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<any>> extend
];
}
}

function isKeyboardClick(keyCode: number) {
return keyCode === Keys.ENTER || keyCode === Keys.SPACE;
}
Loading