Browse Source

style: fix SubMenu offset (#38645)

pull/38658/head
afc163 2 years ago
committed by GitHub
parent
commit
85b171a6e2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/menu/MenuContext.tsx
  2. 6
      components/menu/SubMenu.tsx
  3. 1
      components/menu/menu.tsx

2
components/menu/MenuContext.tsx

@ -1,4 +1,5 @@
import { createContext } from 'react'; import { createContext } from 'react';
import type { MenuProps } from 'rc-menu';
import type { DirectionType } from '../config-provider'; import type { DirectionType } from '../config-provider';
export type MenuTheme = 'light' | 'dark'; export type MenuTheme = 'light' | 'dark';
@ -7,6 +8,7 @@ export interface MenuContextProps {
prefixCls: string; prefixCls: string;
inlineCollapsed: boolean; inlineCollapsed: boolean;
direction?: DirectionType; direction?: DirectionType;
mode?: MenuProps['mode'];
theme?: MenuTheme; theme?: MenuTheme;
firstLevel: boolean; firstLevel: boolean;
/** @internal Safe to remove */ /** @internal Safe to remove */

6
components/menu/SubMenu.tsx

@ -30,7 +30,7 @@ export interface SubMenuProps {
function SubMenu(props: SubMenuProps) { function SubMenu(props: SubMenuProps) {
const { popupClassName, icon, title, theme: customTheme } = props; const { popupClassName, icon, title, theme: customTheme } = props;
const context = React.useContext(MenuContext); const context = React.useContext(MenuContext);
const { prefixCls, inlineCollapsed, theme: contextTheme } = context; const { prefixCls, inlineCollapsed, theme: contextTheme, mode } = context;
const parentPath = useFullPath(); const parentPath = useFullPath();
@ -68,10 +68,12 @@ function SubMenu(props: SubMenuProps) {
[context], [context],
); );
const popupOffset = mode === 'horizontal' ? [0, 8] : [10, 0];
return ( return (
<MenuContext.Provider value={contextValue}> <MenuContext.Provider value={contextValue}>
<RcSubMenu <RcSubMenu
popupOffset={[10, 0]} popupOffset={popupOffset}
{...omit(props, ['icon'])} {...omit(props, ['icon'])}
title={titleNode} title={titleNode}
popupClassName={classNames( popupClassName={classNames(

1
components/menu/menu.tsx

@ -138,6 +138,7 @@ const InternalMenu = forwardRef<RcMenuRef, InternalMenuProps>((props, ref) => {
direction, direction,
firstLevel: true, firstLevel: true,
theme, theme,
mode: mergedMode,
disableMenuItemTitleTooltip: _internalDisableMenuItemTitleTooltip, disableMenuItemTitleTooltip: _internalDisableMenuItemTitleTooltip,
}), }),
[prefixCls, mergedInlineCollapsed, direction, _internalDisableMenuItemTitleTooltip, theme], [prefixCls, mergedInlineCollapsed, direction, _internalDisableMenuItemTitleTooltip, theme],

Loading…
Cancel
Save