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(datepicker): restore focus to trigger element #4804

Merged
merged 2 commits into from
Jun 16, 2017

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented May 25, 2017

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

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 25, 2017
@crisbeto crisbeto changed the title fix(datepicker): restore focus to trigger element and close when pres… fix(datepicker): restore focus to trigger element and close when pressing tab May 25, 2017
@crisbeto crisbeto added the Accessibility This issue is related to accessibility (a11y) label May 25, 2017
@mmalerba
Copy link
Contributor

I think for datepicker we don't want to close on tab (see various accessible datepicker implementations: http://www.webaxe.org/accessible-date-pickers/)

@crisbeto
Copy link
Member Author

In that case we'd need to trap focus inside the popup, otherwise it goes out of the page.

@mmalerba
Copy link
Contributor

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 MdPopup, similar to MdDialog. Things like select and auto-complete could take advantage of this as well. One of the APIs on MdPopup would allow you to set it to floating mode where its acts more like a dialog (not attached to the input) that way datepicker could just use the popup instead of the overlay/dialog hybrid approach

@crisbeto
Copy link
Member Author

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?

@mmalerba
Copy link
Contributor

yeah sgtm

@crisbeto crisbeto force-pushed the datepicker-tab branch 2 times, most recently from de49d3e to 42cb003 Compare May 25, 2017 18:44
@crisbeto crisbeto changed the title fix(datepicker): restore focus to trigger element and close when pressing tab fix(datepicker): restore focus to trigger element May 25, 2017
@crisbeto
Copy link
Member Author

Reverted the tabbing behavior @mmalerba.

@@ -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';
Copy link
Contributor

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

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?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, good to know

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels May 25, 2017
crisbeto added a commit to crisbeto/material2 that referenced this pull request May 27, 2017
Fixes focus trapping not working inside the datepicker in popup mode due to the A11yModule not being imported.

Relates to angular#4804.
andrewseguin pushed a commit that referenced this pull request Jun 5, 2017
Fixes focus trapping not working inside the datepicker in popup mode due to the A11yModule not being imported.

Relates to #4804.
@andrewseguin andrewseguin added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Jun 9, 2017
@BaimosTechnologies
Copy link

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.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Jun 16, 2017
@kara kara merged commit 8860090 into angular:master Jun 16, 2017
@BaimosTechnologies
Copy link

Works very good, thank you for merging this.

@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
Accessibility This issue is related to accessibility (a11y) 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.

6 participants