Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hurali97 committed Jan 11, 2024
1 parent 32aded4 commit 864dead
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,36 @@ type KeyboardShortcutComponentProps = Pick<ButtonProps, 'isDisabled' | 'isLoadin
const accessibilityRoles: string[] = Object.values(CONST.ACCESSIBILITY_ROLE);

function KeyboardShortcutComponent({isDisabled = false, isLoading = false, onPress = () => {}, pressOnEnter, allowBubble, enterKeyEventListenerPriority}: KeyboardShortcutComponentProps) {
const isFocused = useIsFocused();
const activeElementRole = useActiveElementRole();

const shouldDisableEnterShortcut = useMemo(() => accessibilityRoles.includes(activeElementRole ?? '') && activeElementRole !== CONST.ACCESSIBILITY_ROLE.TEXT, [activeElementRole]);

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

const shouldDisableEnterShortcut = useMemo(() => accessibilityRoles.includes(activeElementRole ?? '') && activeElementRole !== CONST.ACCESSIBILITY_ROLE.TEXT, [activeElementRole]);

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

const config = useMemo(
() => ({
isActive: pressOnEnter && !shouldDisableEnterShortcut && isFocused,
shouldBubble: allowBubble,
priority: enterKeyEventListenerPriority,
shouldPreventDefault: false,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[shouldDisableEnterShortcut, isFocused],
);
const config = useMemo(
() => ({
isActive: pressOnEnter && !shouldDisableEnterShortcut && isFocused,
shouldBubble: allowBubble,
priority: enterKeyEventListenerPriority,
shouldPreventDefault: false,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[shouldDisableEnterShortcut, isFocused],
);

useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, keyboardShortcutCallback, config);
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, keyboardShortcutCallback, config);

return null;
};
return null;
}

KeyboardShortcutComponent.displayName = 'KeyboardShortcutComponent';

Expand Down

0 comments on commit 864dead

Please sign in to comment.