@@ -39,14 +39,18 @@ export class PreviewRef {
39
39
/** Reference to the preview element. */
40
40
private _preview : HTMLElement ;
41
41
42
- /** Reference to the preview wrapper. */
43
- private _wrapper : HTMLElement ;
42
+ /**
43
+ * Reference to the preview popover wrapper.
44
+ * May not be created if `_disablePopover` is enabled.
45
+ */
46
+ private _popover : HTMLElement | null ;
44
47
45
48
constructor (
46
49
private _document : Document ,
47
50
private _rootElement : HTMLElement ,
48
51
private _direction : Direction ,
49
52
private _initialDomRect : DOMRect ,
53
+ private _disablePopover : boolean ,
50
54
private _previewTemplate : DragPreviewTemplate | null ,
51
55
private _previewClass : string | string [ ] | null ,
52
56
private _pickupPositionOnPage : {
@@ -58,21 +62,33 @@ export class PreviewRef {
58
62
) { }
59
63
60
64
attach ( parent : HTMLElement ) : void {
61
- this . _wrapper = this . _createWrapper ( ) ;
62
65
this . _preview = this . _createPreview ( ) ;
63
- this . _wrapper . appendChild ( this . _preview ) ;
64
- parent . appendChild ( this . _wrapper ) ;
65
66
66
- // The null check is necessary for browsers that don't support the popover API.
67
- if ( this . _wrapper . showPopover ) {
68
- this . _wrapper . showPopover ( ) ;
67
+ if ( this . _disablePopover ) {
68
+ this . _styleRootElement ( this . _preview ) ;
69
+ parent . appendChild ( this . _preview ) ;
70
+ } else {
71
+ this . _popover = this . _createWrapper ( ) ;
72
+ this . _styleRootElement ( this . _popover ) ;
73
+ this . _popover . appendChild ( this . _preview ) ;
74
+ parent . appendChild ( this . _popover ) ;
75
+
76
+ // The null check is necessary for browsers that don't support the popover API.
77
+ if ( this . _popover . showPopover ) {
78
+ this . _popover . showPopover ( ) ;
79
+ }
69
80
}
70
81
}
71
82
72
83
destroy ( ) : void {
73
- this . _wrapper ?. remove ( ) ;
84
+ if ( this . _popover ) {
85
+ this . _popover . remove ( ) ;
86
+ } else {
87
+ this . _preview . remove ( ) ;
88
+ }
89
+
74
90
this . _previewEmbeddedView ?. destroy ( ) ;
75
- this . _preview = this . _wrapper = this . _previewEmbeddedView = null ! ;
91
+ this . _preview = this . _popover = this . _previewEmbeddedView = null ! ;
76
92
}
77
93
78
94
setTransform ( value : string ) : void {
@@ -102,17 +118,13 @@ export class PreviewRef {
102
118
private _createWrapper ( ) : HTMLElement {
103
119
const wrapper = this . _document . createElement ( 'div' ) ;
104
120
wrapper . setAttribute ( 'popover' , 'manual' ) ;
105
- wrapper . setAttribute ( 'dir' , this . _direction ) ;
106
121
wrapper . classList . add ( 'cdk-drag-preview-container' ) ;
107
122
108
123
extendStyles ( wrapper . style , {
109
124
// This is redundant, but we need it for browsers that don't support the popover API.
110
- 'position' : 'fixed' ,
111
- 'top' : '0' ,
112
- 'left' : '0' ,
125
+ // The rest of the positioning styles are in `_styleRootElement`.
113
126
'width' : '100%' ,
114
127
'height' : '100%' ,
115
- 'z-index' : this . _zIndex + '' ,
116
128
117
129
// Reset the user agent styles.
118
130
'background' : 'none' ,
@@ -189,4 +201,19 @@ export class PreviewRef {
189
201
190
202
return preview ;
191
203
}
204
+
205
+ private _styleRootElement ( root : HTMLElement ) : void {
206
+ root . setAttribute ( 'dir' , this . _direction ) ;
207
+
208
+ extendStyles (
209
+ root . style ,
210
+ {
211
+ 'position' : 'fixed' ,
212
+ 'top' : '0' ,
213
+ 'left' : '0' ,
214
+ 'z-index' : this . _zIndex + '' ,
215
+ } ,
216
+ importantProperties ,
217
+ ) ;
218
+ }
192
219
}
0 commit comments