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

Commit 79d272d

Browse files
crisbetojelbourn
authored andcommitted
fix(sidenav): allow more time before triggering a resize of the children (#9809)
Currently the sidenav triggers the resize handlers whenever it is opened, however in most cases the element heights haven't been computed properly, causing wrong measurements. This PR moves the event trigger to an `rAF` call in order to give the browser more time to calculate the dimensions. Fixes #9745.
1 parent a5b8943 commit 79d272d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/components/sidenav/sidenav.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ function SidenavFocusDirective() {
243243
* - `<md-sidenav md-is-locked-open="$mdMedia('min-width: 1000px')"></md-sidenav>`
244244
* - `<md-sidenav md-is-locked-open="$mdMedia('sm')"></md-sidenav>` (locks open on small screens)
245245
*/
246-
function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInteraction, $animate, $compile,
247-
$parse, $log, $q, $document, $window) {
246+
function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInteraction, $animate,
247+
$compile, $parse, $log, $q, $document, $window, $$rAF) {
248248
return {
249249
restrict: 'E',
250250
scope: {
@@ -368,8 +368,12 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac
368368
]).then(function() {
369369
// Perform focus when animations are ALL done...
370370
if (scope.isOpen) {
371-
// Notifies child components that the sidenav was opened.
372-
ngWindow.triggerHandler('resize');
371+
$$rAF(function() {
372+
// Notifies child components that the sidenav was opened. Should wait
373+
// a frame in order to allow for the element height to be computed.
374+
ngWindow.triggerHandler('resize');
375+
});
376+
373377
focusEl && focusEl.focus();
374378
}
375379

src/components/sidenav/sidenav.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,16 @@ describe('mdSidenav', function() {
165165
});
166166

167167
it('should trigger a resize event when opening',
168-
inject(function($rootScope, $material, $window) {
168+
inject(function($rootScope, $animate, $$rAF, $window) {
169169
var el = setup('md-is-open="show"');
170170
var obj = { callback: function() {} };
171171

172172
spyOn(obj, 'callback');
173173
angular.element($window).on('resize', obj.callback);
174174

175175
$rootScope.$apply('show = true');
176-
$material.flushOutstandingAnimations();
176+
$animate.flush();
177+
$$rAF.flush();
177178

178179
expect(obj.callback).toHaveBeenCalled();
179180
angular.element($window).off('resize', obj.callback);

0 commit comments

Comments
 (0)