Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix submenu focus #662

Closed
wants to merge 5 commits into from
Closed
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
17 changes: 9 additions & 8 deletions src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import warning from 'rc-util/lib/warning';
import * as React from 'react';
import { useImperativeHandle } from 'react';
import { flushSync } from 'react-dom';
import MenuItem from './MenuItem';
import SubMenu from './SubMenu';
import { IdContext } from './context/IdContext';
import MenuContextProvider from './context/MenuContext';
import { PathRegisterContext, PathUserContext } from './context/PathContext';
Expand All @@ -31,8 +33,6 @@ import type {
SelectInfo,
TriggerSubMenuAction,
} from './interface';
import MenuItem from './MenuItem';
import SubMenu from './SubMenu';
import { parseItems } from './utils/nodeUtil';
import { warnItemProp } from './utils/warnUtil';

Expand Down Expand Up @@ -274,9 +274,8 @@ const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
};

// >>>>> Cache & Reset open keys when inlineCollapsed changed
const [inlineCacheOpenKeys, setInlineCacheOpenKeys] = React.useState(
mergedOpenKeys,
);
const [inlineCacheOpenKeys, setInlineCacheOpenKeys] =
React.useState(mergedOpenKeys);

const mountRef = React.useRef(false);

Expand Down Expand Up @@ -352,9 +351,10 @@ const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
[registerPath, unregisterPath],
);

const pathUserContext = React.useMemo(() => ({ isSubPathKey }), [
isSubPathKey,
]);
const pathUserContext = React.useMemo(
() => ({ isSubPathKey }),
[isSubPathKey],
);

React.useEffect(() => {
refreshOverflowKeys(
Expand Down Expand Up @@ -645,6 +645,7 @@ const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
// Events
onItemClick={onInternalClick}
onOpenChange={onInternalOpenChange}
onKeyDown={onInternalKeyDown}
>
<PathUserContext.Provider value={pathUserContext}>
{container}
Expand Down
5 changes: 3 additions & 2 deletions src/SubMenu/SubMenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import classNames from 'classnames';
import * as React from 'react';
import { MenuContext } from '../context/MenuContext';

export interface SubMenuListProps
Expand All @@ -11,7 +11,7 @@ const InternalSubMenuList = (
{ className, children, ...restProps }: SubMenuListProps,
ref: React.Ref<HTMLUListElement>,
) => {
const { prefixCls, mode, rtl } = React.useContext(MenuContext);
const { prefixCls, mode, rtl, onKeyDown } = React.useContext(MenuContext);

return (
<ul
Expand All @@ -26,6 +26,7 @@ const InternalSubMenuList = (
{...restProps}
data-menu-list
ref={ref}
onKeyDown={onKeyDown}
>
{children}
</ul>
Expand Down
3 changes: 2 additions & 1 deletion src/context/MenuContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import type { CSSMotionProps } from 'rc-motion';
import useMemo from 'rc-util/lib/hooks/useMemo';
import isEqual from 'rc-util/lib/isEqual';
import * as React from 'react';
import type {
BuiltinPlacements,
MenuClickEventHandler,
Expand Down Expand Up @@ -52,6 +52,7 @@ export interface MenuContextProps {

// Function
onItemClick: MenuClickEventHandler;
onKeyDown?: React.KeyboardEventHandler<HTMLUListElement>;
onOpenChange: (key: string, open: boolean) => void;
getPopupContainer: (node: HTMLElement) => HTMLElement;
}
Expand Down
Loading