fix: submenu align (#42648)

This commit is contained in:
MadCcc 2023-05-26 17:15:03 +08:00 committed by GitHub
parent b6442fe285
commit 61924699ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 10 deletions

View File

@ -1,5 +1,4 @@
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';
@ -8,7 +7,6 @@ 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 */

View File

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

View File

@ -1,5 +1,6 @@
import { TinyColor } from '@ctrl/tinycolor';
import type { CSSObject } from '@ant-design/cssinjs'; import type { CSSObject } from '@ant-design/cssinjs';
import { TinyColor } from '@ctrl/tinycolor';
import { clearFix, resetComponent, resetIcon } from '../../style';
import { genCollapseMotion, initSlideMotion, initZoomMotion } from '../../style/motion'; import { genCollapseMotion, initSlideMotion, initZoomMotion } from '../../style/motion';
import type { FullToken, GenerateStyle, UseComponentStyleResult } from '../../theme/internal'; import type { FullToken, GenerateStyle, UseComponentStyleResult } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal'; import { genComponentStyleHook, mergeToken } from '../../theme/internal';
@ -7,7 +8,6 @@ import getHorizontalStyle from './horizontal';
import getRTLStyle from './rtl'; import getRTLStyle from './rtl';
import getThemeStyle from './theme'; import getThemeStyle from './theme';
import getVerticalStyle from './vertical'; import getVerticalStyle from './vertical';
import { clearFix, resetComponent, resetIcon } from '../../style';
/** Component only token. Which will handle additional calculation of alias token */ /** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken { export interface ComponentToken {
@ -349,11 +349,14 @@ const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
'&-popup': { '&-popup': {
position: 'absolute', position: 'absolute',
zIndex: zIndexPopup, zIndex: zIndexPopup,
background: 'transparent',
borderRadius: borderRadiusLG, borderRadius: borderRadiusLG,
boxShadow: 'none', boxShadow: 'none',
transformOrigin: '0 0', transformOrigin: '0 0',
[`&${componentCls}-submenu`]: {
background: 'transparent',
},
// https://github.com/ant-design/ant-design/issues/13955 // https://github.com/ant-design/ant-design/issues/13955
'&::before': { '&::before': {
position: 'absolute', position: 'absolute',
@ -372,6 +375,55 @@ const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
insetInlineStart: menuPanelMaskInset, insetInlineStart: menuPanelMaskInset,
}, },
[`
&-placement-leftTop,
&-placement-bottomRight,
`]: {
transformOrigin: '100% 0',
},
[`
&-placement-leftBottom,
&-placement-topRight,
`]: {
transformOrigin: '100% 100%',
},
[`
&-placement-rightBottom,
&-placement-topLeft,
`]: {
transformOrigin: '0 100%',
},
[`
&-placement-leftTop,
&-placement-leftBottom
`]: {
paddingInlineEnd: token.paddingXS,
},
[`
&-placement-rightTop,
&-placement-rightBottom
`]: {
paddingInlineStart: token.paddingXS,
},
[`
&-placement-topRight,
&-placement-topLeft
`]: {
paddingBottom: token.paddingXS,
},
[`
&-placement-bottomRight,
&-placement-bottomLeft
`]: {
paddingTop: token.paddingXS,
},
[`> ${componentCls}`]: { [`> ${componentCls}`]: {
borderRadius: borderRadiusLG, borderRadius: borderRadiusLG,

View File

@ -132,7 +132,7 @@
"rc-input": "~1.0.4", "rc-input": "~1.0.4",
"rc-input-number": "~7.4.0", "rc-input-number": "~7.4.0",
"rc-mentions": "~2.3.0", "rc-mentions": "~2.3.0",
"rc-menu": "~9.9.1", "rc-menu": "~9.9.2",
"rc-motion": "^2.7.3", "rc-motion": "^2.7.3",
"rc-notification": "~5.0.4", "rc-notification": "~5.0.4",
"rc-pagination": "~3.4.2", "rc-pagination": "~3.4.2",