Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): close the panel when pressing escape #3879

Merged
merged 3 commits into from
Apr 21, 2017

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Apr 3, 2017

  • Closes the md-select panel when pressing escape in the same way as the native select.
  • Adds a missing test to ensure that the select closes when tabbing out.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 3, 2017
@crisbeto crisbeto force-pushed the select-close-on-escape branch from 5fcaee8 to 9b8e789 Compare April 3, 2017 03:52
@@ -63,6 +64,9 @@ export class ListKeyManager<T extends CanDisable> {
case END:
this.setLastItemActive();
break;
case ESCAPE:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure the escape handling really belongs here; I think the problem is that while it's called ListKeyManager, it's really more like ListItemMovementKeyManager. The fact that there's both tab and escape as observables with no behavior seems like a code smell; perhaps the components should handle these things themselves.

@kara thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I see your point. We could have something like PopupKeyManager that inherits from the ListKeyManager instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, agree that this doesn't seem like a natural fit for a "list" key manager. I like the idea of having a PopupKeyManager, but inheriting from ListKeyManager doesn't seem like quite the right abstraction since sometimes we'll have popups that aren't lists. Maybe it could be a sibling? Though it's annoying to have to instantiate both a ListKeyManager and a PopupKeyManager.

I think it could still be useful to have a service for this (rather than keeping in components) because turning the key events into observables makes it easy to combine and pass them around later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't a service for this overkill? The only thing it would do is to expose Observable.fromEvent(document, keydown).filter(e => e.keyCode === ESCAPE). I think that at this point it would be better to just inline it or bake it into the overlay directive.

Copy link
Contributor

Choose a reason for hiding this comment

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

Overlay directive is an idea.

@crisbeto crisbeto force-pushed the select-close-on-escape branch 2 times, most recently from d55c6bd to 3b27179 Compare April 19, 2017 19:32
* Closes the `md-select` panel when pressing escape in the same way as the native select.
* Adds an `escape` observable to the `ListKeyManager`, because we'll likely need this on other components.
* Adds a missing test to ensure that the select closes when tabbing out.
@crisbeto crisbeto force-pushed the select-close-on-escape branch from 3b27179 to 66ab501 Compare April 19, 2017 19:34
@crisbeto crisbeto force-pushed the select-close-on-escape branch from 66ab501 to 4f5b2a3 Compare April 19, 2017 19:38
@crisbeto
Copy link
Member Author

Reworked this one as discussed @kara.

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM, just one small tweak. Apply merge label when ready.

@@ -249,6 +254,12 @@ export class ConnectedOverlayDirective implements OnDestroy {

this._position.withDirection(this.dir);
this._overlayRef.getState().direction = this.dir;
this._closeKeyListener = this._renderer.listen('document', 'keydown',
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is getting a bit long. Can you move this new block of code into its own method, maybe _initEscapeListener() or something?

@kara kara assigned crisbeto and unassigned jelbourn and kara Apr 20, 2017
@crisbeto crisbeto force-pushed the select-close-on-escape branch from 3cc69c6 to 3d06bdd Compare April 20, 2017 19:19
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Apr 20, 2017
@kara kara merged commit 94a2855 into angular:master Apr 21, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants