-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(datepicker): restore focus to trigger element #4804
Conversation
crisbeto
commented
May 25, 2017
•
edited
Loading
edited
- The datepicker now restores focus to whatever element was focused before it was open.
- Adds a test for the functionality that closes the datepicker when pressing escape.
I think for datepicker we don't want to close on tab (see various accessible datepicker implementations: http://www.webaxe.org/accessible-date-pickers/) |
In that case we'd need to trap focus inside the popup, otherwise it goes out of the page. |
I believe it does: https://github.com/angular/material2/blob/master/src/lib/datepicker/datepicker-content.html#L1 The behavior might be a little weird though, because the dialog (which we use for the touch UI) does its own focus trapping. What I'd like to eventually do is create a |
It doesn't look like the focus trapping works when it's not in touch mode. Should I remove the tabbing behavior from this PR and try address the focus trapping separately? |
yeah sgtm |
de49d3e
to
42cb003
Compare
Reverted the tabbing behavior @mmalerba. |
src/lib/datepicker/datepicker.ts
Outdated
@@ -30,7 +32,7 @@ import {Subscription} from 'rxjs/Subscription'; | |||
import {MdDialogConfig} from '../dialog/dialog-config'; | |||
import {DateAdapter} from '../core/datetime/index'; | |||
import {createMissingDateImplError} from './datepicker-errors'; | |||
import {ESCAPE} from '../core/keyboard/keycodes'; | |||
import {ESCAPE, TAB} from '../core/keyboard/keycodes'; |
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.
TAB no longer needed
@@ -226,6 +229,11 @@ export class MdDatepicker<D> implements OnDestroy { | |||
if (this._calendarPortal && this._calendarPortal.isAttached) { | |||
this._calendarPortal.detach(); | |||
} | |||
if (this._focusedElementBeforeOpen && 'focus' in this._focusedElementBeforeOpen) { |
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 is the 'focus' in
part needed?
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's there for IE's sake. In some cases it assigns the activeElement
to something that doesn't have a focus
method. It's what was throwing that 4mb error in the CI.
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.
interesting, good to know
Fixes focus trapping not working inside the datepicker in popup mode due to the A11yModule not being imported. Relates to angular#4804.
Fixes focus trapping not working inside the datepicker in popup mode due to the A11yModule not being imported. Relates to #4804.
Also got this focus problem, pretty important for us. Can someone please rebase and merge it? |
* The datepicker now restores focus to whatever element was focused before it was open. * Adds a test for the functionality that closes the datepicker when pressing escape.
Works very good, thank you for merging this. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |