Skip to content

Commit 8eaf6da

Browse files
committed
feat: dropdown add overlayClassName overlayStyle,
1 parent 9252b65 commit 8eaf6da

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

components/dropdown/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports[`renders ./components/dropdown/demo/dropdown-button.md correctly 1`] = `
1414
<div class="ant-btn-group ant-dropdown-button"><button type="button" class="ant-btn ant-btn-default"><span>Dropdown</span></button><button type="button" class="ant-btn ant-btn-default ant-dropdown-trigger"><i class="anticon anticon-ellipsis"><svg viewBox="64 64 896 896" data-icon="ellipsis" width="1em" height="1em" fill="currentColor" aria-hidden="true" class="">
1515
<path d="M176 511a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm280 0a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm280 0a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path>
1616
</svg></i></button></div>
17-
<div class="ant-btn-group ant-dropdown-button" style="margin-left: 8px;"><button type="button" disabled="disabled" class="ant-btn ant-btn-default"><span>Dropdown</span></button><button type="button" class="ant-btn ant-btn-default ant-dropdown-trigger"><i class="anticon anticon-ellipsis"><svg viewBox="64 64 896 896" data-icon="ellipsis" width="1em" height="1em" fill="currentColor" aria-hidden="true" class="">
17+
<div class="ant-btn-group ant-dropdown-button" style="margin-left: 8px;"><button disabled="disabled" type="button" class="ant-btn ant-btn-default"><span>Dropdown</span></button><button type="button" class="ant-btn ant-btn-default ant-dropdown-trigger"><i class="anticon anticon-ellipsis"><svg viewBox="64 64 896 896" data-icon="ellipsis" width="1em" height="1em" fill="currentColor" aria-hidden="true" class="">
1818
<path d="M176 511a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm280 0a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm280 0a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path>
1919
</svg></i></button></div> <button type="button" class="ant-btn ant-btn-default ant-dropdown-trigger" style="margin-left: 8px;">
2020
Button <i class="anticon anticon-down"><svg viewBox="64 64 896 896" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true" class="">

components/dropdown/__tests__/dropdown-button.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from '@vue/test-utils'
22
import Dropdown from '..'
3+
import Menu from '../../menu'
34

45
describe('DropdownButton', () => {
56
it('pass appropriate props to Dropdown', () => {
@@ -26,7 +27,17 @@ describe('DropdownButton', () => {
2627
})
2728

2829
it('don\'t pass visible to Dropdown if it\'s not exits', () => {
29-
const wrapper = mount(Dropdown.Button)
30+
const wrapper = mount({
31+
render () {
32+
return (
33+
<Dropdown.Button
34+
overlay={<Menu>
35+
<Menu.Item>foo</Menu.Item>
36+
</Menu>}
37+
/>
38+
)
39+
},
40+
})
3041
const dropdownProps = wrapper.find({ name: 'ADropdown' }).props()
3142

3243
expect('visible' in dropdownProps).toBe(false)

components/dropdown/dropdown-button.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@ export default {
3434
prop: 'visible',
3535
event: 'visibleChange',
3636
},
37+
inject: {
38+
configProvider: { default: {}},
39+
},
3740
render () {
3841
const {
3942
type, disabled, htmlType,
4043
prefixCls, trigger, align,
4144
visible, placement, getPopupContainer,
4245
...restProps
4346
} = this.$props
44-
47+
const { getPopupContainer: getContextPopupContainer } = this.configProvider
4548
const dropdownProps = {
4649
props: {
4750
align,
4851
disabled,
4952
trigger: disabled ? [] : trigger,
5053
placement,
51-
getPopupContainer,
54+
getPopupContainer: getPopupContainer || getContextPopupContainer,
5255
},
5356
on: {
5457
visibleChange: this.onVisibleChange,

components/dropdown/dropdown.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const Dropdown = {
2121
prop: 'visible',
2222
event: 'visibleChange',
2323
},
24+
inject: {
25+
configProvider: { default: {}},
26+
},
2427
methods: {
2528
getTransitionName () {
2629
const { placement = '', transitionName } = this.$props
@@ -35,7 +38,15 @@ const Dropdown = {
3538
},
3639

3740
render () {
38-
const { $slots, prefixCls, trigger, disabled, $listeners } = this
41+
const { $slots, $listeners } = this
42+
const props = getOptionProps(this)
43+
const {
44+
prefixCls,
45+
trigger,
46+
disabled,
47+
getPopupContainer,
48+
} = props
49+
const { getPopupContainer: getContextPopupContainer } = this.configProvider
3950
const dropdownTrigger = cloneElement($slots.default, {
4051
class: `${prefixCls}-trigger`,
4152
disabled,
@@ -68,7 +79,8 @@ const Dropdown = {
6879
const dropdownProps = {
6980
props: {
7081
alignPoint,
71-
...getOptionProps(this),
82+
...props,
83+
getPopupContainer: getPopupContainer || getContextPopupContainer,
7284
transitionName: this.getTransitionName(),
7385
trigger: triggerActions,
7486
},

components/dropdown/getDropdownProps.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ export default () => ({
99
prefixCls: PropTypes.string,
1010
transitionName: PropTypes.string,
1111
placement: PropTypes.oneOf(['topLeft', 'topCenter', 'topRight', 'bottomLeft', 'bottomCenter', 'bottomRight']),
12+
overlayClassName: PropTypes.string,
13+
overlayStyle: PropTypes.object,
1214
forceRender: PropTypes.bool,
15+
mouseEnterDelay: PropTypes.number,
16+
mouseLeaveDelay: PropTypes.number,
1317
})

components/dropdown/index.en-US.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| disabled | whether the dropdown menu is disabled | boolean | - |
88
| getPopupContainer | to set the container of the dropdown menu. The default is to create a `div` element in `body`, you can reset it to the scrolling area and make a relative reposition. [example](https://codepen.io/afc163/pen/zEjNOy?editors=0010) | Function(triggerNode) | `() => document.body` |
99
| overlay(slot) | the dropdown menu | [Menu](/ant-design-vue/components/menu) | - |
10+
| overlayClassName | Class name of the dropdown root element | string | - |
11+
| overlayStyle | Style of the dropdown root element | object | - |
1012
| placement | placement of pop menu: `bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` |
1113
| trigger | the trigger mode which executes the drop-down action | Array&lt;`click`\|`hover`\|`contextmenu`> | `['hover']` |
1214
| visible(v-model) | whether the dropdown menu is visible | boolean | - |

components/dropdown/index.zh-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| disabled | 菜单是否禁用 | boolean | - |
88
| getPopupContainer | 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。 | Function(triggerNode) | `() => document.body` |
99
| overlay(slot) | 菜单 | [Menu](/ant-design-vue/components/menu-cn) | - |
10+
| overlayClassName | 下拉根元素的类名称 | string | - |
11+
| overlayStyle | 下拉根元素的样式 | object | - |
1012
| placement | 菜单弹出位置:`bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` |
1113
| trigger | 触发下拉的行为 | Array&lt;`click`\|`hover`\|`contextmenu`> | `['hover']` |
1214
| visible(v-model) | 菜单是否显示 | boolean | - |

0 commit comments

Comments
 (0)