Skip to content

Commit

Permalink
Merge pull request #15473 from narefyev91/open-picker-when-error-appears
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Mechler authored Feb 27, 2023
2 parents 9456e8c + 55f5ba1 commit 835a9f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/components/DatePicker/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,17 @@ class DatePicker extends React.Component {
* @param {Date} selectedDate
*/
setDate(event, selectedDate) {
this.setState({isPickerVisible: false});

if (event.type === 'set') {
const asMoment = moment(selectedDate, true);
this.props.onInputChange(asMoment.format(CONST.DATE.MOMENT_FORMAT_STRING));
}

this.setState({isPickerVisible: false});
}

/**
* @param {Event} event
*/
showPicker(event) {
showPicker() {
Keyboard.dismiss();
this.setState({isPickerVisible: true});
event.preventDefault();
}

render() {
Expand All @@ -63,6 +59,13 @@ class DatePicker extends React.Component {
if (!_.isFunction(this.props.innerRef)) {
return;
}
if (el && el.focus && typeof el.focus === 'function') {
let inputRef = {...el};
inputRef = {...inputRef, focus: this.showPicker};
this.props.innerRef(inputRef);
return;
}

this.props.innerRef(el);
}}
/>
Expand Down
13 changes: 8 additions & 5 deletions src/components/DatePicker/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class DatePicker extends React.Component {
this.updateLocalDate = this.updateLocalDate.bind(this);
}

/**
* @param {Event} event
*/
showPicker(event) {
showPicker() {
this.initialValue = this.state.selectedDate;

// Opens the popover only after the keyboard is hidden to avoid a "blinking" effect where the keyboard was on iOS
Expand All @@ -52,7 +49,6 @@ class DatePicker extends React.Component {
listener.remove();
});
Keyboard.dismiss();
event.preventDefault();
}

/**
Expand Down Expand Up @@ -100,6 +96,13 @@ class DatePicker extends React.Component {
if (!_.isFunction(this.props.innerRef)) {
return;
}
if (el && el.focus && typeof el.focus === 'function') {
let inputRef = {...el};
inputRef = {...inputRef, focus: this.showPicker};
this.props.innerRef(inputRef);
return;
}

this.props.innerRef(el);
}}
/>
Expand Down

0 comments on commit 835a9f1

Please sign in to comment.