From 00c0523248cf266e8b6c033da3253f8bc54895d8 Mon Sep 17 00:00:00 2001 From: AmjedNazzal Date: Fri, 12 May 2023 20:35:58 +0300 Subject: [PATCH 1/4] Issue18265 --- src/components/OptionsSelector/BaseOptionsSelector.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index 21af8d1762db..84097a10dbb0 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -52,6 +52,7 @@ class BaseOptionsSelector extends Component { componentDidMount() { const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER; + let isEnterDisabled = false; this.unsubscribeEnter = KeyboardShortcut.subscribe( enterConfig.shortcutKey, () => { @@ -60,7 +61,14 @@ class BaseOptionsSelector extends Component { return; } - this.selectRow(focusedOption); + // We are handeling multiple Enter events to address the issue in https://github.com/Expensify/App/issues/18265 + if (!isEnterDisabled) { + isEnterDisabled = true; + this.selectRow(focusedOption); + setTimeout(() => { + isEnterDisabled = false; + }, 300); + } }, enterConfig.descriptionKey, enterConfig.modifiers, From 6fc32bdaaef99caf4c61fc6aff79c973de3f80fa Mon Sep 17 00:00:00 2001 From: AmjedNazzal Date: Fri, 12 May 2023 21:22:38 +0300 Subject: [PATCH 2/4] add promise to debounce --- .../OptionsSelector/BaseOptionsSelector.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index 84097a10dbb0..8f9614cc70ad 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -47,12 +47,12 @@ class BaseOptionsSelector extends Component { this.state = { allOptions, focusedIndex, + isEnterDisabled: false, }; } componentDidMount() { const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER; - let isEnterDisabled = false; this.unsubscribeEnter = KeyboardShortcut.subscribe( enterConfig.shortcutKey, () => { @@ -60,14 +60,13 @@ class BaseOptionsSelector extends Component { if (!focusedOption) { return; } - - // We are handeling multiple Enter events to address the issue in https://github.com/Expensify/App/issues/18265 - if (!isEnterDisabled) { - isEnterDisabled = true; - this.selectRow(focusedOption); - setTimeout(() => { - isEnterDisabled = false; - }, 300); + if (!this.state.isEnterDisabled) { + this.setState({isEnterDisabled: true}); + let result = this.selectRow(focusedOption); + if (!(result instanceof Promise)) { + result = Promise.resolve(); + } + setTimeout(() => result.finally(() => this.setState({isEnterDisabled: false})), 300); } }, enterConfig.descriptionKey, From 3f4eafa40201c5ddcd8a19941d850e6a150a8e49 Mon Sep 17 00:00:00 2001 From: AmjedNazzal Date: Fri, 12 May 2023 21:26:52 +0300 Subject: [PATCH 3/4] Changed variable name --- src/components/OptionsSelector/BaseOptionsSelector.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index 8f9614cc70ad..695d56d426cb 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -47,7 +47,7 @@ class BaseOptionsSelector extends Component { this.state = { allOptions, focusedIndex, - isEnterDisabled: false, + shouldDisableRowSelection: false, }; } @@ -60,13 +60,13 @@ class BaseOptionsSelector extends Component { if (!focusedOption) { return; } - if (!this.state.isEnterDisabled) { - this.setState({isEnterDisabled: true}); + if (!this.state.shouldDisableRowSelection) { + this.setState({shouldDisableRowSelection: true}); let result = this.selectRow(focusedOption); if (!(result instanceof Promise)) { result = Promise.resolve(); } - setTimeout(() => result.finally(() => this.setState({isEnterDisabled: false})), 300); + setTimeout(() => result.finally(() => this.setState({shouldDisableRowSelection: false})), 300); } }, enterConfig.descriptionKey, From f624081e43e9db67f5729abb9f6497a7f2702a87 Mon Sep 17 00:00:00 2001 From: AmjedNazzal Date: Sat, 13 May 2023 12:52:29 +0300 Subject: [PATCH 4/4] logic adjustment --- src/components/OptionsSelector/BaseOptionsSelector.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index 695d56d426cb..f2ae4ee96718 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -60,13 +60,15 @@ class BaseOptionsSelector extends Component { if (!focusedOption) { return; } - if (!this.state.shouldDisableRowSelection) { + if (this.props.canSelectMultipleOptions) { + this.selectRow(focusedOption); + } else if (!this.state.shouldDisableRowSelection) { this.setState({shouldDisableRowSelection: true}); let result = this.selectRow(focusedOption); if (!(result instanceof Promise)) { result = Promise.resolve(); } - setTimeout(() => result.finally(() => this.setState({shouldDisableRowSelection: false})), 300); + setTimeout(() => result.finally(() => this.setState({shouldDisableRowSelection: false})), 500); } }, enterConfig.descriptionKey,