Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dialog): incorrect node attachment when mode = "normal" #3493

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/config-provider/config-receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue, { VueConstructor } from 'vue';
import { mergeWith } from 'lodash-es';
import { GlobalIconConfig } from 'tdesign-icons-vue';
import { defaultGlobalConfig } from './context';
import { GlobalConfigProvider, AnimationType } from './type';
import { GlobalConfigProvider, AnimationType, AttachNodeComponent } from './type';

import type { AttachNode } from '../common';

Expand Down Expand Up @@ -206,7 +206,7 @@ export function getClassPrefixMixins(componentName: string) {
}

// 用于非 composition api 的组件使用来自 config provider注入的 attach 使用
export function getAttachConfigMixins(componentName: string) {
export function getAttachConfigMixins(componentName: AttachNodeComponent) {
return (Vue as VueConstructor<ConfigComponent>).extend({
name: 'TAttachProvider',
inject: {
Expand All @@ -216,8 +216,13 @@ export function getAttachConfigMixins(componentName: string) {
},
methods: {
globalAttach(): AttachNode {
// @ts-ignore
return this.globalConfig?.attach?.[componentName] || this.globalConfig?.attach || 'body';
const globalConfigAttach = this.globalConfig?.attach;

if (typeof globalConfigAttach === 'string' || typeof globalConfigAttach === 'function') {
return globalConfigAttach;
}

return globalConfigAttach?.[componentName] || 'body';
},
},
});
Expand Down
7 changes: 5 additions & 2 deletions src/config-provider/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { MessageOptions } from '../message';
import { ImageProps } from '../image';
import { TNode, SizeEnum, AttachNode } from '../common';

export type AttachNodeComponent = 'imageViewer' | 'drawer' | 'dialog' | 'popup';

export interface GlobalConfigProvider {
/**
* 警告全局配置
Expand All @@ -26,9 +28,10 @@ export interface GlobalConfigProvider {
*/
animation?: Partial<Record<'include' | 'exclude', Array<AnimationType>>>;
/**
* null
* 组件挂载节点
* @default document.body
*/
attach?: AttachNode | { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode };
attach?: AttachNode | { [key in AttachNodeComponent]?: AttachNode };
/**
* 自动填充组件全局配置
*/
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default mixins(
return !this.isFullScreen ? { width: getCSSValue(this.width), ...this.dialogStyle } : { ...this.dialogStyle }; // width全屏模式不生效;
},
computedAttach(): AttachNode {
return this.showInAttachedElement ? undefined : this.attach || this.globalAttach();
return this.showInAttachedElement || this.isNormal ? undefined : this.attach || this.globalAttach();
},
},

Expand Down
Loading