44 * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55 */
66import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js' ;
7- import { LoginMixin } from './vaadin-login-mixin .js' ;
7+ import { TitleController } from './title-controller .js' ;
88
99/**
1010 * @polymerMixin
11- * @mixes LoginMixin
1211 * @mixes OverlayClassMixin
1312 */
1413export const LoginOverlayMixin = ( superClass ) =>
15- class LoginOverlayMixin extends OverlayClassMixin ( LoginMixin ( superClass ) ) {
14+ class LoginOverlayMixin extends OverlayClassMixin ( superClass ) {
1615 static get properties ( ) {
1716 return {
1817 /**
@@ -32,8 +31,8 @@ export const LoginOverlayMixin = (superClass) =>
3231 opened : {
3332 type : Boolean ,
3433 value : false ,
34+ reflectToAttribute : true ,
3535 sync : true ,
36- observer : '_onOpenedChange' ,
3736 } ,
3837
3938 /**
@@ -47,15 +46,43 @@ export const LoginOverlayMixin = (superClass) =>
4746 } ;
4847 }
4948
50- static get observers ( ) {
51- return [ '__i18nChanged(__effectiveI18n)' ] ;
49+ /** @protected */
50+ firstUpdated ( ) {
51+ super . firstUpdated ( ) ;
52+
53+ this . setAttribute ( 'role' , 'dialog' ) ;
54+
55+ this . __titleController = new TitleController ( this ) ;
56+ this . addController ( this . __titleController ) ;
57+
58+ this . _overlayElement = this . $ . overlay ;
59+ }
60+
61+ /** @protected */
62+ willUpdate ( props ) {
63+ super . willUpdate ( props ) ;
64+
65+ if ( props . has ( '__effectiveI18n' ) && this . __effectiveI18n . header ) {
66+ this . title = this . __effectiveI18n . header . title ;
67+ this . description = this . __effectiveI18n . header . description ;
68+ }
5269 }
5370
5471 /** @protected */
55- ready ( ) {
56- super . ready ( ) ;
72+ updated ( props ) {
73+ super . updated ( props ) ;
74+
75+ if ( props . has ( 'title' ) || props . has ( '__effectiveI18n' ) ) {
76+ this . __titleController . setTitle ( this . title ) ;
77+ }
78+
79+ if ( props . has ( 'headingLevel' ) ) {
80+ this . __titleController . setLevel ( this . headingLevel ) ;
81+ }
5782
58- this . _overlayElement = this . $ . vaadinLoginOverlayWrapper ;
83+ if ( props . has ( 'opened' ) ) {
84+ this . _openedChanged ( this . opened ) ;
85+ }
5986 }
6087
6188 /** @protected */
@@ -72,91 +99,32 @@ export const LoginOverlayMixin = (superClass) =>
7299 disconnectedCallback ( ) {
73100 super . disconnectedCallback ( ) ;
74101
75- // Close overlay and memorize opened state
76- this . __restoreOpened = this . opened ;
77- this . opened = false ;
78- }
79-
80- /** @private */
81- __i18nChanged ( effectiveI18n ) {
82- const header = effectiveI18n && effectiveI18n . header ;
83- if ( ! header ) {
84- return ;
85- }
86- this . title = header . title ;
87- this . description = header . description ;
102+ // Using a timeout to avoid toggling opened state
103+ // when just moving the overlay in the DOM
104+ setTimeout ( ( ) => {
105+ if ( ! this . isConnected ) {
106+ this . __restoreOpened = this . opened ;
107+ this . opened = false ;
108+ }
109+ } ) ;
88110 }
89111
90112 /** @protected */
91113 _preventClosingLogin ( e ) {
92114 e . preventDefault ( ) ;
93115 }
94116
95- /**
96- * @param {!Event } e
97- * @protected
98- */
99- _retargetEvent ( e ) {
100- e . stopPropagation ( ) ;
101- const { detail, composed, cancelable, bubbles } = e ;
102-
103- const firedEvent = this . dispatchEvent ( new CustomEvent ( e . type , { bubbles, cancelable, composed, detail } ) ) ;
104- // Check if `eventTarget.preventDefault()` was called to prevent default in the original event
105- if ( ! firedEvent ) {
106- e . preventDefault ( ) ;
107- }
108- }
109-
110117 /** @private */
111- _onOpenedChange ( ) {
112- const form = this . $ . vaadinLoginForm ;
113-
114- if ( ! this . opened ) {
115- form . _userNameField . value = '' ;
116- form . _passwordField . value = '' ;
118+ _openedChanged ( opened , oldOpened ) {
119+ if ( oldOpened ) {
120+ this . _userNameField . value = '' ;
121+ this . _passwordField . value = '' ;
117122 this . disabled = false ;
118-
119- if ( this . _undoTitleTeleport ) {
120- this . _undoTitleTeleport ( ) ;
121- }
122-
123- if ( this . _undoFieldsTeleport ) {
124- this . _undoFieldsTeleport ( ) ;
125- }
126-
127- if ( this . _undoFooterTeleport ) {
128- this . _undoFooterTeleport ( ) ;
129- }
130- } else {
131- this . _undoTitleTeleport = this . _teleport ( 'title' , this . $ . vaadinLoginOverlayWrapper ) ;
132- this . _undoFieldsTeleport = this . _teleport ( 'custom-form-area' , form , form . querySelector ( 'vaadin-button' ) ) ;
133- this . _undoFooterTeleport = this . _teleport ( 'footer' , form ) ;
134-
123+ } else if ( opened ) {
135124 // Overlay sets pointerEvents on body to `none`, which breaks LastPass popup
136125 // Reverting it back to the previous state
137126 // https://github.com/vaadin/vaadin-overlay/blob/041cde4481b6262eac68d3a699f700216d897373/src/vaadin-overlay.html#L660
138- document . body . style . pointerEvents = this . $ . vaadinLoginOverlayWrapper . _previousDocumentPointerEvents ;
127+ document . body . style . pointerEvents = this . $ . overlay . _previousDocumentPointerEvents ;
139128 }
140129 }
141-
142- /** @private */
143- _teleport ( slot , target , refNode ) {
144- const teleported = [ ...this . querySelectorAll ( `[slot="${ slot } "]` ) ] . map ( ( el ) => {
145- if ( refNode ) {
146- target . insertBefore ( el , refNode ) ;
147- } else {
148- target . appendChild ( el ) ;
149- }
150- return el ;
151- } ) ;
152- // Function to undo the teleport
153- return ( ) => {
154- this . append ( ...teleported ) ;
155- } ;
156- }
157-
158- /** @private */
159- __computeHeadingLevel ( headingLevel ) {
160- return headingLevel + 1 ;
161- }
162130 } ;
0 commit comments