Skip to content

Commit

Permalink
[Fade] Fix child element appearing in the a11y tree if hidden visually
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 12, 2019
1 parent 6cbaabe commit 1ed6682
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/material-ui/src/Fade/Fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ import { reflow, getTransitionProps } from '../transitions/utils';
const styles = {
entering: {
opacity: 1,
visibility: 'visible',
},
entered: {
opacity: 1,
visibility: 'visible',
},
exited: {
visibility: 'hidden',
},
};

/**
* The Fade transition is used by the [Modal](/utils/modal/) component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*
* The `hidden` prop will be set on the child according to the `in` prop.
*/
class Fade extends React.Component {
handleEnter = node => {
Expand Down Expand Up @@ -50,22 +57,24 @@ class Fade extends React.Component {
};

render() {
const { children, onEnter, onExit, style: styleProp, theme, ...other } = this.props;
const { children, in: inProp, onEnter, onExit, style: styleProp, theme, ...other } = this.props;

const style = {
...styleProp,
...(React.isValidElement(children) ? children.props.style : {}),
};

return (
<Transition appear onEnter={this.handleEnter} onExit={this.handleExit} {...other}>
<Transition appear in={inProp} onEnter={this.handleEnter} onExit={this.handleExit} {...other}>
{(state, childProps) =>
React.cloneElement(children, {
style: {
display: 'initial',
opacity: 0,
...styles[state],
...style,
},
hidden: !inProp,
...childProps,
})
}
Expand Down
10 changes: 7 additions & 3 deletions packages/material-ui/src/Fade/Fade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ describe('<Fade />', () => {
</Fade>,
);
assert.deepEqual(wrapper.find('div').props().style, {
display: 'initial',
opacity: 0,
visibility: 'hidden',
});
});

Expand All @@ -97,18 +99,20 @@ describe('<Fade />', () => {
</Fade>,
);
assert.deepEqual(wrapper.find('div').props().style, {
display: 'initial',
opacity: 0,
visibility: 'hidden',
});
});
});

describe('accessiblity', () => {
it('will set `aria-hidden` acording to the `in` prop', () => {
it('will set `hidden` acording to the `in` prop', () => {
const wrapper = mount(<Fade {...defaultProps} />);
assert.strictEqual(wrapper.find('div').props()['aria-hidden'], false);
assert.strictEqual(wrapper.find('div').props().hidden, false);

wrapper.setProps({ in: false });
assert.strictEqual(wrapper.find('div').props()['aria-hidden'], true);
assert.strictEqual(wrapper.find('div').props().hidden, true);
});
});
});
2 changes: 2 additions & 0 deletions pages/api/fade.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Fade from '@material-ui/core/Fade';
The Fade transition is used by the [Modal](/utils/modal/) component.
It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.

The `hidden` prop will be set on the child according to the `in` prop.

## Props

| Name | Type | Default | Description |
Expand Down

0 comments on commit 1ed6682

Please sign in to comment.