Skip to content

Commit

Permalink
feat: add inputRef to props
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfisher committed Aug 22, 2020
1 parent a231081 commit 65b2c1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import TimeField from 'react-simple-timefield';
value={time} // {String} required, format '00:00' or '00:00:00'
onChange={(event, value) => {...}} // {Function} required
input={<MyCustomInputElement />} // {Element} default: <input type="text" />
inputRef={(ref) => {...}} // {Function} input's ref
colon=":" // {String} default: ":"
showSeconds // {Boolean} default: false
/>
Expand Down Expand Up @@ -86,11 +87,15 @@ in `demo/index.tsx` file.
```bash
# run development mode
cd demo
npm install
npm install --only=dev
npm run dev
```

#### Build:
```bash
npm install
npm install --only=dev
npm test
npm run format
npm run build
Expand Down
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface Props {
onChange?: onChangeType;
showSeconds?: boolean;
input: ReactElement | null;
inputRef?: () => HTMLInputElement | null;
colon?: string;
style?: CSSProperties | {};
}
Expand Down Expand Up @@ -196,7 +197,7 @@ export default class TimeField extends React.Component<Props, State> {

render(): ReactElement {
const {value} = this.state;
const {onChange, style, showSeconds, input, colon, ...props} = this.props; //eslint-disable-line no-unused-vars
const {onChange, style, showSeconds, input, inputRef, colon, ...props} = this.props; //eslint-disable-line no-unused-vars
const onChangeHandler = (event: ChangeEvent<HTMLInputElement>) =>
this.onInputChange(event, (e: ChangeEvent<HTMLInputElement>, v: string) => onChange && onChange(e, v));

Expand All @@ -213,6 +214,7 @@ export default class TimeField extends React.Component<Props, State> {
<input
type="text"
{...props}
ref={inputRef}
value={value}
onChange={onChangeHandler}
style={{width: showSeconds ? 54 : 35, ...style}}
Expand Down

0 comments on commit 65b2c1f

Please sign in to comment.