Skip to content

Commit 2f16669

Browse files
fix: update types for React 19 compatibility (#2522)
1 parent 4877115 commit 2f16669

27 files changed

Lines changed: 90 additions & 36 deletions

File tree

src/components/Drawer/components/Drawer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ export const Drawer = ({
145145

146146
const role = useRole(context, {role: 'dialog'});
147147
const {getFloatingProps} = useInteractions([dismiss, role]);
148-
const handleFloatingRef = useForkRef<HTMLDivElement>(refs.setFloating, floatingRef);
148+
/*
149+
* TODO: Remove casting in React 19 (https://github.com/gravity-ui/uikit/issues/2537)
150+
*/
151+
const handleFloatingRef = useForkRef<HTMLDivElement>(
152+
refs.setFloating,
153+
floatingRef as React.Ref<HTMLDivElement>,
154+
);
149155

150156
const portal =
151157
isMounted || keepMounted ? (

src/components/DropdownMenu/DropdownMenuNavigationContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as React from 'react';
55
export type DropdownMenuNavigationContextType = {
66
activeMenuPath: number[];
77
setActiveMenuPath: (path: number[]) => void;
8-
anchorRef: React.RefObject<HTMLDivElement>;
8+
anchorRef: React.RefObject<HTMLDivElement | null>;
99
};
1010

1111
const rootMenuPath: number[] = [];
@@ -19,7 +19,7 @@ export const DropdownMenuNavigationContext = React.createContext<DropdownMenuNav
1919
);
2020

2121
export type DropdownMenuNavigationContextProviderProps = {
22-
anchorRef: React.RefObject<HTMLDivElement>;
22+
anchorRef: React.RefObject<HTMLDivElement | null>;
2323
children: React.ReactNode;
2424
disabled: boolean;
2525
};

src/components/DropdownMenu/DropdownMenuPopup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {stringifyNavigationPath} from './utils/stringifyNavigationPath';
2121
export type DropdownMenuPopupProps<T> = {
2222
items: DropdownMenuListItem<T>[];
2323
open: boolean;
24-
anchorRef: React.RefObject<HTMLDivElement>;
24+
anchorRef: React.RefObject<HTMLDivElement | null>;
2525
onClose?: () => void;
2626
size?: DropdownMenuSize;
2727
menuProps?: MenuProps;

src/components/DropdownMenu/hooks/useScrollHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22

33
export function useScrollHandler(
44
onScroll: (event: Event) => void,
5-
anchorRef: React.RefObject<HTMLDivElement>,
5+
anchorRef: React.RefObject<HTMLDivElement | null>,
66
disabled?: boolean,
77
) {
88
React.useEffect(() => {

src/components/List/components/SimpleContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type SimpleContainerProps = React.PropsWithChildren<{
1212
onScrollToItem?: (node: HTMLElement) => boolean;
1313
}>;
1414

15-
type RefsList = Record<number, React.RefObject<ListItem>>;
15+
type RefsList = Record<number, React.RefObject<ListItem | null>>;
1616

1717
export type SimpleContainerState = {
1818
refsList: RefsList;

src/components/Modal/Modal.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export interface ModalProps
100100
/** Callback called when `Popup` is closed and "out" transition is completed */
101101
onTransitionOutComplete?: () => void;
102102
contentOverflow?: 'visible' | 'auto';
103-
floatingRef?: React.RefObject<HTMLDivElement>;
103+
floatingRef?: React.RefObject<HTMLDivElement | null>;
104104
disableHeightTransition?: boolean;
105105
}
106106

@@ -180,7 +180,13 @@ function ModalComponent({
180180
onOpenChange: handleOpenChange,
181181
});
182182

183-
const handleFloatingRef = useForkRef<HTMLDivElement>(refs.setFloating, floatingRef);
183+
const handleFloatingRef = useForkRef<HTMLDivElement>(
184+
refs.setFloating,
185+
/*
186+
* TODO: Remove casting in React 19 (https://github.com/gravity-ui/uikit/issues/2537)
187+
*/
188+
floatingRef as React.Ref<HTMLDivElement>,
189+
);
184190

185191
const dismiss = useDismiss(context, {
186192
enabled: !disableOutsideClick || !disableEscapeKeyDown,

src/components/NumberInput/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function clampToNearestStepValue({
158158
}
159159

160160
export function updateCursorPosition(
161-
inputRef: React.RefObject<HTMLInputElement>,
161+
inputRef: React.RefObject<HTMLInputElement | null>,
162162
eventRawValue: string | undefined = '',
163163
computedEventValue: string | undefined = '',
164164
) {

src/components/PinInput/PinInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface PinInputProps extends DOMProps, AriaLabelingProps, QAProps, Foc
4444
note?: TextInputProps['note'];
4545
validationState?: TextInputProps['validationState'];
4646
errorMessage?: TextInputProps['errorMessage'];
47-
apiRef?: React.RefObject<PinInputApi>;
47+
apiRef?: React.RefObject<PinInputApi | null>;
4848
}
4949

5050
const b = block('pin-input');

src/components/Popup/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type PopupPlacement = AutoPlacement | Placement | Placement[];
88

99
export type PopupAnchorElement = Element | VirtualElement;
1010

11-
export type PopupAnchorRef = React.RefObject<PopupAnchorElement>;
11+
export type PopupAnchorRef = React.RefObject<PopupAnchorElement | null>;
1212

1313
type RemoveFunction<T> = T extends Function ? never : T;
1414

src/components/Select/components/SelectPopup/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type SelectPopupProps = {
99
width?: SelectProps['popupWidth'];
1010
open?: boolean;
1111
placement?: PopupPlacement;
12-
controlRef?: React.RefObject<HTMLElement>;
12+
controlRef?: React.RefObject<HTMLElement | null>;
1313
children?: React.ReactNode;
1414
className?: string;
1515
disablePortal?: boolean;

0 commit comments

Comments
 (0)