Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

feat(sidenav): add disable click and escape event #11165

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

FjVillar
Copy link
Contributor

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:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Infrastructure changes
[ ] Other... Please describe:

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 pressing ESC. 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?


[ ] Yes
[x] No

Other information

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot googlebot added the cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ label Mar 13, 2018
@FjVillar
Copy link
Contributor Author

FjVillar commented Mar 13, 2018

I have tried to fix the CLA, lets see if it works...

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ and removed cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ labels Mar 13, 2018
@FjVillar
Copy link
Contributor Author

FjVillar commented Mar 13, 2018

Seems like i'm having the same issue as this other PR #11166, any clue on what could be the problem?

@Splaktar
Copy link
Member

@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!

@Splaktar Splaktar self-assigned this Mar 13, 2018
@Splaktar Splaktar added needs: review This PR is waiting on review from the team type: enhancement P4: minor Minor issues. May not be fixed without community contributions. labels Mar 13, 2018
@Splaktar Splaktar added this to the 1.1.9 milestone Mar 13, 2018
@Splaktar
Copy link
Member

Please add a blank line and then Closes #4699 to the bottom of your commit message.

@Splaktar
Copy link
Member

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.

@FjVillar FjVillar force-pushed the addDisableClickKeyToSidenav branch from 91e8f6b to 1559af9 Compare March 14, 2018 07:20
@FjVillar
Copy link
Contributor Author

I did update the commit message : )

@FjVillar
Copy link
Contributor Author

FjVillar commented Mar 19, 2018

I think the Travis issue returned, is already fixed? @Splaktar

Copy link
Member

@Splaktar Splaktar left a 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.
Copy link
Member

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/>
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.

@@ -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.
Copy link
Member

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?

Copy link
Contributor Author

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'])
Copy link
Member

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.

Copy link
Contributor Author

@FjVillar FjVillar Mar 26, 2018

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 ?

Copy link
Member

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">
Copy link
Member

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 :)

Copy link
Contributor Author

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?

Copy link
Member

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.

@@ -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
Copy link
Member

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"

@Splaktar
Copy link
Member

Yes, please ignore these TravisCI failures.

@Splaktar Splaktar added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs and removed needs: review This PR is waiting on review from the team labels Mar 22, 2018
@FjVillar FjVillar force-pushed the addDisableClickKeyToSidenav branch 2 times, most recently from 3ba974e to 3f1286a Compare March 26, 2018 10:17
@FjVillar
Copy link
Contributor Author

@Splaktar I have done the requested changes. If you see something It could be improved I will be happy to do it.

Copy link
Member

@Splaktar Splaktar left a 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.
Copy link
Member

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) {
Copy link
Member

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.

@@ -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.
Copy link
Member

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'".

@@ -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
Copy link
Member

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',
Copy link
Member

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.

@FjVillar FjVillar force-pushed the addDisableClickKeyToSidenav branch from 3f1286a to 3b31883 Compare March 27, 2018 07:25
@FjVillar
Copy link
Contributor Author

Lets check it now @Splaktar. Thanks for your review!

Copy link
Member

@Splaktar Splaktar left a 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.
Copy link
Member

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".

@FjVillar FjVillar force-pushed the addDisableClickKeyToSidenav branch from 3b31883 to a64b647 Compare March 27, 2018 10:07
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
@FjVillar FjVillar force-pushed the addDisableClickKeyToSidenav branch from a64b647 to 632caf7 Compare March 27, 2018 10:59
@FjVillar
Copy link
Contributor Author

Done!

Copy link
Member

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review pr: lgtm This PR has been approved by the reviewer and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs labels Mar 27, 2018
@Splaktar
Copy link
Member

Thanks, looks good! I just re-ran the 3 failing builds (due to 504 gateway timeouts).

@Splaktar
Copy link
Member

Yay, tests are finally green! Submitted to presubmit. Thank you for hanging in there!

@josephperrott josephperrott merged commit fae4042 into angular:master Mar 29, 2018
@FjVillar FjVillar deleted the addDisableClickKeyToSidenav branch April 1, 2018 18:30
chmelevskij pushed a commit to chmelevskij/material that referenced this pull request Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ P4: minor Minor issues. May not be fixed without community contributions. pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants