Skip to content

Commit 7a3c881

Browse files
committed
feat: config-provider getPopupContainer add dialogContext
1 parent 74f5d9f commit 7a3c881

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

components/config-provider/index.en-US.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
This component provides a configuration to all Vue components underneath itself via the [provide / inject](https://vuejs.org/v2/api/#provide-inject), In the render tree all components will have access to the provided config.
44

55
```html
6-
<a-config-provider :getPopupContainer="getPopupContainer">
7-
<app />
8-
</a-config-provider>
6+
<template>
7+
<a-config-provider :getPopupContainer="getPopupContainer">
8+
<app />
9+
</a-config-provider>
10+
</template>
11+
<script>
12+
export default {
13+
methods: {
14+
getPopupContainer(el, dialogContext) {
15+
if(dialogContext) {
16+
return dialogContext.$refs.wrap;
17+
} else {
18+
return document.body;
19+
}
20+
},
21+
},
22+
};
23+
</script>
924
```
1025

1126
### Content Security Policy
@@ -25,5 +40,5 @@ Some component use dynamic style to support wave effect. You can config `csp` pr
2540
| autoInsertSpaceInButton | Set `false` to remove space between 2 chinese characters on Button | boolean | true |
2641
| csp | Set [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) config | { nonce: string } | - |
2742
| renderEmpty | set empty content of components. Ref [Empty](/components/empty/) | slot-scope \| Function(componentName: string): ReactNode | - |
28-
| getPopupContainer | to set the container of the popup element. The default is to create a `div` element in `body`. | Function(triggerNode) | `() => document.body` |
43+
| getPopupContainer | to set the container of the popup element. The default is to create a `div` element in `body`. | Function(triggerNode, dialogContext) | `() => document.body` |
2944
| prefixCls | set prefix class | string | ant |

components/config-provider/index.zh-CN.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33
ConfigProvider 使用 Vue 的 [provide / inject](https://vuejs.org/v2/api/#provide-inject) 特性,只需在应用外围包裹一次即可全局生效。
44

55
```html
6-
<a-config-provider :getPopupContainer="getPopupContainer">
7-
<app />
8-
</a-config-provider>
6+
<template>
7+
<a-config-provider :getPopupContainer="getPopupContainer">
8+
<app />
9+
</a-config-provider>
10+
</template>
11+
<script>
12+
export default {
13+
methods: {
14+
getPopupContainer(el, dialogContext) {
15+
if(dialogContext) {
16+
return dialogContext.$refs.wrap;
17+
} else {
18+
return document.body;
19+
}
20+
},
21+
},
22+
};
23+
</script>
924
```
1025

1126
### Content Security Policy
@@ -25,5 +40,5 @@ ConfigProvider 使用 Vue 的 [provide / inject](https://vuejs.org/v2/api/#provi
2540
| autoInsertSpaceInButton | 设置为 `false` 时,移除按钮中 2 个汉字之间的空格 | boolean | true |
2641
| csp | 设置 [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) 配置 | { nonce: string } | - |
2742
| renderEmpty | 自定义组件空状态。参考 [空状态](/components/empty/) | slot-scope \| Function(componentName: string): VNode | - |
28-
| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode) | () => document.body |
43+
| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode, dialogContext) | () => document.body |
2944
| prefixCls | 设置统一样式前缀 | string | ant |

components/vc-dialog/Dialog.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export default {
6464
};
6565
},
6666

67+
provide() {
68+
return {
69+
dialogContext: this,
70+
};
71+
},
72+
6773
watch: {
6874
visible(val) {
6975
if (val) {

components/vc-trigger/Trigger.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default {
7878
inject: {
7979
vcTriggerContext: { default: () => ({}) },
8080
savePopupRef: { default: () => noop },
81+
dialogContext: { default: () => null },
8182
},
8283
data() {
8384
const props = this.$props;
@@ -420,7 +421,7 @@ export default {
420421
},
421422

422423
getContainer() {
423-
const { $props: props } = this;
424+
const { $props: props, dialogContext } = this;
424425
const popupContainer = document.createElement('div');
425426
// Make sure default popup container will never cause scrollbar appearing
426427
// https://github.com/react-component/trigger/issues/41
@@ -429,7 +430,7 @@ export default {
429430
popupContainer.style.left = '0';
430431
popupContainer.style.width = '100%';
431432
const mountNode = props.getPopupContainer
432-
? props.getPopupContainer(this.$el)
433+
? props.getPopupContainer(this.$el, dialogContext)
433434
: props.getDocument().body;
434435
mountNode.appendChild(popupContainer);
435436
this.popupContainer = popupContainer;

types/config-provider.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AntdComponent } from './component';
2+
import Vue from 'vue';
23

34
import { Locale } from './locale-provider';
45

@@ -7,7 +8,7 @@ export interface CSPConfig {
78
}
89

910
export declare class ConfigProvider extends AntdComponent {
10-
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
11+
getPopupContainer?: (triggerNode: HTMLElement, dialogContext?: Vue | null) => HTMLElement;
1112
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => string;
1213
renderEmpty: Function;
1314
csp?: CSPConfig;

0 commit comments

Comments
 (0)