From a5a43a3df9a2935981e1a3a32e8faa7d62e894f9 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Fri, 16 Jun 2023 15:04:09 -0700 Subject: [PATCH 1/2] Just modify the hook --- .../interactive-hooks/src/useOnPressWithFocus.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/utils/interactive-hooks/src/useOnPressWithFocus.ts b/packages/utils/interactive-hooks/src/useOnPressWithFocus.ts index b09052ccde..2cc7254616 100644 --- a/packages/utils/interactive-hooks/src/useOnPressWithFocus.ts +++ b/packages/utils/interactive-hooks/src/useOnPressWithFocus.ts @@ -5,19 +5,18 @@ import { Platform } from 'react-native'; export type OnPressCallback = (args: GestureResponderEvent) => void; export type OnPressWithFocusCallback = (args: GestureResponderEvent) => void; -/* Re-usable hook for pressable components. - * This hook sets focus on a component after onPress behavior. - * - * PROPS: focusRef - the ref used to set focus - * userCallback() - Callback provided by userProps for onPress behavior - * RETURNS: - * onPressWithFocus() - Callback to set focus after calling the userCallback for onPress +/** + * Sets focus on the focusRef after calling the userCallback for onPress, if that is an expected behavior on the platform + * @param focusRef the ref used to set focus, generally the ref of the component that is being pressed + * @param userCallback user-provided callback for onPress behavior + * @returns Hook that sets focus, then calls the user callback */ export function useOnPressWithFocus(focusRef: React.RefObject, userCallback: OnPressCallback): OnPressWithFocusCallback { const onPressWithFocus = React.useCallback( (args?: any) => { const platformSupportsFocus = ['windows', 'win32', 'macos'].includes(Platform.OS as string); - if (platformSupportsFocus) { + const takesFocusOnClick = ['windows', 'win32'].includes(Platform.OS as string); + if (platformSupportsFocus && takesFocusOnClick) { focusRef?.current?.focus(); } From 91cf7a0d14214598f92da0926a4d0ee5bb3b03fe Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Fri, 16 Jun 2023 15:22:54 -0700 Subject: [PATCH 2/2] Change files --- ...ractive-hooks-00476c7a-9659-4dcd-ae01-130251e854a1.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-native-interactive-hooks-00476c7a-9659-4dcd-ae01-130251e854a1.json diff --git a/change/@fluentui-react-native-interactive-hooks-00476c7a-9659-4dcd-ae01-130251e854a1.json b/change/@fluentui-react-native-interactive-hooks-00476c7a-9659-4dcd-ae01-130251e854a1.json new file mode 100644 index 0000000000..42732562cd --- /dev/null +++ b/change/@fluentui-react-native-interactive-hooks-00476c7a-9659-4dcd-ae01-130251e854a1.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "useOnPressWihFocus doesn't take focus on macOS", + "packageName": "@fluentui-react-native/interactive-hooks", + "email": "sanajmi@microsoft.com", + "dependentChangeType": "patch" +}