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
Expand Up @@ -29,7 +29,7 @@ export const FocusZoneTabNavigations: FocusZoneTabNavigation[] = ['None', 'Navig

// Buttons by default focus on click on Win32, but they don't on the Mac, so place focus explicitly for convenience
function useFocusOnClickForMac(): Partial<ButtonProps> {
const componentRef = React.useRef<IFocusable>();
const componentRef = React.useRef<IFocusable>(null);
const onClick = React.useCallback(() => componentRef.current?.focus(), [componentRef]);
return Platform.OS === 'macos' ? { componentRef, onClick } : {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ const FocusZoneTabNavigationComponent: React.FunctionComponent = () => {
};

const TinyBox = () => {
const ref = React.useRef<View>();
const ref = React.useRef<View>(null);
const onPress = useOnPressWithFocus(ref, null);

return <Pressable focusable style={focusZoneTestStyles.smallBoxStyle} ref={ref} onPress={onPress} />;
};

const WideBox = () => {
const ref = React.useRef<View>();
const ref = React.useRef<View>(null);
const onPress = useOnPressWithFocus(ref, null);

return <Pressable focusable style={focusZoneTestStyles.wideBoxStyle} ref={ref} onPress={onPress} />;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "ensure useRef always has a parameter",
"packageName": "@fluentui-react-native/dropdown",
"email": "jasonmo@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "ensure useRef always has a parameter",
"packageName": "@fluentui-react-native/interactive-hooks",
"email": "jasonmo@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "ensure useRef always has a parameter",
"packageName": "@fluentui-react-native/menu",
"email": "jasonmo@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "ensure useRef always has a parameter",
"packageName": "@fluentui-react-native/tester-core",
"email": "jasonmo@microsoft.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion packages/components/Menu/src/Menu/useMenu.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useMenu = (props: MenuProps): MenuState => {
* State , Ref and Context Values for Menu Container and Anchor
*/

const triggerRef = React.useRef();
const triggerRef = React.useRef<View>(null);
const context = useMenuContext();
const isSubmenu = context.triggerRef !== null;
const isOpenControlled = typeof props.open !== 'undefined';
Expand Down
3 changes: 2 additions & 1 deletion packages/components/Menu/src/Menu/useMenu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import type { View } from 'react-native';
import { Platform } from 'react-native';

import type { InteractionEvent } from '@fluentui-react-native/interactive-hooks';
Expand All @@ -14,7 +15,7 @@ import { useMenuContext } from '../context/menuContext';
const delayOpen = 150;

export const useMenu = (props: MenuProps): MenuState => {
const triggerRef = React.useRef();
const triggerRef = React.useRef<View>(null);
const context = useMenuContext();
const isSubmenu = context.triggerRef !== null;
const isOpenControlled = typeof props.open !== 'undefined';
Expand Down
2 changes: 1 addition & 1 deletion packages/components/Menu/src/MenuList/useMenuList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const useMenuList = (_props: MenuListProps): MenuListState => {
});

// focus management
const focusZoneRef = React.useRef<View>();
const focusZoneRef = React.useRef<View>(null);
const setFocusZoneFocus = () => {
focusZoneRef?.current?.focus();
};
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental/Dropdown/src/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Dropdown = compressible<DropdownProps, DropdownTokens>((props: DropdownPro
const onButtonClick = React.useCallback(() => {
setOpen(!isOpen);
}, [isOpen, setOpen]);
const defaultRef = React.useRef();
const defaultRef = React.useRef<View>(null);

const buttonProps: ButtonProps = React.useMemo(
() => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/interactive-hooks/src/useConst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export function useConst<T>(initialValue: T | FunctionToValue<T>): T {
// Use useRef to store the value because it's the least expensive built-in hook that works here
// (we could also use `const [value] = React.useState(initialValue)` but that's more expensive
// internally due to reducer handling which we don't need)
const ref = React.useRef<{ value: T }>();
if (ref.current === undefined) {
const ref = React.useRef<{ value: T }>(null);
if (ref.current == null) {
// Box the value in an object so we can tell if it's initialized even if the initializer
// returns/is undefined
ref.current = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function useViewCommandFocus(
/**
* Set up the forwarding ref to enable adding the focus method.
*/
const focusRef = React.useRef<any>();
const focusRef = React.useRef<any>(null);

const _setNativeRef = setAndForwardRef({
getForwardedRef: () => forwardedRef,
Expand Down
Loading