Skip to content

Commit bd47231

Browse files
bsunderhusmainframev
authored andcommitted
chore: redeclare RefAttributes instead of supporting LegacyRef
1 parent 35ff00f commit bd47231

File tree

6 files changed

+48
-28
lines changed

6 files changed

+48
-28
lines changed

packages/react-components/react-table/library/src/components/DataGridBody/DataGridBody.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';
1010
* DataGridBody component
1111
*/
1212
export const DataGridBody: ForwardRefComponent<DataGridBodyProps> &
13-
(<TItem>(props: DataGridBodyProps<TItem>) => JSX.Element) = React.forwardRef((props, ref) => {
14-
const state = useDataGridBody_unstable(props, ref);
13+
(<TItem>(props: DataGridBodyProps<TItem>) => JSX.Element) = React.forwardRef<HTMLElement, DataGridBodyProps>(
14+
(props, ref) => {
15+
const state = useDataGridBody_unstable(props, ref);
1516

16-
useDataGridBodyStyles_unstable(state);
17+
useDataGridBodyStyles_unstable(state);
1718

18-
useCustomStyleHook_unstable('useDataGridBodyStyles_unstable')(state);
19+
useCustomStyleHook_unstable('useDataGridBodyStyles_unstable')(state);
1920

20-
return renderDataGridBody_unstable(state);
21-
}) as ForwardRefComponent<DataGridBodyProps> & (<TItem>(props: DataGridBodyProps<TItem>) => JSX.Element);
21+
return renderDataGridBody_unstable(state);
22+
},
23+
) as ForwardRefComponent<DataGridBodyProps> & (<TItem>(props: DataGridBodyProps<TItem>) => JSX.Element);
2224

2325
DataGridBody.displayName = 'DataGridBody';

packages/react-components/react-table/library/src/components/DataGridRow/DataGridRow.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';
1010
* DataGridRow component
1111
*/
1212
export const DataGridRow: ForwardRefComponent<DataGridRowProps> &
13-
(<TItem>(props: DataGridRowProps<TItem>) => JSX.Element) = React.forwardRef((props, ref) => {
14-
const state = useDataGridRow_unstable(props, ref);
13+
(<TItem>(props: DataGridRowProps<TItem>) => JSX.Element) = React.forwardRef<HTMLElement, DataGridRowProps>(
14+
(props, ref) => {
15+
const state = useDataGridRow_unstable(props, ref);
1516

16-
useDataGridRowStyles_unstable(state);
17+
useDataGridRowStyles_unstable(state);
1718

18-
useCustomStyleHook_unstable('useDataGridRowStyles_unstable')(state);
19+
useCustomStyleHook_unstable('useDataGridRowStyles_unstable')(state);
1920

20-
return renderDataGridRow_unstable(state);
21-
}) as ForwardRefComponent<DataGridRowProps> & (<TItem>(props: DataGridRowProps<TItem>) => JSX.Element);
21+
return renderDataGridRow_unstable(state);
22+
},
23+
) as ForwardRefComponent<DataGridRowProps> & (<TItem>(props: DataGridRowProps<TItem>) => JSX.Element);
2224

2325
DataGridRow.displayName = 'DataGridRow';

packages/react-components/react-utilities/etc/react-utilities.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export type FluentTriggerComponent = {
6363
};
6464

6565
// @public
66-
export type ForwardRefComponent<Props> = FunctionComponent<Props & React_2.RefAttributes<InferredElementRefType<Props>>>;
66+
export type ForwardRefComponent<Props> = NamedExoticComponent<Props & RefAttributes<InferredElementRefType<Props>>>;
6767

6868
// @public
6969
export function getEventClientCoords(event: TouchOrMouseEvent): {
@@ -359,7 +359,7 @@ export const useIsomorphicLayoutEffect: typeof React_2.useEffect;
359359
export function useIsSSR(): boolean;
360360

361361
// @public
362-
export function useMergedRefs<T>(...refs: ReactRefCompat<T>[]): RefObjectFunction<T>;
362+
export function useMergedRefs<T>(...refs: (React_2.Ref<T> | undefined)[]): RefObjectFunction<T>;
363363

364364
// @internal (undocumented)
365365
export type UseOnClickOrScrollOutsideOptions = {

packages/react-components/react-utilities/src/compose/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constan
33
import {
44
ComponentType,
55
FunctionComponent,
6+
NamedExoticComponent,
67
PropsWithoutChildren,
78
PropsWithoutRef,
89
ReactNode,
10+
RefAttributes,
911
ReplaceNullWithUndefined,
1012
} from '../utils/types';
1113

@@ -233,7 +235,7 @@ export type InferredElementRefType<Props> = ObscureEventName extends keyof Props
233235
*
234236
* Note: {@link React.RefAttributes} is {@link https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/69756 | leaking string references} into forwardRef components, forwardRef component do not support string refs.
235237
*/
236-
export type ForwardRefComponent<Props> = FunctionComponent<Props & React.RefAttributes<InferredElementRefType<Props>>>;
238+
export type ForwardRefComponent<Props> = NamedExoticComponent<Props & RefAttributes<InferredElementRefType<Props>>>;
237239

238240
/**
239241
* Helper type to correctly define the slot class names object.

packages/react-components/react-utilities/src/hooks/useMergedRefs.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,14 @@ export type RefObjectFunction<T> = React.RefObject<T> & ((value: T | null) => vo
99
/** @internal */
1010
type MutableRefObjectFunction<T> = React.MutableRefObject<T | null> & ((value: T | null) => void);
1111

12-
/**
13-
* This type is used to support both React 17 and React 18.
14-
*
15-
* In React 17, this is equivalent to {@link React.Ref} | undefined,
16-
* but in React 18, this is equivalent to {@link React.LegacyRef} | undefined.
17-
*
18-
* We have to support both types as {@link React.RefAttributes} is used in component creation that are
19-
* using {@link React.forwardRef} method, which includes the majority of Fluent UI components.
20-
*/
21-
type ReactRefCompat<T> = React.RefAttributes<T>['ref'];
22-
2312
/**
2413
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
2514
* updates all provided refs
2615
* @param refs - Refs to collectively update with one ref value.
2716
* @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
2817
*/
2918
// LegacyRef is actually not supported, but in React v18 types this is leaking directly from forwardRef component declaration
30-
export function useMergedRefs<T>(...refs: ReactRefCompat<T>[]): RefObjectFunction<T> {
19+
export function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {
3120
'use no memo';
3221

3322
const mergedCallback = React.useCallback(

packages/react-components/react-utilities/src/utils/types.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ import * as React from 'react';
2323
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2424
export type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Omit<T, K> : T;
2525

26+
/**
27+
* @public
28+
*
29+
* Helper type that works similar to Pick,
30+
* but when modifying an union type it will distribute the picking to all the union members.
31+
*
32+
* See {@link https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types} for more information
33+
*/
34+
export type DistributivePick<T, K> = T extends unknown ? Pick<T, K & keyof T> : never;
35+
2636
/**
2737
* Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
2838
*/
@@ -63,10 +73,25 @@ export type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
6373
export interface FunctionComponent<P> {
6474
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6575
(props: P): any;
66-
defaultProps?: Partial<P>;
6776
displayName?: string;
6877
}
6978

79+
export type FC<P> = FunctionComponent<P>;
80+
81+
export interface ExoticComponent<P> {
82+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
83+
(props: P): any;
84+
$$typeof: symbol;
85+
}
86+
87+
export interface NamedExoticComponent<P> extends ExoticComponent<P> {
88+
displayName?: string;
89+
}
90+
91+
export interface RefAttributes<T> extends React.Attributes {
92+
ref?: React.Ref<T> | undefined;
93+
}
94+
7095
/**
7196
* @internal
7297
* **THIS TYPE IS INTERNAL AND SHOULD NEVER BE EXPOSED**

0 commit comments

Comments
 (0)