Skip to content
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
Original file line number Diff line number Diff line change
@@ -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"
}
15 changes: 7 additions & 8 deletions packages/utils/interactive-hooks/src/useOnPressWithFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>, 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();
}

Expand Down