44
55import 'dart:async' ;
66import 'dart:html' ;
7+ import 'dart:math' ;
78
89import 'package:angular/angular.dart' ;
910import 'package:intl/intl.dart' ;
@@ -93,10 +94,30 @@ class MaterialExpansionPanel
9394 }));
9495 }
9596
97+ HtmlElement _headerPanel;
98+ @ViewChild ('headerPanel' )
99+ set headerPanel (HtmlElement headerPanel) {
100+ _headerPanel = headerPanel;
101+ _disposer.addStreamSubscription (_headerPanel.onTransitionEnd.listen ((_) {
102+ // Clear height override so it will match the active child's height.
103+ _headerPanel.style.height = '' ;
104+ }));
105+ }
106+
96107 HtmlElement _mainContent;
97108 @ViewChild ('mainContent' )
98109 set mainContent (HtmlElement mainContent) => _mainContent = mainContent;
99110
111+ HtmlElement _headerContent;
112+ @ViewChild ('headerContent' )
113+ set headerContent (HtmlElement headerContent) =>
114+ _headerContent = headerContent;
115+
116+ HtmlElement _actionContent;
117+ @ViewChild ('action' )
118+ set actionContent (HtmlElement headerContent) =>
119+ _actionContent = headerContent;
120+
100121 HtmlElement _contentWrapper;
101122 @ViewChild ('contentWrapper' )
102123 set contentWrapper (HtmlElement contentWrapper) {
@@ -441,28 +462,45 @@ class MaterialExpansionPanel
441462 } else {
442463 _domService.nextFrame.then ((_) => _mainPanel.style.height = '' );
443464 }
465+
466+ // If the header has to disappear, animate that transition as well
467+ if (hideExpandedHeader) {
468+ // Make current height explicit as a starting point for animation.
469+ _headerPanel.style.height = '${_headerPanel .scrollHeight }px' ;
470+
471+ // On next frame, set target height for animation.
472+ if (expand) {
473+ _domService.nextFrame.then ((_) {
474+ _headerPanel.style.height = '' ;
475+ });
476+ } else {
477+ _readExpandedHeaderHeight ().then ((expandedHeaderHeight) {
478+ _headerPanel.style.height = expandedHeaderHeight;
479+ });
480+ }
481+ }
444482 }
445483
446484 /// Reads the DOM state to calculate the height of the "expanded" panel in its
447485 /// current condition.
448486 ///
449487 /// This defined end point will be used to animate expansion.
450488 Future <String > _readExpandedPanelHeight () {
451- var completeExpandedHeight = Completer <String >();
489+ final completeExpandedHeight = Completer <String >();
452490
453491 _domService.scheduleRead (() {
454- var contentHeight = _mainContent.scrollHeight;
492+ final contentHeight = _mainContent.scrollHeight;
455493 var expandedPanelHeight = '' ;
456494
457- var mainPanelStyle = _mainPanel.getComputedStyle ();
495+ final mainPanelStyle = _mainPanel.getComputedStyle ();
458496 // Do our best to make sure that onTransitionEnd will fire later.
459- var hasHeightTransition =
497+ final hasHeightTransition =
460498 contentHeight > 0 && mainPanelStyle.transition.contains ('height' );
461499
462500 if (hasHeightTransition) {
463501 // If the content-wrapper has a top margin, it is not reflected in the
464502 // scroll height.
465- var topMargin = _contentWrapper.getComputedStyle ().marginTop;
503+ final topMargin = _contentWrapper.getComputedStyle ().marginTop;
466504 expandedPanelHeight = 'calc(${contentHeight }px + ${topMargin })' ;
467505 }
468506 completeExpandedHeight.complete (expandedPanelHeight);
@@ -471,6 +509,31 @@ class MaterialExpansionPanel
471509 return completeExpandedHeight.future;
472510 }
473511
512+ /// Reads the DOM state to calculate the height of the header in its
513+ /// current condition.
514+ ///
515+ /// This defined end point will be used to animate expansion.
516+ Future <String > _readExpandedHeaderHeight () {
517+ final completeExpandedHeight = Completer <String >();
518+
519+ _domService.scheduleRead (() {
520+ final contentHeight =
521+ max (_headerContent.scrollHeight, _actionContent? .scrollHeight ?? 0 );
522+ var expandedHeaderHeight = '' ;
523+
524+ final headerPanelStyle = _headerPanel.getComputedStyle ();
525+ // Do our best to make sure that onTransitionEnd will fire later.
526+ final hasHeightTransition =
527+ contentHeight > 0 && headerPanelStyle.transition.contains ('height' );
528+
529+ if (hasHeightTransition) expandedHeaderHeight = '${contentHeight }px' ;
530+
531+ completeExpandedHeight.complete (expandedHeaderHeight);
532+ });
533+
534+ return completeExpandedHeight.future;
535+ }
536+
474537 @override
475538 void ngOnDestroy () {
476539 _disposer.dispose ();
0 commit comments