Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions docs/src/pages/api/DayPickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default () => (
</p>
<p>
If your custom component doesn’t support such props, wrap it in a
component contaning them. For example:
component containing them. For example:
</p>
<CodeBlock>{`import React from 'react';
import { DayPickerInput } from 'react-day-picker';
Expand All @@ -93,9 +93,33 @@ class MyInputWithFocus extends React.Component {
}
}

function MyDayPickerInput(props) {
function MyDayPickerInput() {
return <DayPickerInput component={MyInputWithFocus} />
}
`}</CodeBlock>

<p>
An alternative is to use{' '}
<a href="https://reactjs.org/docs/forwarding-refs.html">forwardRef()</a>{' '}
from React 16.3 to forward the ref directly to the native input.
</p>
<CodeBlock>{`import React from 'react';
import { DayPickerInput } from 'react-day-picker';

class MyInput extends React.Component {
render() {
const { forwardRef, ...rest} = this.props;
return <input ref={forwardRef} {...rest} />;
}
}

const MyInputWithForwardedRef = React.forwardRef((props, ref) => (
<MyInputWithoutFocus {...props} forwardRef={ref} />
));

function MyDayPickerInput() {
return <DayPickerInput component={MyInputWithForwardedRef} />
}
`}</CodeBlock>

<h3>
Expand Down