Skip to content

Commit

Permalink
Merge pull request #35415 from bernhardoj/fix/35373-enter-doesn't-work
Browse files Browse the repository at this point in the history
Fix enter doesn't work after going back from referral page
  • Loading branch information
bondydaa authored Feb 13, 2024
2 parents f438cb7 + b846422 commit 3791db8
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,19 @@ class BaseOptionsSelector extends Component {

componentDidUpdate(prevProps, prevState) {
if (prevState.disableEnterShortCut !== this.state.disableEnterShortCut) {
if (this.state.disableEnterShortCut) {
if (this.unsubscribeEnter) {
this.unsubscribeEnter();
this.unsubscribeEnter = undefined;
}
} else {
// Unregister the shortcut before registering a new one to avoid lingering shortcut listener
this.unsubscribeEnter();
if (!this.state.disableEnterShortCut) {
this.subscribeToEnterShortcut();
}
}

if (prevProps.isFocused !== this.props.isFocused) {
// Unregister the shortcut before registering a new one to avoid lingering shortcut listener
this.unSubscribeFromKeyboardShortcut();
if (this.props.isFocused) {
this.subscribeToEnterShortcut();
this.subscribeToCtrlEnterShortcut();
} else {
this.unSubscribeFromKeyboardShortcut();
}
}

Expand Down Expand Up @@ -293,9 +290,6 @@ class BaseOptionsSelector extends Component {
}

subscribeToEnterShortcut() {
if (this.unsubscribeEnter) {
this.unsubscribeEnter();
}
const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER;
this.unsubscribeEnter = KeyboardShortcut.subscribe(
enterConfig.shortcutKey,
Expand All @@ -308,9 +302,6 @@ class BaseOptionsSelector extends Component {
}

subscribeToCtrlEnterShortcut() {
if (this.unsubscribeCTRLEnter) {
this.unsubscribeCTRLEnter();
}
const CTRLEnterConfig = CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER;
this.unsubscribeCTRLEnter = KeyboardShortcut.subscribe(
CTRLEnterConfig.shortcutKey,
Expand All @@ -336,12 +327,10 @@ class BaseOptionsSelector extends Component {
unSubscribeFromKeyboardShortcut() {
if (this.unsubscribeEnter) {
this.unsubscribeEnter();
this.unsubscribeEnter = undefined;
}

if (this.unsubscribeCTRLEnter) {
this.unsubscribeCTRLEnter();
this.unsubscribeCTRLEnter = undefined;
}
}

Expand Down

0 comments on commit 3791db8

Please sign in to comment.