Skip to content

Commit

Permalink
feat(DateInput): revert last valid value on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Nov 23, 2018
1 parent e0d50cd commit 9f6c676
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/atoms/dataEntry/DateInput/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
}
};

onBlur = () => {
const { withTime } = this.props;
const { textValue } = this.state;

const luxonValue = utils.fromViewFormatToLuxon(textValue, withTime);

if (luxonValue && !luxonValue.isValid) {
this.setState({ textValue: utils.fromISOToViewFormat(this.props.value, withTime) });
}
}

onChangeDate = (selected: Date) => {
const { withTime, value } = this.props;

Expand Down Expand Up @@ -132,7 +143,7 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
{ ...rest }
>
<Dropdown.Head onClick={ this.open }>
<DateInputValue mask={ mask } value={ textValue } onChange={ this.onChangeText } />
<DateInputValue mask={ mask } value={ textValue } onChange={ this.onChangeText } onBlur={ this.onBlur } />
</Dropdown.Head>
<Dropdown.Body withPortal preventOverflow>
<DatePicker { ...collectedProps } />
Expand Down
1 change: 1 addition & 0 deletions src/atoms/dataEntry/DateInput/DateInputValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Input } from '../Input';

type DateInputValueProps = {|
onChange: (value: Object) => void,
onBlur: () => void,
value: ?string,
mask: string,
|};
Expand Down

0 comments on commit 9f6c676

Please sign in to comment.