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

Commit 989f81e

Browse files
crisbetokara
authored andcommitted
fix(sidenav): notify child components when the element is opened (#9512)
Triggers a resize event whenever a sidenav is opened. This allows components like virtualRepeat and textarea to resize properly. Fixes #7309.
1 parent dc6b10c commit 989f81e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/components/sidenav/sidenav.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +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, $animate, $compile, $parse, $log, $q, $document) {
246+
function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming,
247+
$animate, $compile, $parse, $log, $q, $document, $window) {
247248
return {
248249
restrict: 'E',
249250
scope: {
@@ -268,6 +269,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
268269
var previousContainerStyles;
269270
var promise = $q.when(true);
270271
var isLockedOpenParsed = $parse(attr.mdIsLockedOpen);
272+
var ngWindow = angular.element($window);
271273
var isLocked = function() {
272274
return isLockedOpenParsed(scope.$parent, {
273275
$media: function(arg) {
@@ -365,6 +367,8 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
365367
]).then(function() {
366368
// Perform focus when animations are ALL done...
367369
if (scope.isOpen) {
370+
// Notifies child components that the sidenav was opened.
371+
ngWindow.triggerHandler('resize');
368372
focusEl && focusEl.focus();
369373
}
370374

src/components/sidenav/sidenav.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ describe('mdSidenav', function() {
164164
});
165165
});
166166

167+
it('should trigger a resize event when opening',
168+
inject(function($rootScope, $material, $window) {
169+
var el = setup('md-is-open="show"');
170+
var obj = { callback: function() {} };
171+
172+
spyOn(obj, 'callback');
173+
angular.element($window).on('resize', obj.callback);
174+
175+
$rootScope.$apply('show = true');
176+
$material.flushOutstandingAnimations();
177+
178+
expect(obj.callback).toHaveBeenCalled();
179+
angular.element($window).off('resize', obj.callback);
180+
})
181+
);
182+
167183
describe('parent scroll prevention', function() {
168184
it('should prevent scrolling on the parent element', inject(function($rootScope) {
169185
var parent = setup('md-is-open="isOpen"').parent()[0];

0 commit comments

Comments
 (0)