-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(sidenav): add disable click and escape event #11165
feat(sidenav): add disable click and escape event #11165
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
I have tried to fix the CLA, lets see if it works... |
CLAs look good, thanks! |
Seems like i'm having the same issue as this other PR #11166, any clue on what could be the problem? |
@FjVillar don't worry about the snapshot failures at this time. There is something wrong with the AngularJS snapshots and the team is investigating. Thank you for your contribution! |
Please add a blank line and then |
I think that Travis might be fixed, but may not work until you force push up your changes after the review. I wouldn't worry about it for now. |
91e8f6b
to
1559af9
Compare
I did update the commit message : ) |
I think the Travis issue returned, is already fixed? @Splaktar |
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 is a good start, thank you! I would like to refine the API, demo, and documentation a bit.
|
||
<md-content layout-margin=""> | ||
<p> | ||
This sidenav is still showing the backdrop, but users can't close the sidenav on clicking or pressing 'ESC' button. |
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.
Let's change this a little for clarity "This sidenav is showing the backdrop, but users can't close the sidenav by clicking on the backdrop or pressing 'ESC' button."
|
||
<div layout="column" layout-align="top center"> | ||
<p> | ||
Developers can also disable the click and 'Escape' button events.<br/> |
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.
Let's change this to "Developers can disable closing the sidenav on backdrop clicks and 'Escape' key events."
<div layout="column" layout-align="top center"> | ||
<p> | ||
Developers can also disable the click and 'Escape' button events.<br/> | ||
This will disable the functionality to click outside to close the sidenav. |
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 second line is probably not needed then.
|
||
<div> | ||
<md-button ng-click="toggleSidenav()" class="md-raised"> | ||
Toggle Sidenav |
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.
Let's call this Open Sidenav
.
src/components/sidenav/sidenav.js
Outdated
@@ -231,6 +231,7 @@ function SidenavFocusDirective() { | |||
* | |||
* @param {expression=} md-is-open A model bound to whether the sidenav is opened. | |||
* @param {boolean=} md-disable-backdrop When present in the markup, the sidenav will not show a backdrop. | |||
* @param {boolean=} md-disable-click-key-events When present in the markup, the click outside and 'ESC' button will not close the sidenav. |
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 we rename this to md-disable-close-events
? So it would be possible to close via toggle
or open
functions, but not via events (backdrop click or escape key).
With a description like: "When present in the markup, clicking the backdrop or pressing the 'ESC' key will not close the sidenav."
Does this make sense? Do you have any ideas for a better API?
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, it sounds good to me :).
@@ -0,0 +1,11 @@ | |||
angular | |||
.module('sidenavDemo3', ['ngMaterial']) |
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.
I would like to get rid of this sidenavDemoX
pattern and name the module after the demo, i.e. sidenavDisableCloseEvents
.
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.
What do you think about a pattern like this customSidenavDemo
, basicSidenavDemo
, disableCloseEventsSidenavDemo
?
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.
Sounds good!
</p> | ||
|
||
<div> | ||
<md-button ng-click="toggleSidenav()" class="md-raised"> |
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.
Let's throw a md-primary
on here too :)
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.
It this also wanted in the others demo buttons?
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 could do it in the custom sidenav demo's "Toggle Sidenav" button, but I would leave the other flat buttons.
src/components/sidenav/sidenav.js
Outdated
@@ -302,6 +303,12 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac | |||
if (!attr.hasOwnProperty('mdDisableBackdrop')) { | |||
backdrop = $mdUtil.createBackdrop(scope, "md-sidenav-backdrop md-opaque ng-enter"); | |||
} | |||
|
|||
// If md-disable-click-key-events is set on the sidenav we will disable | |||
// click and Escape events |
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.
"backdrop click and Escape key events"
Yes, please ignore these TravisCI failures. |
3ba974e
to
3f1286a
Compare
@Splaktar I have done the requested changes. If you see something It could be improved I will be happy to do 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.
Thank you for the updates. This is heading in the right direction. I had a few more comments mostly related to consistency.
<md-content layout-margin=""> | ||
<p> | ||
This sidenav is showing the backdrop, but users can't close the | ||
sidenav by clicking on the backdrop or pressing 'ESC' button. |
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 use "'Escape' key" instead of "'ESC' button" to be consistent with the other messaging (like on line 29).
@@ -0,0 +1,11 @@ | |||
angular | |||
.module('disableCloseEventsSidenavDemo', ['ngMaterial']) | |||
.controller('AppCtrl', function ($scope, $timeout, $mdSidenav) { |
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.
It looks like $timeout
isn't used? If so, please remove it.
src/components/sidenav/sidenav.js
Outdated
@@ -231,6 +231,7 @@ function SidenavFocusDirective() { | |||
* | |||
* @param {expression=} md-is-open A model bound to whether the sidenav is opened. | |||
* @param {boolean=} md-disable-backdrop When present in the markup, the sidenav will not show a backdrop. | |||
* @param {boolean=} md-disable-close-events When present in the markup, clicking the backdrop or pressing the 'ESC' key will not close the sidenav. |
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.
We should be consistent on calling it "'Escape'" instead of "'ESC'".
src/components/sidenav/sidenav.js
Outdated
@@ -351,8 +358,12 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInterac | |||
var focusEl = $mdUtil.findFocusTarget(element) || $mdUtil.findFocusTarget(element,'[md-sidenav-focus]') || element; | |||
var parent = element.parent(); | |||
|
|||
parent[isOpen ? 'on' : 'off']('keydown', onKeyDown); | |||
if (backdrop) backdrop[isOpen ? 'on' : 'off']('click', close); | |||
// If the user hasn't set disable close events property we are adding |
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.
Let's add a "the" in there. "If the user hasn't set the disable close events property we are adding"
@@ -59,6 +59,40 @@ describe('mdSidenav', function() { | |||
expect($rootScope.show).toBe(false); | |||
})); | |||
|
|||
describe('disable click and ESC key events if md-disable-close-events is set to 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.
Let's use Escape instead of ESC here too.
3f1286a
to
3b31883
Compare
Lets check it now @Splaktar. Thanks for your review! |
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.
Almost there! I just had one minor docs comment.
<md-content layout-margin=""> | ||
<p> | ||
This sidenav is showing the backdrop, but users can't close the | ||
sidenav by clicking on the backdrop or pressing 'Escape' key button. |
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.
Let's do "pressing the 'Escape' key." This adds "the" and removes "button".
3b31883
to
a64b647
Compare
Add a property to disable the click and Escape button actions to prevent the user from closing the sidenav but still showing the backdrop. Closes angular#4699
a64b647
to
632caf7
Compare
Done! |
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.
LGTM
Thanks, looks good! I just re-ran the 3 failing builds (due to 504 gateway timeouts). |
Yay, tests are finally green! Submitted to presubmit. Thank you for hanging in there! |
Add a property to disable the click and Escape button actions to prevent the user
from closing the sidenav but still showing the backdrop.
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number:
#4699
What is the new behavior?
Now it is possible to add a new attribute called
md-disable-click-escape-events
to prevent the sidenav from closing when clicking on the backdrop or pressingESC
. If you add it to a md-sidenav it will still show the backdrop but the user won't be able to close it with the previous named events and will force the user to close it by some button or action you've created on your sidenav.Does this PR introduce a breaking change?
Other information