@@ -8,7 +8,7 @@ import '@vaadin/button/src/vaadin-button.js';
88import '@vaadin/dialog/src/vaadin-dialog.js' ;
99import '@vaadin/confirm-dialog/src/vaadin-confirm-dialog.js' ;
1010import '@vaadin/vaadin-license-checker/vaadin-license-checker.js' ;
11- import './vaadin-dialog-layout .js' ;
11+ import './vaadin-crud-dialog .js' ;
1212import './vaadin-crud-grid.js' ;
1313import './vaadin-crud-form.js' ;
1414import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js' ;
@@ -176,7 +176,8 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
176176 height : 100% ;
177177 }
178178
179- : host ( [hidden ]) {
179+ : host ( [hidden ]) ,
180+ [hidden ] {
180181 display : none !important ;
181182 }
182183
@@ -199,6 +200,39 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
199200 : host ( [editor-position = 'bottom' ]) # container {
200201 flex-direction : column;
201202 }
203+
204+ [part = 'editor' ] {
205+ z-index : 1 ;
206+ display : flex;
207+ flex-direction : column;
208+ height : 100% ;
209+ }
210+
211+ : host ( : not ( [editor-position = '' ]) [editor-opened ]) [part = 'editor' ]: not ( [mobile ]) {
212+ flex : 1 0 100% ;
213+ }
214+
215+ : host ( [editor-position = 'bottom' ][editor-opened ]) [part = 'editor' ]: not ( [mobile ]) {
216+ max-height : var ( --vaadin-crud-editor-max-height ) ;
217+ }
218+
219+ : host ( [editor-position = 'aside' ][editor-opened ]) [part = 'editor' ]: not ( [mobile ]) {
220+ min-width : 300px ;
221+ max-width : var ( --vaadin-crud-editor-max-width ) ;
222+ }
223+
224+ [part = 'scroller' ] {
225+ display : flex;
226+ flex-direction : column;
227+ overflow : auto;
228+ flex : auto;
229+ }
230+
231+ [part = 'footer' ] {
232+ display : flex;
233+ flex : none;
234+ flex-direction : row-reverse;
235+ }
202236 </ style >
203237
204238 < div id ="container ">
@@ -222,25 +256,38 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
222256 </ slot >
223257 </ div >
224258 </ div >
225- < vaadin-dialog-layout
226- id ="dialog "
227- theme$ ="[[theme]] "
228- form ="[[_form]] "
229- no-close-on-outside-click ="[[__isDirty]] "
230- no-close-on-esc ="[[__isDirty]] "
231- opened ="{{editorOpened}} "
232- editor-position ="{{editorPosition}} "
233- mobile ="[[__mobile]] "
234- theme ="crud "
259+
260+ < div
261+ id ="editor "
262+ part ="editor "
263+ hidden$ ="[[__computeEditorHidden(editorOpened, __mobile, editorPosition)]] "
264+ mobile$ ="[[__mobile]] "
235265 >
236- < slot name ="header " slot ="header "> </ slot >
237- < slot name ="form " slot ="form "> </ slot >
238- < slot name ="save-button " slot ="save-button "> </ slot >
239- < slot name ="cancel-button " slot ="cancel-button "> </ slot >
240- < slot name ="delete-button " slot ="delete-button "> </ slot >
241- </ vaadin-dialog-layout >
266+ < div part ="scroller " id ="scroller " role ="group " aria-labelledby ="header ">
267+ < div part ="header " id ="header ">
268+ < slot name ="header "> </ slot >
269+ </ div >
270+ < slot name ="form "> </ slot >
271+ </ div >
272+
273+ < div part ="footer " role ="toolbar ">
274+ < slot name ="save-button "> </ slot >
275+ < slot name ="cancel-button "> </ slot >
276+ < slot name ="delete-button "> </ slot >
277+ </ div >
278+ </ div >
242279 </ div >
243280
281+ < vaadin-crud-dialog
282+ id ="dialog "
283+ opened ="[[__computeDialogOpened(editorOpened, __mobile, editorPosition)]] "
284+ aria-label ="[[__editorAriaLabel]] "
285+ no-close-on-outside-click ="[[__isDirty]] "
286+ no-close-on-esc ="[[__isDirty]] "
287+ theme$ ="[[theme]] "
288+ on-opened-changed ="__onDialogOpened "
289+ > </ vaadin-crud-dialog >
290+
244291 < vaadin-confirm-dialog
245292 theme$ ="[[theme]] "
246293 id ="confirmCancel "
@@ -252,6 +299,7 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
252299 message ="[[i18n.confirm.cancel.content]] "
253300 confirm-theme ="primary "
254301 > </ vaadin-confirm-dialog >
302+
255303 < vaadin-confirm-dialog
256304 theme$ ="[[theme]] "
257305 id ="confirmDelete "
@@ -436,6 +484,7 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
436484 */
437485 editorOpened : {
438486 type : Boolean ,
487+ reflectToAttribute : true ,
439488 notify : true ,
440489 observer : '__onOpenedChanged'
441490 } ,
@@ -532,6 +581,9 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
532581 }
533582 } ,
534583
584+ /** @private */
585+ __editorAriaLabel : String ,
586+
535587 /** @private */
536588 __isDirty : Boolean ,
537589
@@ -628,8 +680,8 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
628680 this . __gridSizeListener = this . __onGridSizeChanges . bind ( this ) ;
629681 this . __boundEditOnClickListener = this . __editOnClickListener . bind ( this ) ;
630682 this . _grid = this . $ . grid ;
631- this . $ . dialog . $ . dialog . $ . overlay . addEventListener ( 'vaadin-overlay-outside-click' , this . __cancelBound ) ;
632- this . $ . dialog . $ . dialog . $ . overlay . addEventListener ( 'vaadin-overlay-escape-press' , this . __cancelBound ) ;
683+ this . $ . dialog . $ . overlay . addEventListener ( 'vaadin-overlay-outside-click' , this . __cancelBound ) ;
684+ this . $ . dialog . $ . overlay . addEventListener ( 'vaadin-overlay-escape-press' , this . __cancelBound ) ;
633685 // Initialize the default buttons
634686 this . __propagateHostAttributes ( ) ;
635687 }
@@ -691,12 +743,23 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
691743 this . __onFormChange ( this . _form ) ;
692744 }
693745
746+ if ( opened ) {
747+ this . __ensureChildren ( ) ;
748+ }
749+
694750 this . __toggleToolbar ( ) ;
751+
752+ // Make sure to reset scroll position
753+ this . $ . scroller . scrollTop = 0 ;
695754 }
696755
697756 /** @private */
698- __mobileChanged ( ) {
699- this . __toggleToolbar ( ) ;
757+ __mobileChanged ( mobile , oldMobile ) {
758+ if ( mobile || oldMobile ) {
759+ this . __toggleToolbar ( ) ;
760+
761+ this . __ensureChildren ( ) ;
762+ }
700763 }
701764
702765 /** @private */
@@ -707,6 +770,62 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
707770 }
708771 }
709772
773+ /** @private */
774+ __moveChildNodes ( target ) {
775+ const nodes = [ this . _headerNode , this . _form , this . _saveButton , this . _cancelButton , this . _deleteButton ] ;
776+ if ( ! nodes . every ( ( node ) => node instanceof HTMLElement ) ) {
777+ return ;
778+ }
779+
780+ // Teleport header node, form, and the buttons to corresponding slots.
781+ // NOTE: order in which buttons are moved matches the order of slots.
782+ nodes . forEach ( ( node ) => {
783+ target . appendChild ( node ) ;
784+ } ) ;
785+
786+ // Wait to set label until slotted element has been moved.
787+ setTimeout ( ( ) => {
788+ this . __dialogAriaLabel = this . _headerNode . textContent . trim ( ) ;
789+ } ) ;
790+ }
791+
792+ /** @private */
793+ __shouldOpenDialog ( isMobile , editorPosition ) {
794+ return editorPosition === '' || isMobile ;
795+ }
796+
797+ /** @private */
798+ __ensureChildren ( ) {
799+ if ( this . __shouldOpenDialog ( this . __mobile , this . editorPosition ) ) {
800+ // Move form to dialog
801+ this . __moveChildNodes ( this . $ . dialog . $ . overlay ) ;
802+ } else {
803+ // Move form to crud
804+ this . __moveChildNodes ( this ) ;
805+ }
806+ }
807+
808+ /** @private */
809+ __computeDialogOpened ( opened , isMobile , editorPosition ) {
810+ // Only open dialog when editorPosition is "" or mobile is set
811+ return this . __shouldOpenDialog ( isMobile , editorPosition ) ? opened : false ;
812+ }
813+
814+ /** @private */
815+ __computeEditorHidden ( opened , mobile , editorPosition ) {
816+ // Only show editor when editorPosition is "bottom" or "aside"
817+ if ( [ 'aside' , 'bottom' ] . includes ( editorPosition ) && ! mobile ) {
818+ return ! opened ;
819+ }
820+
821+ return true ;
822+ }
823+
824+ /** @private */
825+ __onDialogOpened ( event ) {
826+ this . editorOpened = event . detail . value ;
827+ }
828+
710829 /** @private */
711830 __onDomChange ( addedNodes ) {
712831 // TODO: restore default button when a corresponding slotted button is removed.
@@ -729,10 +848,8 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
729848 } else if ( slotAttributeValue . indexOf ( 'button' ) >= 0 ) {
730849 const [ button ] = slotAttributeValue . split ( '-' ) ;
731850 this [ `_${ button } Button` ] = node ;
732- this . $ . dialog [ `${ button } Button` ] = node ;
733851 } else if ( slotAttributeValue == 'header' ) {
734852 this . _headerNode = node ;
735- this . $ . dialog . header = node ;
736853 }
737854 } ) ;
738855 }
@@ -811,9 +928,7 @@ class Crud extends SlotMixin(ElementMixin(ThemableMixin(PolymerElement))) {
811928 currentButton . parentElement . removeChild ( currentButton ) ;
812929 }
813930
814- if ( slottedButton . parentElement === this ) {
815- slottedButton . addEventListener ( 'click' , clickListener ) ;
816- }
931+ slottedButton . addEventListener ( 'click' , clickListener ) ;
817932 }
818933
819934 /** @private */
0 commit comments