diff --git a/components/dropdown/__tests__/__snapshots__/demo.test.js.snap b/components/dropdown/__tests__/__snapshots__/demo.test.js.snap index d1fee32357..a3246ec04a 100644 --- a/components/dropdown/__tests__/__snapshots__/demo.test.js.snap +++ b/components/dropdown/__tests__/__snapshots__/demo.test.js.snap @@ -1,5 +1,59 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`renders ./components/dropdown/demo/arrow.md correctly 1`] = ` +Array [ + , + , + , +
, + , + , + , +] +`; + exports[`renders ./components/dropdown/demo/basic.md correctly 1`] = ` + + + 1st menu item + + + + + 2nd menu item + + + + + 3rd menu item + + + +); + +ReactDOM.render( + <> + + + + + + + + + +
+ + + + + + + + + + , + mountNode, +); +``` + +```css +#components-dropdown-demo-arrow .ant-btn { + margin-right: 8px; + margin-bottom: 8px; +} +.ant-row-rtl #components-dropdown-demo-arrow .ant-btn { + margin-right: 0; + margin-bottom: 8px; + margin-left: 8px; +} +``` diff --git a/components/dropdown/dropdown.tsx b/components/dropdown/dropdown.tsx index 7c768577b5..5b972add30 100644 --- a/components/dropdown/dropdown.tsx +++ b/components/dropdown/dropdown.tsx @@ -35,6 +35,7 @@ type Align = { }; export interface DropDownProps { + arrow?: boolean; trigger?: ('click' | 'hover' | 'contextMenu')[]; overlay: React.ReactElement | OverlayFunc; onVisibleChange?: (visible: boolean) => void; @@ -130,6 +131,7 @@ const Dropdown: DropdownInterface = props => { }; const { + arrow, prefixCls: customizePrefixCls, children, trigger, @@ -160,6 +162,7 @@ const Dropdown: DropdownInterface = props => { return ( document.body` | | | overlay | The dropdown menu | [Menu](/components/menu) \| () => Menu | - | | diff --git a/components/dropdown/index.zh-CN.md b/components/dropdown/index.zh-CN.md index 7046915f86..11177138e0 100644 --- a/components/dropdown/index.zh-CN.md +++ b/components/dropdown/index.zh-CN.md @@ -21,6 +21,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/TIIiKrsQT/Dropdown.svg | 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | +| arrow | 下拉框箭头是否显示 | boolean | `false` | | | disabled | 菜单是否禁用 | boolean | - | | | getPopupContainer | 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。[示例](https://codepen.io/afc163/pen/zEjNOy?editors=0010) | Function(triggerNode) | `() => document.body` | | | overlay | 菜单 | [Menu](/components/menu) \| () => Menu | - | | diff --git a/components/dropdown/style/index.less b/components/dropdown/style/index.less index cb47c6a945..b977cde04f 100644 --- a/components/dropdown/style/index.less +++ b/components/dropdown/style/index.less @@ -47,6 +47,76 @@ display: none; } + // Offset the popover to account for the dropdown arrow + &-show-arrow&-placement-topCenter, + &-show-arrow&-placement-topLeft, + &-show-arrow&-placement-topRight { + padding-bottom: @popover-distance; + } + + &-show-arrow&-placement-bottomCenter, + &-show-arrow&-placement-bottomLeft, + &-show-arrow&-placement-bottomRight { + padding-top: @popover-distance; + } + + // Arrows + // .popover-arrow is outer, .popover-arrow:after is inner + + &-arrow { + position: absolute; + z-index: 1; // lift it up so the menu wouldn't cask shadow on it + display: block; + width: sqrt(@popover-arrow-width * @popover-arrow-width * 2); + height: sqrt(@popover-arrow-width * @popover-arrow-width * 2); + background: transparent; + border-style: solid; + border-width: sqrt(@popover-arrow-width * @popover-arrow-width * 2) / 2; + transform: rotate(45deg); + } + + &-placement-topCenter > &-arrow, + &-placement-topLeft > &-arrow, + &-placement-topRight > &-arrow { + bottom: @popover-distance - @popover-arrow-width + 2.2px; + border-top-color: transparent; + border-right-color: @popover-bg; + border-bottom-color: @popover-bg; + border-left-color: transparent; + box-shadow: 3px 3px 7px fade(@black, 7%); + } + &-placement-topCenter > &-arrow { + left: 50%; + transform: translateX(-50%) rotate(45deg); + } + &-placement-topLeft > &-arrow { + left: 16px; + } + &-placement-topRight > &-arrow { + right: 16px; + } + + &-placement-bottomCenter > &-arrow, + &-placement-bottomLeft > &-arrow, + &-placement-bottomRight > &-arrow { + top: @popover-distance - @popover-arrow-width + 2px; + border-top-color: @popover-bg; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: @popover-bg; + box-shadow: -2px -2px 5px fade(@black, 6%); + } + &-placement-bottomCenter > &-arrow { + left: 50%; + transform: translateX(-50%) rotate(45deg); + } + &-placement-bottomLeft > &-arrow { + left: 16px; + } + &-placement-bottomRight > &-arrow { + right: 16px; + } + &-menu { position: relative; margin: 0;