Skip to content

Commit

Permalink
fix(refs): allow NumericInput component to take a ref prop
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Apr 23, 2019
1 parent ee4e23d commit 203d143
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@emotion/core": "10.0.10",
"@emotion/styled": "10.0.10",
"@quid/merge-refs": "1.38.1",
"@wkovacs64/normalize.css": "8.0.1",
"currency.js": "1.2.1",
"gatsby": "2.3.25",
Expand Down
1 change: 1 addition & 0 deletions src/@types/quid__merge-refs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@quid/merge-refs';
12 changes: 7 additions & 5 deletions src/components/numeric-input.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';
import mergeRefs from '@quid/merge-refs';
import NumberInput from '../styles/number-input';

const NumericInput: React.FunctionComponent<
React.InputHTMLAttributes<HTMLInputElement>
> = props => {
const NumericInput = React.forwardRef<
HTMLInputElement,
React.ComponentPropsWithRef<typeof NumberInput>
>((props, userRef) => {
const ref = React.useRef<HTMLInputElement>(null);

return (
<NumberInput
type="text"
inputMode="numeric"
ref={ref}
ref={mergeRefs(ref, userRef)}
onKeyDown={e => {
if (e.keyCode === 13 && ref && ref.current) {
ref.current.blur();
Expand All @@ -20,6 +22,6 @@ const NumericInput: React.FunctionComponent<
{...props}
/>
);
};
});

export default NumericInput;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,11 @@
string-width "^2.0.0"
strip-ansi "^3"

"@quid/merge-refs@1.38.1":
version "1.38.1"
resolved "https://registry.yarnpkg.com/@quid/merge-refs/-/merge-refs-1.38.1.tgz#eea1e94066726f07d1bdf8ea07aae0e21f2b228b"
integrity sha512-ZmNE8DTcia8eNqDnrz9O/unKXVXRwCYuopG6ervXV6WUBGohz8q3fRn45GiiySXS1+gmzPWp8BjE2sMJr+pRZg==

"@reach/router@^1.1.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.2.1.tgz#34ae3541a5ac44fa7796e5506a5d7274a162be4e"
Expand Down

0 comments on commit 203d143

Please sign in to comment.