Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

fix(dialog): Handle focus trapping correctly #491

Merged
merged 1 commit into from
Apr 10, 2017
Merged

Conversation

traviskaufman
Copy link
Contributor

  • Remove all focus trapping logic within the dialog foundation,
    replacing it with adapter methods set up to handle focus trapping.
  • Add focus-trap as a dependency and use
    it for implementing the adapter methods at the component level
  • Add a util method for easily creating properly configured focus-trap
    instances that framework components can use when implementing their
    adapters.
  • Remove use of aria-hidden and replace with visibility styles so that
    tab-focusing works correctly when dialog is hidden.
  • [techdebt] Remove all unnecessary adapter API methods and dead code
  • [techdebt] Make grammatical corrections in README
  • [techdebt] Remove unneeded passive event listener logic for dialog handlers
  • [demos] Fix ripples incorrectly appearing in buttons within the demos.

Resolves #424
Resolves #409
Resolves #426

NOTE: The additional issues resolved are by-products from switching to
focus-trap.

BREAKING CHANGE: There are a few changes that need to be taken into
account for this commit:

  • Dialogs no longer require an aria-hidden="true" attribute.
  • Dialogs do require a style="visibility:hidden" attribute for
    correct first render.
  • trapFocusOnSurface and untrapFocusOnSurface methods must be
    implemented for the adapter
  • hasClass, setAttr, registerFocusTrappingHandler,
    deregisterFocusTrappingHandler, numFocusableTargets,
    setDialogFocusFirstTarget, setInitialFocus,
    getFocusableElements, saveElementTabState,
    restoreElementTabState, makeElementUntabbable, setBodyAttr,
    rmBodyAttr, getFocusedTarget, and setFocusedTarget have all been
    removed from the adapter.
  • applyPassive, saveElementTabState, and restoreElementTabState
    have all been removed from mdcDialog.util.

@traviskaufman traviskaufman requested a review from amsheehan April 7, 2017 21:51
@codecov-io
Copy link

codecov-io commented Apr 7, 2017

Codecov Report

Merging #491 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #491      +/-   ##
==========================================
- Coverage   99.17%   99.13%   -0.04%     
==========================================
  Files          40       40              
  Lines        2050     1972      -78     
  Branches      261      250      -11     
==========================================
- Hits         2033     1955      -78     
  Misses         17       17
Impacted Files Coverage Δ
packages/mdc-dialog/constants.js 100% <ø> (ø) ⬆️
packages/mdc-dialog/foundation.js 100% <100%> (ø) ⬆️
packages/mdc-dialog/index.js 100% <100%> (ø) ⬆️
packages/mdc-dialog/util.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90f136c...a004f17. Read the comment docs.

Copy link
Contributor

@amsheehan amsheehan left a comment

Choose a reason for hiding this comment

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

Two nits, otherwise looks good.


In order for dialogs to be fully accessible, they must conform to the guidelines outlined in
https://www.w3.org/TR/wai-aria-practices/#dialog_modal. The main implication of these guidelines is
Copy link
Contributor

Choose a reason for hiding this comment

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

"The main implication of these guidelines is that such that the only focusable elements..."

Should read:

"The main implication of these guidelines is that the only focusable elements..."

});

test('#close makes elements untabbable', () => {
test('#close removes the scroll lock class from dialog background', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is on me for coming up with the naming convention for the component, but potentially we should rephrase "background" to "content underneath dialog" for the test description. Aria calls things behind the dialog "background" which is why I called it this to begin with, but I feel this could too easily be confused with the concept of a dialog backdrop, which we also have.

Copy link
Contributor Author

@traviskaufman traviskaufman Apr 10, 2017

Choose a reason for hiding this comment

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

np! Changing background to content underneath the dialog

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually just changed it to the body to match the spec description above

- Remove all focus trapping logic within the dialog foundation,
  replacing it with adapter methods set up to handle focus trapping.
- Add [focus-trap](https://npmjs.com/focus-trap) as a dependency and use
  it for implementing the adapter methods at the component level
- Add a util method for easily creating properly configured focus-trap
  instances that framework components can use when implementing their
  adapters.
- Remove use of aria-hidden and replace with visibility styles so that
  tab-focusing works correctly when dialog is hidden.
- [techdebt] Remove all unnecessary adapter API methods and dead code
- [techdebt] Make grammatical corrections in README
- [techdebt] Remove unneeded passive event listener logic for dialog handlers
- [demos] Fix ripples incorrectly appearing in buttons within the demos.

Resolves #424
Resolves #409
Resolves #426

NOTE: The additional issues resolved are by-products from switching to
focus-trap.

BREAKING CHANGE: There are a few changes that need to be taken into
account for this commit:

- Dialogs no longer require an `aria-hidden="true"` attribute.
- Dialogs _do_ require a `style="visibility:hidden"` attribute for
  correct first render.
- `trapFocusOnSurface` and `untrapFocusOnSurface` methods must be
  implemented for the adapter
- `hasClass`, `setAttr`, `registerFocusTrappingHandler`,
  `deregisterFocusTrappingHandler`, `numFocusableTargets`,
  `setDialogFocusFirstTarget`, `setInitialFocus`,
  `getFocusableElements`, `saveElementTabState`,
  `restoreElementTabState`, `makeElementUntabbable`, `setBodyAttr`,
  `rmBodyAttr`, `getFocusedTarget`, and `setFocusedTarget` have all been
  removed from the adapter.
- `applyPassive`, `saveElementTabState`, and `restoreElementTabState`
  have all been removed from `mdcDialog.util`.
@traviskaufman traviskaufman merged commit 12bd03e into master Apr 10, 2017
@traviskaufman traviskaufman deleted the fix/dialog-focus branch April 10, 2017 14:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants