Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit d641433

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(toast): Hide scrollbars during animation.
During animation, certain browsers would show scroll bars if the toast was positioned at the bottom of the parent container. Fix by adding a class to the parent which sets the overflow to hidden only during the animations. Also, update documentation with notes about positioning and recommendations. Fixes #2936. Closes #6017
1 parent 5d34eff commit d641433

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/components/toast/toast.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,41 @@ function MdToastDirective($mdToast) {
4040
* - For a toast action, use element with class `md-action`.
4141
* - Add the class `md-capsule` for curved corners.
4242
*
43+
* ## Parent container notes
44+
*
45+
* The toast is positioned using absolute positioning relative to it's first non-static parent
46+
* container. Thus, if the requested parent container uses static positioning, we will temporarily
47+
* set it's positioning to `relative` while the toast is visible and reset it when the toast is
48+
* hidden.
49+
*
50+
* Because of this, it is usually best to ensure that the parent container has a fixed height and
51+
* prevents scrolling by setting the `overflow: hidden;` style. Since the position is based off of
52+
* the parent's height, the toast may be mispositioned if you allow the parent to scroll.
53+
*
54+
* You can, however, have a scrollable element inside of the container; just make sure the
55+
* container itself does not scroll.
56+
*
57+
* <hljs lang="html">
58+
* <div layout-fill id="toast-container">
59+
* <md-content>
60+
* I can have lots of content and scroll!
61+
* </md-content>
62+
* </div>
63+
* </hljs>
64+
*
65+
* Additionally, during animation, we will add the `md-toast-animating` class to the parent
66+
* container. This defines a simple rule of `overflow: hidden !important;` to ensure that
67+
* scrollbars are not visible on the parent during animation if you use a different overflow style.
68+
*
69+
* If you need to override this, you can use the following CSS, but be aware that it may cause
70+
* scrollbars to intermittently appear.
71+
*
72+
* <hljs lang="css">
73+
* .md-toast-animating {
74+
* overflow: auto !important;
75+
* }
76+
* </hljs>
77+
*
4378
* @usage
4479
* <hljs lang="html">
4580
* <div ng-controller="MyController">
@@ -298,15 +333,20 @@ function MdToastProvider($$interimElementProvider) {
298333
return 'md-' + pos;
299334
}).join(' '));
300335

301-
return $animate.enter(element, options.parent);
336+
if (options.parent) options.parent.addClass('md-toast-animating');
337+
return $animate.enter(element, options.parent).then(function() {
338+
if (options.parent) options.parent.removeClass('md-toast-animating');
339+
});
302340
}
303341

304342
function onRemove(scope, element, options) {
305343
element.off(SWIPE_EVENTS, options.onSwipe);
344+
if (options.parent) options.parent.addClass('md-toast-animating');
306345
if (options.openClass) options.parent.removeClass(options.openClass);
307346

308347
return ((options.$destroy == true) ? element.remove() : $animate.leave(element))
309348
.then(function () {
349+
if (options.parent) options.parent.removeClass('md-toast-animating');
310350
if ($mdUtil.hasComputedStyle(options.parent, 'position', 'static')) {
311351
options.parent.css('position', '');
312352
}

src/components/toast/toast.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,9 @@ md-toast {
152152
border: 1px solid #fff;
153153
}
154154
}
155+
156+
157+
// While animating, set the toast parent's overflow to hidden so scrollbars do not appear
158+
.md-toast-animating {
159+
overflow: hidden !important;
160+
}

0 commit comments

Comments
 (0)