File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -29,16 +29,25 @@ describe('Overlay directives', () => {
29
29
fixture . detectChanges ( ) ;
30
30
} ) ;
31
31
32
+ /** Returns the current open overlay pane element. */
33
+ function getPaneElement ( ) {
34
+ return overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
35
+ }
36
+
32
37
it ( `should attach the overlay based on the open property` , ( ) => {
33
38
fixture . componentInstance . isOpen = true ;
34
39
fixture . detectChanges ( ) ;
35
40
36
41
expect ( overlayContainerElement . textContent ) . toContain ( 'Menu content' ) ;
42
+ expect ( getPaneElement ( ) . style . pointerEvents )
43
+ . toBeFalsy ( 'Expected the overlay pane to enable pointerEvents when attached.' ) ;
37
44
38
45
fixture . componentInstance . isOpen = false ;
39
46
fixture . detectChanges ( ) ;
40
47
41
48
expect ( overlayContainerElement . textContent ) . toBe ( '' ) ;
49
+ expect ( getPaneElement ( ) . style . pointerEvents )
50
+ . toBe ( 'none' , 'Expected the overlay pane to disable pointerEvents when detached.' ) ;
42
51
} ) ;
43
52
44
53
it ( 'should destroy the overlay when the directive is destroyed' , ( ) => {
@@ -47,6 +56,8 @@ describe('Overlay directives', () => {
47
56
fixture . destroy ( ) ;
48
57
49
58
expect ( overlayContainerElement . textContent . trim ( ) ) . toBe ( '' ) ;
59
+ expect ( getPaneElement ( ) )
60
+ . toBeFalsy ( 'Expected the overlay pane element to be removed when disposed.' ) ;
50
61
} ) ;
51
62
52
63
it ( 'should use a connected position strategy with a default set of positions' , ( ) => {
Original file line number Diff line number Diff line change @@ -35,10 +35,15 @@ export class OverlayRef implements PortalHost {
35
35
}
36
36
37
37
let attachResult = this . _portalHost . attach ( portal ) ;
38
+
39
+ // Update the pane element with the given state configuration.
38
40
this . updateSize ( ) ;
39
41
this . updateDirection ( ) ;
40
42
this . updatePosition ( ) ;
41
43
44
+ // Enable pointer events for the overlay pane element.
45
+ this . _togglePointerEvents ( true ) ;
46
+
42
47
return attachResult ;
43
48
}
44
49
@@ -48,6 +53,12 @@ export class OverlayRef implements PortalHost {
48
53
*/
49
54
detach ( ) : Promise < any > {
50
55
this . _detachBackdrop ( ) ;
56
+
57
+ // When the overlay is detached, the pane element should disable pointer events.
58
+ // This is necessary because otherwise the pane element will cover the page and disable
59
+ // pointer events therefore. Depends on the position strategy and the applied pane boundaries.
60
+ this . _togglePointerEvents ( false ) ;
61
+
51
62
return this . _portalHost . detach ( ) ;
52
63
}
53
64
@@ -115,6 +126,11 @@ export class OverlayRef implements PortalHost {
115
126
}
116
127
}
117
128
129
+ /** Toggles the pointer events for the overlay pane element. */
130
+ private _togglePointerEvents ( enablePointer : boolean ) {
131
+ this . _pane . style . pointerEvents = enablePointer ? null : 'none' ;
132
+ }
133
+
118
134
/** Attaches a backdrop for this overlay. */
119
135
private _attachBackdrop ( ) {
120
136
this . _backdropElement = document . createElement ( 'div' ) ;
Original file line number Diff line number Diff line change @@ -62,6 +62,23 @@ describe('Overlay', () => {
62
62
expect ( overlayContainerElement . textContent ) . toBe ( '' ) ;
63
63
} ) ;
64
64
65
+ it ( 'should disable pointer events of the pane element if detached' , ( ) => {
66
+ let overlayRef = overlay . create ( ) ;
67
+ let paneElement = overlayRef . overlayElement ;
68
+
69
+ overlayRef . attach ( componentPortal ) ;
70
+
71
+ expect ( paneElement . childNodes . length ) . not . toBe ( 0 ) ;
72
+ expect ( paneElement . style . pointerEvents )
73
+ . toBeFalsy ( 'Expected the overlay pane to enable pointerEvents when attached.' ) ;
74
+
75
+ overlayRef . detach ( ) ;
76
+
77
+ expect ( paneElement . childNodes . length ) . toBe ( 0 ) ;
78
+ expect ( paneElement . style . pointerEvents )
79
+ . toBe ( 'none' , 'Expected the overlay pane to disable pointerEvents when detached.' ) ;
80
+ } ) ;
81
+
65
82
it ( 'should open multiple overlays' , ( ) => {
66
83
let pizzaOverlayRef = overlay . create ( ) ;
67
84
pizzaOverlayRef . attach ( componentPortal ) ;
Original file line number Diff line number Diff line change @@ -65,11 +65,14 @@ export class DomPortalHost extends BasePortalHost {
65
65
let viewContainer = portal . viewContainerRef ;
66
66
let viewRef = viewContainer . createEmbeddedView ( portal . templateRef ) ;
67
67
68
+ // The method `createEmbeddedView` will add the view as a child of the viewContainer.
69
+ // But for the DomPortalHost the view can be added everywhere in the DOM (e.g Overlay Container)
70
+ // To move the view to the specified host element. We just re-append the existing root nodes.
68
71
viewRef . rootNodes . forEach ( rootNode => this . _hostDomElement . appendChild ( rootNode ) ) ;
69
72
70
73
this . setDisposeFn ( ( ( ) => {
71
74
let index = viewContainer . indexOf ( viewRef ) ;
72
- if ( index != - 1 ) {
75
+ if ( index !== - 1 ) {
73
76
viewContainer . remove ( index ) ;
74
77
}
75
78
} ) ) ;
You can’t perform that action at this time.
0 commit comments