@@ -34,14 +34,19 @@ export interface PushState {
34
34
}
35
35
36
36
const defaultPushState : PushState = { distance : 180 } ;
37
-
37
+ type getContainerFunc = ( ) => HTMLElement ;
38
38
export const drawerProps = ( ) => ( {
39
39
autofocus : { type : Boolean , default : undefined } ,
40
40
closable : { type : Boolean , default : undefined } ,
41
41
closeIcon : PropTypes . any ,
42
42
destroyOnClose : { type : Boolean , default : undefined } ,
43
43
forceRender : { type : Boolean , default : undefined } ,
44
- getContainer : PropTypes . any ,
44
+ getContainer : {
45
+ type : [ String , Function , Boolean , Object ] as PropType <
46
+ string | HTMLElement | getContainerFunc | false
47
+ > ,
48
+ default : undefined as string | HTMLElement | getContainerFunc | false ,
49
+ } ,
45
50
maskClosable : { type : Boolean , default : undefined } ,
46
51
mask : { type : Boolean , default : undefined } ,
47
52
maskStyle : { type : Object as PropType < CSSProperties > , default : undefined as CSSProperties } ,
@@ -108,7 +113,14 @@ const Drawer = defineComponent({
108
113
const destroyClose = ref ( false ) ;
109
114
const vcDrawer = ref ( null ) ;
110
115
const parentDrawerOpts = inject ( 'parentDrawerOpts' , null ) ;
111
- const { prefixCls } = useConfigInject ( 'drawer' , props ) ;
116
+ const { prefixCls, getPopupContainer, direction } = useConfigInject ( 'drawer' , props ) ;
117
+ const getContainer = computed ( ( ) =>
118
+ // 有可能为 false,所以不能直接判断
119
+ props . getContainer === undefined && getPopupContainer . value
120
+ ? ( ) => getPopupContainer . value ( document . body )
121
+ : props . getContainer ,
122
+ ) ;
123
+
112
124
devWarning (
113
125
! props . afterVisibleChange ,
114
126
'Drawer' ,
@@ -366,13 +378,15 @@ const Drawer = defineComponent({
366
378
[ className ] : className ,
367
379
[ wrapClassName ] : ! ! wrapClassName ,
368
380
[ haveMask ] : ! ! haveMask ,
381
+ [ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
369
382
} ) ,
370
383
style : drawerStyle . value ,
371
384
ref : vcDrawer ,
372
385
} ;
373
386
return (
374
387
< VcDrawer
375
388
{ ...vcDrawerProps }
389
+ getContainer = { getContainer . value }
376
390
v-slots = { {
377
391
handler : props . handle ? ( ) => props . handle : slots . handle ,
378
392
default : ( ) => renderBody ( prefixCls . value ) ,
0 commit comments