- I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
Modal的静态方法在ShadowDOM中按钮点击无效
DEMO: https://chuyb.csb.app/
代码: https://codesandbox.io/s/shadowdom-antd-modal-func-chuyb
What does the proposed API look like?
- 修改confirm.tsx,提供全局设置getContainer方法
// 提供全局设置getContainer方法
let funcConfig: ModalFuncProps;
export const setFuncConfig = (config: ModalFuncProps) => {
funcConfig = config;
}
修改index.tsx,增加静态方法setFuncConfig
Modal.setFuncConfig = setFuncConfig;
- 修改confirm.tsx,修改confirm中渲染容器div的获取方式
function getFuncContainer(containerFn: GetContainer) {
let funcContainer: HTMLElement = containerFn as HTMLElement;
if (typeof containerFn === 'function') {
funcContainer = containerFn();
} else if (typeof containerFn === 'string') {
funcContainer = document.querySelector(containerFn);
}
return funcContainer;
}
export default function confirm(config: ModalFuncProps) {
// eslint-disable-next-line no-use-before-define
let currentConfig = { ...funcConfig, ...config, close, visible: true } as any;
const div = document.createElement('div');
const containerFn = currentConfig.getContainer;
if (containerFn) {
const root: HTMLElement = getFuncContainer(containerFn);
root.appendChild(div);
} else {
document.body.appendChild(div);
}
1条答案
按热度按时间0lvr5msh1#
后来怎么解决的?