diff --git a/components/menu/MenuDivider.tsx b/components/menu/MenuDivider.tsx new file mode 100644 index 0000000000..c94b3868fb --- /dev/null +++ b/components/menu/MenuDivider.tsx @@ -0,0 +1,32 @@ +import * as React from 'react'; +import classNames from 'classnames'; +import { Divider } from 'rc-menu'; +import { ConfigContext } from '../config-provider'; + +export interface MenuDividerProps extends React.HTMLAttributes { + className?: string; + prefixCls?: string; + style?: React.CSSProperties; + dashed?: boolean; +} + +const MenuDivider: React.FC = ({ + prefixCls: customizePrefixCls, + className, + dashed, + ...restProps +}) => { + const { getPrefixCls } = React.useContext(ConfigContext); + + const prefixCls = getPrefixCls('menu', customizePrefixCls); + const classString = classNames( + { + [`${prefixCls}-item-divider-dashed`]: !!dashed, + }, + className, + ); + + return ; +}; + +export default MenuDivider; diff --git a/components/menu/__tests__/index.test.js b/components/menu/__tests__/index.test.js index 55be80d847..9c42eda228 100644 --- a/components/menu/__tests__/index.test.js +++ b/components/menu/__tests__/index.test.js @@ -821,4 +821,25 @@ describe('Menu', () => { expect(wrapper.find('.ant-menu-inline-collapsed-noicon').first().text()).toEqual('L'); expect(wrapper.find('.ant-menu-inline-collapsed-noicon').last().text()).toEqual('B'); }); + + it('divider should show', () => { + const wrapper = mount( + + + Option 1 + + + + Option 2 + + + + Option 3 + + , + ); + + expect(wrapper.find('li.ant-menu-item-divider').length).toBe(2); + expect(wrapper.find('li.ant-menu-item-divider-dashed').length).toBe(1); + }); }); diff --git a/components/menu/demo/vertical.md b/components/menu/demo/vertical.md index 0ef0bbcb83..13bc1fb9ea 100755 --- a/components/menu/demo/vertical.md +++ b/components/menu/demo/vertical.md @@ -30,7 +30,7 @@ ReactDOM.render( Option 1 Option 2 - + Option 3 Option 4 diff --git a/components/menu/index.en-US.md b/components/menu/index.en-US.md index b72920eef0..885c3de1b7 100644 --- a/components/menu/index.en-US.md +++ b/components/menu/index.en-US.md @@ -111,6 +111,10 @@ More layouts with navigation: [Layout](/components/layout). Divider line in between menu items, only used in vertical popup Menu or Dropdown Menu. +| Param | Description | Type | Default value | Version | +| ------ | ---------------------- | ------- | ------------- | ------- | +| dashed | Whether line is dashed | boolean | false | 4.17.0 | + ## FAQ ### Why Menu children node will render twice? diff --git a/components/menu/index.tsx b/components/menu/index.tsx index bd43a54d55..716b8f4acd 100644 --- a/components/menu/index.tsx +++ b/components/menu/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import RcMenu, { Divider, ItemGroup, MenuProps as RcMenuProps } from 'rc-menu'; +import RcMenu, { ItemGroup, MenuProps as RcMenuProps } from 'rc-menu'; import classNames from 'classnames'; import omit from 'rc-util/lib/omit'; import EllipsisOutlined from '@ant-design/icons/EllipsisOutlined'; @@ -11,6 +11,9 @@ import { SiderContext, SiderContextProps } from '../layout/Sider'; import collapseMotion from '../_util/motion'; import { cloneElement } from '../_util/reactNode'; import MenuContext, { MenuTheme } from './MenuContext'; +import MenuDivider from './MenuDivider'; + +export { MenuDividerProps } from './MenuDivider'; export { MenuItemGroupProps } from 'rc-menu'; @@ -113,7 +116,7 @@ class InternalMenu extends React.Component { // We should keep this as ref-able class Menu extends React.Component { - static Divider = Divider; + static Divider = MenuDivider; static Item = Item; diff --git a/components/menu/index.zh-CN.md b/components/menu/index.zh-CN.md index 4b369ac460..7df6588e54 100644 --- a/components/menu/index.zh-CN.md +++ b/components/menu/index.zh-CN.md @@ -112,6 +112,10 @@ cover: https://gw.alipayobjects.com/zos/alicdn/3XZcjGpvK/Menu.svg 菜单项分割线,只用在弹出菜单内。 +| 参数 | 说明 | 类型 | 默认值 | 版本 | +| ------ | -------- | ------- | ------ | ------ | +| dashed | 是否虚线 | boolean | false | 4.17.0 | + ## FAQ ### 为何 Menu 的子元素会渲染两次? diff --git a/components/menu/style/index.less b/components/menu/style/index.less index e787f07e65..01a6f99398 100644 --- a/components/menu/style/index.less +++ b/components/menu/style/index.less @@ -118,10 +118,15 @@ } &-item-divider { - height: 1px; overflow: hidden; line-height: 0; - background-color: @border-color-split; + border-color: @border-color-split; + border-style: solid; + border-width: 1px 0 0; + } + + &-item-divider-dashed { + border-style: dashed; } &-horizontal &-item, @@ -238,12 +243,8 @@ } & > &-item-divider { - height: 1px; margin: 1px 0; padding: 0; - overflow: hidden; - line-height: 0; - background-color: @border-color-split; } &-submenu {