-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(sidenav): track sidenav visibility and enter / leave backdrop if needed #6486
feat(sidenav): track sidenav visibility and enter / leave backdrop if needed #6486
Conversation
function revalidateVisibility() { | ||
var lastValue = scope.isOpen; | ||
if (isHidden(element, true, true) && scope.isOpen == true) scope.isOpen = false; | ||
else if (!isHidden(element, true, true) && scope.isOpen == false) scope.isOpen = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brackets, scope.isOpen == true
is the same as scope.isOpen
and ternary operator
b89b094
to
950216f
Compare
@EladBezalel - Completed all your suggestions, thanks for reviewing! |
@@ -229,6 +229,9 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate, | |||
var lastParentOverFlow; | |||
var triggeringElement = null; | |||
var promise = $q.when(true); | |||
var skipSidenav = false; | |||
var skipNextUpdate = false; | |||
var $window = angular.element(window); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use DI to get $window
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be better, yes!
fcfff73
to
b2d0548
Compare
@EladBezalel - Fixed the suggestions + Improved |
*/ | ||
function isHidden(computedStyle, offsetParent) { | ||
if (computedStyle && window.getComputedStyle(element[0]).display === 'none') return true; | ||
if (offsetParent && element[0].offsetParent == null) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not doing
if (computedStyle && window.getComputedStyle(element[0]).display === 'none' ||
offsetParent && !element[0].offsetParent) {
return true;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's also possible, but I thought we should have a clear variant, because this method is really important and needs to be easy to understand, but if you want I can simplify the code?
b2d0548
to
9fd9ed6
Compare
scope.isOpen = false; | ||
} else if (!isHidden(true, true) && !scope.isOpen) { | ||
scope.isOpen = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that equals to:
scope.isOpen = !(isHidden(true, true) && scope.isOpen);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that works not, because I noticed that we only should update if that if statements are true, and we should not set the scope always
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry i couldn't understand, are we watching for isOpen
changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late answer. Yes updateIsOpen
(the actual method which triggers open and close animations) is called by watching isOpen
.
6e426c1
to
e8817ee
Compare
* @param computedStyle Check Computed Style | ||
* @param offsetParent Check Offset Parent | ||
*/ | ||
function isHidden(computedStyle, offsetParent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function is generic enough to be on the util service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely, should I add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍 Added to Util + added tests to validate the functionality.
e8817ee
to
8c2c521
Compare
} | ||
}); | ||
var actions = [isOpen ? $animate.enter(backdrop, parent) : $animate.leave(backdrop)]; | ||
if (!skipSidenav) actions.push(isOpen ? $animate.removeClass(element, 'md-closed') : $animate.addClass(element, 'md-closed')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please break this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✋ I should definitely use that conventions
(how I call it) in my next PR's so we would save much time 😄 - Already done in my newer PR's
8c2c521
to
94c0d6f
Compare
scope.isOpen = !!oldValue; | ||
return; | ||
} | ||
element.toggleClass('md-closed', wasClosed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you reuse that?
element.removeClass('md-closed');
if ($mdUtil.isHidden(element, true, false) && !skipSidenav) {
skipNextUpdate = true;
scope.isOpen = !!oldValue;
}
element.toggleClass('md-closed', wasClosed);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, won't work, because I need to revert the class before the scope watcher will be triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
element.removeClass('md-closed');
var isHidden = $mdUtil.isHidden(element, true, false);
element.toggleClass('md-closed', wasClosed);
if (isHidden && !skipSidenav) {
skipNextUpdate = true;
scope.isOpen = !!oldValue;
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs the return
, but yes this will work, because we check before removing the class 👍
-> Updated
@ThomasBurleson please review |
@EladBezalel I think this PR is not really a high priority, not much developers are complaining about it. What do you think? Should we remove it from the deprecation progress? |
This issue is closed as part of our ‘Surge Focus on Material 2' efforts. |
Fixes #4595