Skip to content

Commit 84b6467

Browse files
fix(Menu): narrow event type
1 parent fd41d3c commit 84b6467

File tree

12 files changed

+80
-25
lines changed

12 files changed

+80
-25
lines changed

packages/react-core/src/components/Menu/Menu.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ export interface MenuProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'r
4040
/** @beta Array of menus that are drilled in */
4141
drilledInMenus?: string[];
4242
/** @beta Callback for drilling into a submenu */
43-
onDrillIn?: (event: any, fromItemId: string, toItemId: string, itemId: string) => void;
43+
onDrillIn?: (
44+
event: React.KeyboardEvent | React.MouseEvent,
45+
fromItemId: string,
46+
toItemId: string,
47+
itemId: string
48+
) => void;
4449
/** @beta Callback for drilling out of a submenu */
45-
onDrillOut?: (event: any, toItemId: string, itemId: string) => void;
50+
onDrillOut?: (event: React.KeyboardEvent | React.MouseEvent, toItemId: string, itemId: string) => void;
4651
/** @beta Callback for collecting menu heights */
4752
onGetMenuHeight?: (menuId: string, height: number) => void;
4853
/** @beta ID of parent menu for drilldown menus */

packages/react-core/src/components/Menu/MenuContext.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ export const MenuContext = React.createContext<{
99
selected?: any | any[];
1010
drilldownItemPath?: string[];
1111
drilledInMenus?: string[];
12-
onDrillIn?: (event: any, fromItemId: string, toItemId: string, itemId: string) => void;
13-
onDrillOut?: (event: any, toItemId: string, itemId: string) => void;
12+
onDrillIn?: (
13+
event: React.KeyboardEvent | React.MouseEvent,
14+
fromItemId: string,
15+
toItemId: string,
16+
itemId: string
17+
) => void;
18+
onDrillOut?: (event: React.KeyboardEvent | React.MouseEvent, toItemId: string, itemId: string) => void;
1419
onGetMenuHeight?: (menuId: string, height: number) => void;
1520
flyoutRef?: React.Ref<HTMLLIElement>;
1621
setFlyoutRef?: (ref: React.Ref<HTMLLIElement>) => void;

packages/react-core/src/components/Menu/MenuItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
224224
onClick && onClick(event);
225225
};
226226
const _isOnPath = (isOnPath && isOnPath) || (drilldownItemPath && drilldownItemPath.includes(itemId)) || false;
227-
let drill: (event: any) => void;
227+
let drill: (event: React.KeyboardEvent | React.MouseEvent) => void;
228228
if (direction) {
229229
if (direction === 'down') {
230-
drill = (event: any) =>
230+
drill = event =>
231231
onDrillIn &&
232232
onDrillIn(
233233
event,
@@ -319,7 +319,7 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
319319
{...(!hasCheck && !flyoutMenu && { role: 'menuitem' })}
320320
ref={innerRef}
321321
{...(!hasCheck && {
322-
onClick: (event: any) => {
322+
onClick: (event: React.KeyboardEvent | React.MouseEvent) => {
323323
onItemSelect(event, onSelect);
324324
drill && drill(event);
325325
flyoutMenu && handleFlyout(event);

packages/react-core/src/components/Menu/examples/MenuFilterDrilldown.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ export const MenuWithDrilldown: React.FunctionComponent = () => {
1616
const [menuHeights, setMenuHeights] = React.useState<any>({});
1717
const [activeMenu, setActiveMenu] = React.useState<string>('filter_drilldown-rootMenu');
1818

19-
const drillIn = (_event: any, fromMenuId: string, toMenuId: string, pathId: string) => {
19+
const drillIn = (
20+
_event: React.KeyboardEvent | React.MouseEvent,
21+
fromMenuId: string,
22+
toMenuId: string,
23+
pathId: string
24+
) => {
2025
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
2126
setDrilldownPath([...drilldownPath, pathId]);
2227
setActiveMenu(toMenuId);
2328
};
2429

25-
const drillOut = (_event: any, toMenuId: string) => {
30+
const drillOut = (_event: React.KeyboardEvent | React.MouseEvent, toMenuId: string) => {
2631
const menuDrilledInSansLast = menuDrilledIn.slice(0, menuDrilledIn.length - 1);
2732
const pathSansLast = drilldownPath.slice(0, drilldownPath.length - 1);
2833
setMenuDrilledIn(menuDrilledInSansLast);

packages/react-core/src/components/Menu/examples/MenuWithDrilldown.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ export const MenuWithDrilldown: React.FunctionComponent = () => {
1111
const [menuHeights, setMenuHeights] = React.useState<any>({});
1212
const [activeMenu, setActiveMenu] = React.useState<string>('drilldown-rootMenu');
1313

14-
const drillIn = (_event: any, fromMenuId: string, toMenuId: string, pathId: string) => {
14+
const drillIn = (
15+
_event: React.KeyboardEvent | React.MouseEvent,
16+
fromMenuId: string,
17+
toMenuId: string,
18+
pathId: string
19+
) => {
1520
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
1621
setDrilldownPath([...drilldownPath, pathId]);
1722
setActiveMenu(toMenuId);
1823
};
1924

20-
const drillOut = (_event: any, toMenuId: string) => {
25+
const drillOut = (_event: React.KeyboardEvent | React.MouseEvent, toMenuId: string) => {
2126
const menuDrilledInSansLast = menuDrilledIn.slice(0, menuDrilledIn.length - 1);
2227
const pathSansLast = drilldownPath.slice(0, drilldownPath.length - 1);
2328
setMenuDrilledIn(menuDrilledInSansLast);

packages/react-core/src/components/Menu/examples/MenuWithDrilldownBreadcrumbs.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
5252
setWithMaxMenuHeight(checked);
5353
};
5454

55-
const drillOut = (_event: any, toMenuId: string, fromPathId: string, breadcrumb: JSX.Element | null) => {
55+
const drillOut = (
56+
_event: React.KeyboardEvent<Element> | MouseEvent | React.MouseEvent<any, MouseEvent>,
57+
toMenuId: string,
58+
fromPathId: string,
59+
breadcrumb: JSX.Element | null
60+
) => {
5661
setMenuDrilledIn(prevMenuDrilledIn => {
5762
const indexOfMenuId = prevMenuDrilledIn.indexOf(toMenuId);
5863
return prevMenuDrilledIn.slice(0, indexOfMenuId);
@@ -71,7 +76,12 @@ export const MenuWithDrilldownBreadcrumbs: React.FunctionComponent = () => {
7176
}
7277
};
7378

74-
const drillIn = (_event: any, fromMenuId: string, toMenuId: string, pathId: string) => {
79+
const drillIn = (
80+
_event: React.KeyboardEvent | React.MouseEvent,
81+
fromMenuId: string,
82+
toMenuId: string,
83+
pathId: string
84+
) => {
7585
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
7686
setDrilldownPath([...drilldownPath, pathId]);
7787
setActiveMenu(toMenuId);

packages/react-core/src/components/Menu/examples/MenuWithDrilldownInitialState.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ export const MenuDrilldownInitialState: React.FunctionComponent = () => {
1414
const [menuHeights, setMenuHeights] = React.useState<any>({ 'initial-state-rootMenu': 216 }); // The root menu height must be defined when starting from a drilled in state
1515
const [activeMenu, setActiveMenu] = React.useState<string>('initial-state-drilldownMenuStartGrouping');
1616

17-
const drillIn = (_event: any, fromMenuId: string, toMenuId: string, pathId: string) => {
17+
const drillIn = (
18+
_event: React.KeyboardEvent | React.MouseEvent,
19+
fromMenuId: string,
20+
toMenuId: string,
21+
pathId: string
22+
) => {
1823
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
1924
setDrilldownPath([...drilldownPath, pathId]);
2025
setActiveMenu(toMenuId);
2126
};
2227

23-
const drillOut = (_event: any, toMenuId: string) => {
28+
const drillOut = (_event: React.KeyboardEvent | React.MouseEvent, toMenuId: string) => {
2429
const menuDrilledInSansLast = menuDrilledIn.slice(0, menuDrilledIn.length - 1);
2530
const pathSansLast = drilldownPath.slice(0, drilldownPath.length - 1);
2631
setMenuDrilledIn(menuDrilledInSansLast);

packages/react-core/src/components/Menu/examples/MenuWithDrilldownSubmenuFunctions.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ export const MenuWithDrilldownSubmenuFunctions: React.FunctionComponent = () =>
1111
const [menuHeights, setMenuHeights] = React.useState<any>({});
1212
const [activeMenu, setActiveMenu] = React.useState<string>('functions-rootMenu');
1313

14-
const drillIn = (_event: any, fromMenuId: string, toMenuId: string, pathId: string) => {
14+
const drillIn = (
15+
_event: React.KeyboardEvent | React.MouseEvent,
16+
fromMenuId: string,
17+
toMenuId: string,
18+
pathId: string
19+
) => {
1520
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
1621
setDrilldownPath([...drilldownPath, pathId]);
1722
setActiveMenu(toMenuId);
1823
};
1924

20-
const drillOut = (_event: any, toMenuId: string) => {
25+
const drillOut = (_event: React.KeyboardEvent | React.MouseEvent, toMenuId: string) => {
2126
const menuDrilledInSansLast = menuDrilledIn.slice(0, menuDrilledIn.length - 1);
2227
const pathSansLast = drilldownPath.slice(0, drilldownPath.length - 1);
2328
setMenuDrilledIn(menuDrilledInSansLast);

packages/react-core/src/components/Nav/examples/NavDrilldown.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ export const NavigationDrilldown: React.FunctionComponent = () => {
5151
const [menuHeights, setMenuHeights] = React.useState<MenuHeights>({});
5252
const [activeMenu, setActiveMenu] = React.useState('rootMenu');
5353

54-
const onDrillIn = (_event: any, fromItemId: string, toItemId: string, itemId: string) => {
54+
const onDrillIn = (
55+
_event: React.KeyboardEvent | React.MouseEvent,
56+
fromItemId: string,
57+
toItemId: string,
58+
itemId: string
59+
) => {
5560
setMenuDrilledIn(prevMenuDrilledIn => [...prevMenuDrilledIn, fromItemId]);
5661
setDrilldownPath(prevDrilldownPath => [...prevDrilldownPath, itemId]);
5762
setActiveMenu(toItemId);
5863
};
5964

60-
const onDrillOut = (_event: any, toItemId: string, _itemId: string) => {
65+
const onDrillOut = (_event: React.KeyboardEvent | React.MouseEvent, toItemId: string, _itemId: string) => {
6166
setMenuDrilledIn(prevMenuDrilledIn => prevMenuDrilledIn.slice(0, prevMenuDrilledIn.length - 1));
6267
setDrilldownPath(prevDrilldownPath => prevDrilldownPath.slice(0, prevDrilldownPath.length - 1));
6368
setActiveMenu(toItemId);

packages/react-core/src/demos/ComposableMenu/examples/ComposableDrilldownMenu.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ export const ComposableDrilldownMenu: React.FunctionComponent = () => {
6666
setActiveMenu('rootMenu');
6767
};
6868

69-
const drillIn = (_event: any, fromMenuId: string, toMenuId: string, pathId: string) => {
69+
const drillIn = (
70+
_event: React.KeyboardEvent | React.MouseEvent,
71+
fromMenuId: string,
72+
toMenuId: string,
73+
pathId: string
74+
) => {
7075
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
7176
setDrilldownPath([...drilldownPath, pathId]);
7277
setActiveMenu(toMenuId);
7378
};
7479

75-
const drillOut = (_event: any, toMenuId: string) => {
80+
const drillOut = (_event: React.KeyboardEvent | React.MouseEvent, toMenuId: string) => {
7681
setMenuDrilledIn(menuDrilledIn.slice(0, menuDrilledIn.length - 1));
7782
setDrilldownPath(drilldownPath.slice(0, drilldownPath.length - 1));
7883
setActiveMenu(toMenuId);

0 commit comments

Comments
 (0)