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

Commit 103e19c

Browse files
Benjamin MillagouSplaktar
authored andcommitted
fix(toolbar): prevent scroll shrink being applied to md-content within the toolbar
1 parent 3746148 commit 103e19c

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/components/toolbar/toolbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate) {
144144
*
145145
*/
146146
function onChangeScrollShrink(shrinkWithScroll) {
147-
var closestContent = element.parent().find('md-content');
147+
var closestContent = $mdUtil.getSiblings(element, 'md-content');
148148

149149
// If we have a content element, fake the call; this might still fail
150150
// if the content element isn't a sibling of the toolbar

src/core/util/util.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,22 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
603603
},
604604

605605
/**
606-
* getClosest replicates jQuery.closest() to walk up the DOM tree until it finds a matching
607-
* nodeName.
606+
* Get an element siblings matching a given tag name
607+
*
608+
* @param el Element to start walking the DOM from
609+
* @param tagName Tag name to match
610+
*/
611+
getSiblings: function getSiblings(element, tagName) {
612+
var upperCasedTagName = tagName.toUpperCase();
613+
if (element instanceof angular.element) element = element[0];
614+
var siblings = Array.prototype.filter.call(element.parentNode.children, function(node) {
615+
return element !== node && node.tagName.toUpperCase() === upperCasedTagName;
616+
});
617+
return angular.element(siblings);
618+
},
619+
620+
/*
621+
* getClosest replicates jQuery.closest() to walk up the DOM tree until it finds a matching nodeName
608622
*
609623
* @param {Node} el Element to start walking the DOM from
610624
* @param {string|function} validateWith If a string is passed, it will be evaluated against

src/core/util/util.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,31 @@ describe('util', function() {
672672
});
673673
});
674674

675+
describe('getSiblings', function() {
676+
var $mdUtil;
677+
678+
beforeEach(inject(function(_$mdUtil_) {
679+
$mdUtil = _$mdUtil_;
680+
}));
681+
682+
it('should be able to get the siblings (wihout source element) of a particular node type', function() {
683+
var parent = angular.element('<h1>');
684+
var element = angular.element('<h2>');
685+
var sibling = angular.element('<h2>');
686+
687+
parent.append(element);
688+
parent.append(sibling);
689+
690+
var result = $mdUtil.getSiblings(element, 'h2');
691+
692+
expect(result).toBeTruthy();
693+
expect(result.length).toBe(1);
694+
expect(result[0]).toBe(sibling[0]);
695+
696+
parent.remove();
697+
});
698+
});
699+
675700
describe('getClosest', function() {
676701
var $mdUtil;
677702

0 commit comments

Comments
 (0)