Skip to content

Commit

Permalink
fix listener added in options selector
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Feb 13, 2024
1 parent da5737c commit 224bdda
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class BaseOptionsSelector extends Component {
componentDidUpdate(prevProps, prevState) {
if (prevState.disableEnterShortCut !== this.state.disableEnterShortCut) {
if (this.state.disableEnterShortCut) {
this.unsubscribeEnter();
if (this.unsubscribeEnter) {
this.unsubscribeEnter();
this.unsubscribeEnter = undefined;
}
} else {
this.subscribeToEnterShortcut();
}
Expand Down Expand Up @@ -290,6 +293,9 @@ class BaseOptionsSelector extends Component {
}

subscribeToEnterShortcut() {
if (this.unsubscribeEnter) {
this.unsubscribeEnter();
}
const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER;
this.unsubscribeEnter = KeyboardShortcut.subscribe(
enterConfig.shortcutKey,
Expand All @@ -302,6 +308,9 @@ 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 @@ -327,10 +336,12 @@ 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 224bdda

Please sign in to comment.