Skip to content

Commit

Permalink
fix(material/stepper): don't allow focus inside a hidden element (#21842
Browse files Browse the repository at this point in the history
)

The CSS `visibility` allows for a child element to become visible, even though its parent is
hidden. This becomes a problem for an expanded stepper inside a collapsed sidenav,
because it allows the user to tab into the stepper.

These changes resolve the issue by transitioning to `visibility: ''` which allows it to be
inherited.

Fixes #21831.

(cherry picked from commit 6f99852)
  • Loading branch information
crisbeto authored and mmalerba committed Feb 12, 2021
1 parent aa21fa1 commit 3f96885
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/material/stepper/stepper-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const matStepperAnimations: {
/** Animation that transitions the step along the X axis in a horizontal stepper. */
horizontalStepTransition: trigger('stepTransition', [
state('previous', style({transform: 'translate3d(-100%, 0, 0)', visibility: 'hidden'})),
state('current', style({transform: 'none', visibility: 'visible'})),
// Transition to '', rather than `visible`, because visibility on a child element overrides
// the one from the parent, making this element focusable inside of a `hidden` element.
state('current', style({transform: 'none', visibility: ''})),
state('next', style({transform: 'translate3d(100%, 0, 0)', visibility: 'hidden'})),
transition('* => *', animate('500ms cubic-bezier(0.35, 0, 0.25, 1)'))
]),
Expand All @@ -34,7 +36,9 @@ export const matStepperAnimations: {
verticalStepTransition: trigger('stepTransition', [
state('previous', style({height: '0px', visibility: 'hidden'})),
state('next', style({height: '0px', visibility: 'hidden'})),
state('current', style({height: '*', visibility: 'visible'})),
// Transition to '', rather than `visible`, because visibility on a child element overrides
// the one from the parent, making this element focusable inside of a `hidden` element.
state('current', style({height: '*', visibility: ''})),
transition('* <=> current', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
])
};

0 comments on commit 3f96885

Please sign in to comment.