Skip to content

Commit

Permalink
feat(ffe-form-react): Pass refs for input and textarea
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Requires React 16.3.0 and above!

This commit lets the consumer pass refs down to the `Input` and
`TextArea` components, to handle focus et al.

The only breaking change is the fact that React 16.3.0 is required.

Fixes #231.
  • Loading branch information
selbekk committed May 22, 2018
1 parent d549e1a commit 066c71f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/ffe-form-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"peerDependencies": {
"@sb1/ffe-core": "^12.0.0",
"@sb1/ffe-form": "^9.0.0",
"react": "^16.2.0"
"react": "^16.3.0"
},
"publishConfig": {
"access": "public"
Expand Down
6 changes: 4 additions & 2 deletions packages/ffe-form-react/src/Input.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import React, { forwardRef } from 'react';
import { bool, string } from 'prop-types';
import classNames from 'classnames';

const Input = ({ className, inline, textLike, ...rest }) => {
const Input = forwardRef((props, ref) => {
const { className, inline, textLike, ...rest } = props;
return (
<input
className={classNames(
Expand All @@ -12,6 +13,7 @@ const Input = ({ className, inline, textLike, ...rest }) => {
className,
)}
{...rest}
ref={ref}
/>
);
};
Expand Down
13 changes: 9 additions & 4 deletions packages/ffe-form-react/src/TextArea.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from 'react';
import React, { forwardRef } from 'react';
import { string } from 'prop-types';
import classNames from 'classnames';

const TextArea = ({ className, ...rest }) => {
const TextArea = forwardRef((props, ref) => {
const { className, ...rest } = props;
return (
<textarea className={classNames('ffe-textarea', className)} {...rest} />
<textarea
className={classNames('ffe-textarea', className)}
{...rest}
ref={ref}
/>
);
};
});

TextArea.propTypes = {
className: string,
Expand Down

0 comments on commit 066c71f

Please sign in to comment.