Skip to content

Commit 31ea25a

Browse files
committed
types: align legacy menu item contract
1 parent 6af2fea commit 31ea25a

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/MenuItem.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import PrivateContext from './context/PrivateContext';
99
import useActive from './hooks/useActive';
1010
import useDirectionStyle from './hooks/useDirectionStyle';
1111
import Icon from './Icon';
12-
import type { MenuInfo, ItemData, MenuItemType } from './interface';
12+
import type { LegacyMenuItemInfo, MenuInfo, ItemData, MenuItemType } from './interface';
1313
import { warnItemProp } from './utils/warnUtil';
1414

1515
export interface MenuItemProps
@@ -44,9 +44,8 @@ type LegacyMenuItemProps = Omit<React.ComponentProps<typeof Overflow.Item>, 'tit
4444
onTitleClick?: () => void;
4545
};
4646

47-
type LegacyMenuItemHandle = {
47+
type LegacyMenuItemHandle = Omit<LegacyMenuItemInfo, 'props'> & {
4848
props: LegacyMenuItemProps;
49-
element: HTMLLIElement | null;
5049
};
5150

5251
// Keep exposing a legacy-compatible handle for deprecated `info.item`.
@@ -178,7 +177,7 @@ const InternalMenuItem = React.forwardRef((props: MenuItemProps, ref: React.Ref<
178177
key: eventKey,
179178
// Note: For legacy code is reversed which not like other antd component
180179
keyPath: [...connectedKeys].reverse(),
181-
item: legacyMenuItemRef.current as unknown as React.ReactInstance,
180+
item: legacyMenuItemRef.current,
182181
domEvent: e,
183182
itemData: propsItemData || itemData,
184183
};

src/interface.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ export interface RenderIconInfo {
103103

104104
export type RenderIconType = React.ReactNode | ((props: RenderIconInfo) => React.ReactNode);
105105

106+
/**
107+
* @deprecated Compatibility handle for deprecated `info.item`.
108+
* Avoid relying on this shape since it will be removed in a future major version.
109+
*/
110+
export interface LegacyMenuItemInfo {
111+
props: {
112+
eventKey?: string;
113+
[key: string]: unknown;
114+
};
115+
element: HTMLLIElement | null;
116+
}
117+
106118
export interface MenuInfo {
107119
key: string;
108120
keyPath: string[];
109121
/** @deprecated This will not support in future. You should avoid to use this */
110-
item: React.ReactInstance;
122+
item: LegacyMenuItemInfo;
111123
domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
112124
itemData: ItemData;
113125
}

src/utils/warnUtil.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { warning } from '@rc-component/util';
2+
import type { LegacyMenuItemInfo } from '../interface';
23

34
/**
45
* `onClick` still exposes deprecated `info.item` for backward compatibility.
56
* Keep warning since function components no longer provide a React node instance.
67
*/
7-
export function warnItemProp<T extends { item: React.ReactInstance }>({ item, ...restInfo }: T): T {
8+
export function warnItemProp<T extends { item: LegacyMenuItemInfo }>({ item, ...restInfo }: T): T {
89
Object.defineProperty(restInfo, 'item', {
910
get: () => {
1011
warning(

0 commit comments

Comments
 (0)