Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pressOnEnter of button to be disabled when screen is not focused #33889

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ function Button(

const keyboardShortcutCallback = useCallback(
(event?: GestureResponderEvent | KeyboardEvent) => {
if (!validateSubmitShortcut(isFocused, isDisabled, isLoading, event)) {
if (!validateSubmitShortcut(isDisabled, isLoading, event)) {
return;
}
onPress();
},
[isDisabled, isFocused, isLoading, onPress],
[isDisabled, isLoading, onPress],
);

useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, keyboardShortcutCallback, {
isActive: pressOnEnter && !shouldDisableEnterShortcut,
isActive: pressOnEnter && !shouldDisableEnterShortcut && isFocused,
shouldBubble: allowBubble,
priority: enterKeyEventListenerPriority,
shouldPreventDefault: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import type ValidateSubmitShortcut from './types';
/**
* Validate if the submit shortcut should be triggered depending on the button state
*
* @param isFocused Whether Button is on active screen
* @param isDisabled Indicates whether the button should be disabled
* @param isLoading Indicates whether the button should be disabled and in the loading state
* @return Returns `true` if the shortcut should be triggered
*/

const validateSubmitShortcut: ValidateSubmitShortcut = (isFocused, isDisabled, isLoading) => {
if (!isFocused || isDisabled || isLoading) {
const validateSubmitShortcut: ValidateSubmitShortcut = (isDisabled, isLoading) => {
if (isDisabled || isLoading) {
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions src/components/Button/validateSubmitShortcut/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import type ValidateSubmitShortcut from './types';
/**
* Validate if the submit shortcut should be triggered depending on the button state
*
* @param isFocused Whether Button is on active screen
* @param isDisabled Indicates whether the button should be disabled
* @param isLoading Indicates whether the button should be disabled and in the loading state
* @param event Focused input event
* @returns Returns `true` if the shortcut should be triggered
*/

const validateSubmitShortcut: ValidateSubmitShortcut = (isFocused, isDisabled, isLoading, event) => {
const validateSubmitShortcut: ValidateSubmitShortcut = (isDisabled, isLoading, event) => {
const eventTarget = event?.target as HTMLElement;
if (!isFocused || isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA') {
if (isDisabled || isLoading || eventTarget.nodeName === 'TEXTAREA') {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/validateSubmitShortcut/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {GestureResponderEvent} from 'react-native';

type ValidateSubmitShortcut = (isFocused: boolean, isDisabled: boolean, isLoading: boolean, event?: GestureResponderEvent | KeyboardEvent) => boolean;
type ValidateSubmitShortcut = (isDisabled: boolean, isLoading: boolean, event?: GestureResponderEvent | KeyboardEvent) => boolean;

export default ValidateSubmitShortcut;
Loading