@@ -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,22 +62,34 @@ 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
- // Note that we use a string access for compatibility with Closure.
68
- if ( 'showPopover' in this . _wrapper ) {
69
- 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
+ // Note that we use a string access for compatibility with Closure.
78
+ if ( 'showPopover' in this . _popover ) {
79
+ this . _popover [ 'showPopover' ] ( ) ;
80
+ }
70
81
}
71
82
}
72
83
73
84
destroy ( ) : void {
74
- this . _wrapper ?. remove ( ) ;
85
+ if ( this . _popover ) {
86
+ this . _popover . remove ( ) ;
87
+ } else {
88
+ this . _preview . remove ( ) ;
89
+ }
90
+
75
91
this . _previewEmbeddedView ?. destroy ( ) ;
76
- this . _preview = this . _wrapper = this . _previewEmbeddedView = null ! ;
92
+ this . _preview = this . _popover = this . _previewEmbeddedView = null ! ;
77
93
}
78
94
79
95
setTransform ( value : string ) : void {
@@ -103,17 +119,13 @@ export class PreviewRef {
103
119
private _createWrapper ( ) : HTMLElement {
104
120
const wrapper = this . _document . createElement ( 'div' ) ;
105
121
wrapper . setAttribute ( 'popover' , 'manual' ) ;
106
- wrapper . setAttribute ( 'dir' , this . _direction ) ;
107
122
wrapper . classList . add ( 'cdk-drag-preview-container' ) ;
108
123
109
124
extendStyles ( wrapper . style , {
110
125
// This is redundant, but we need it for browsers that don't support the popover API.
111
- 'position' : 'fixed' ,
112
- 'top' : '0' ,
113
- 'left' : '0' ,
126
+ // The rest of the positioning styles are in `_styleRootElement`.
114
127
'width' : '100%' ,
115
128
'height' : '100%' ,
116
- 'z-index' : this . _zIndex + '' ,
117
129
118
130
// Reset the user agent styles.
119
131
'background' : 'none' ,
@@ -190,4 +202,19 @@ export class PreviewRef {
190
202
191
203
return preview ;
192
204
}
205
+
206
+ private _styleRootElement ( root : HTMLElement ) : void {
207
+ root . setAttribute ( 'dir' , this . _direction ) ;
208
+
209
+ extendStyles (
210
+ root . style ,
211
+ {
212
+ 'position' : 'fixed' ,
213
+ 'top' : '0' ,
214
+ 'left' : '0' ,
215
+ 'z-index' : this . _zIndex + '' ,
216
+ } ,
217
+ importantProperties ,
218
+ ) ;
219
+ }
193
220
}
0 commit comments