From 55f5ba15f27f473eccf2e259e94f94a15f4fde45 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Fri, 24 Feb 2023 15:30:14 +0200 Subject: [PATCH] Android/IOS app does not focus on date of birth field when 'fix the errors' link is clicked --- src/components/DatePicker/index.android.js | 17 ++++++++++------- src/components/DatePicker/index.ios.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/DatePicker/index.android.js b/src/components/DatePicker/index.android.js index 922c676b6a45..83c1ca5f09d4 100644 --- a/src/components/DatePicker/index.android.js +++ b/src/components/DatePicker/index.android.js @@ -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() { @@ -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); }} /> diff --git a/src/components/DatePicker/index.ios.js b/src/components/DatePicker/index.ios.js index 61c91b4a93ee..6e286e8447e2 100644 --- a/src/components/DatePicker/index.ios.js +++ b/src/components/DatePicker/index.ios.js @@ -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 @@ -52,7 +49,6 @@ class DatePicker extends React.Component { listener.remove(); }); Keyboard.dismiss(); - event.preventDefault(); } /** @@ -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); }} />