From 63d99ba38ebb523ae9381bf5cd5d534af52cb237 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Fri, 21 Apr 2023 18:29:04 +0500 Subject: [PATCH] fix: correct focus index for option list --- src/components/OptionsSelector/BaseOptionsSelector.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index 326072b73a1b..c844ef6fe98a 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -93,7 +93,7 @@ class BaseOptionsSelector extends Component { true, ); - this.scrollToIndex(this.state.focusedIndex, false); + this.scrollToIndex(this.props.selectedOptions.length ? 0 : this.state.focusedIndex, false); if (!this.props.autoFocus) { return; @@ -153,6 +153,9 @@ class BaseOptionsSelector extends Component { * @returns {Number} */ getInitiallyFocusedIndex(allOptions) { + if (this.props.selectedOptions.length > 0) { + return this.props.selectedOptions.length; + } const defaultIndex = this.props.shouldTextInputAppearBelowOptions ? allOptions.length : 0; if (_.isUndefined(this.props.initiallyFocusedOptionKey)) { return defaultIndex; @@ -305,7 +308,9 @@ class BaseOptionsSelector extends Component { isDisabled={this.props.isDisabled} shouldHaveOptionSeparator={this.props.shouldHaveOptionSeparator} onLayout={() => { - this.scrollToIndex(this.state.focusedIndex, false); + if (this.props.selectedOptions.length === 0) { + this.scrollToIndex(this.state.focusedIndex, false); + } if (this.props.onLayout) { this.props.onLayout();