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

[Accordion] Ensure AccordionSummary backwards compatible deprecation of classes.focused #27351

Merged
merged 3 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/pages/api-docs/accordion-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The `MuiAccordionSummary` name can be used for providing [default props](/custom
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the accordion summary. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name required">classes<abbr title="required">*</abbr></span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">expandIcon</span> | <span class="prop-type">node</span> | | The icon to display as the expand indicator. |
| <span class="prop-name">focusVisibleClassName</span> | <span class="prop-type">string</span> | | This prop can help identify which element has keyboard focus. The class name will be applied when the element gains the focus through keyboard interaction. It's a polyfill for the [CSS :focus-visible selector](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo). The rationale for using this feature [is explained here](https://github.com/WICG/focus-visible/blob/master/explainer.md). A [polyfill can be used](https://github.com/WICG/focus-visible) to apply a `focus-visible` class to other components if needed. |
| <span class="prop-name">IconButtonProps</span> | <span class="prop-type">object</span> | <span class="prop-default">{}</span> | Props applied to the `IconButton` element wrapping the expand icon. |
Expand All @@ -44,6 +44,7 @@ Any other props supplied will be provided to the root element ([ButtonBase](/api
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiAccordionSummary-root</span> | Styles applied to the root element.
| <span class="prop-name">expanded</span> | <span class="prop-name">.Mui-expanded</span> | Pseudo-class applied to the root element, children wrapper element and `IconButton` component if `expanded={true}`.
| <span class="prop-name">focused</span> | <span class="prop-name">.Mui-focused</span> | Pseudo-class applied to the ButtonBase root element if the button is keyboard focused.
| <span class="prop-name">focusVisible</span> | <span class="prop-name">.Mui-focusVisible</span> | Pseudo-class applied to the ButtonBase root element if the button is keyboard focused.
| <span class="prop-name">disabled</span> | <span class="prop-name">.Mui-disabled</span> | Pseudo-class applied to the root element if `disabled={true}`.
| <span class="prop-name">content</span> | <span class="prop-name">.MuiAccordionSummary-content</span> | Styles applied to the children wrapper element.
Expand Down
14 changes: 1 addition & 13 deletions packages/material-ui/src/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,7 @@ Accordion.propTypes = {
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: chainPropTypes(PropTypes.object, (props) => {
if (props.classes && props.classes.focused) {
throw new Error(
[
'Material-UI: the classes.focused key is deprecated.',
'Use `classes.focusedVisible` instead',
'The name of the pseudo-class was changed for consistency.',
].join('\n'),
);
}

return null;
}),
classes: PropTypes.object,
/**
* @ignore
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ declare const AccordionSummary: ExtendButtonBase<AccordionSummaryTypeMap>;
export type AccordionSummaryClassKey =
| 'root'
| 'expanded'
// deprecated
| 'focused'
| 'focusVisible'
| 'disabled'
| 'content'
Expand Down
19 changes: 17 additions & 2 deletions packages/material-ui/src/AccordionSummary/AccordionSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { chainPropTypes } from '@material-ui/utils';
import ButtonBase from '../ButtonBase';
import IconButton from '../IconButton';
import withStyles from '../styles/withStyles';
Expand All @@ -25,7 +26,7 @@ export const styles = (theme) => {
'&$expanded': {
minHeight: 64,
},
'&$focusVisible': {
'&$focused, &$focusVisible': {
backgroundColor: theme.palette.action.focus,
},
'&$disabled': {
Expand All @@ -35,6 +36,8 @@ export const styles = (theme) => {
/* Pseudo-class applied to the root element, children wrapper element and `IconButton` component if `expanded={true}`. */
expanded: {},
/* Pseudo-class applied to the ButtonBase root element if the button is keyboard focused. */
focused: {},
/* Pseudo-class applied to the ButtonBase root element if the button is keyboard focused. */
focusVisible: {},
/* Pseudo-class applied to the root element if `disabled={true}`. */
disabled: {},
Expand Down Expand Up @@ -140,7 +143,19 @@ AccordionSummary.propTypes = {
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
classes: chainPropTypes(PropTypes.object.isRequired, (props) => {
eps1lon marked this conversation as resolved.
Show resolved Hide resolved
if (props.classes.focused.indexOf(' ') !== -1) {
return new Error(
[
'Material-UI: The `classes.focused` key is deprecated.',
'Use `classes.focusVisible` instead.',
'The name of the pseudo-class was changed for consistency.',
].join('\n'),
);
}

return null;
}),
/**
* @ignore
*/
Expand Down
36 changes: 36 additions & 0 deletions packages/material-ui/src/AccordionSummary/AccordionSummary.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { spy } from 'sinon';
import { getClasses } from 'test/utils';
import createMount from 'test/utils/createMount';
import describeConformance from 'test/utils/describeConformance';
import consoleErrorMock from 'test/utils/consoleErrorMock';
import { createClientRender, fireEvent } from 'test/utils/createClientRender';
import Accordion from '../Accordion';
import AccordionSummary from './AccordionSummary';
Expand Down Expand Up @@ -98,4 +100,38 @@ describe('<AccordionSummary />', () => {

expect(handleFocusVisible.callCount).to.equal(1);
});

describe('warnings', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
});

it('should when using the `focused` class', () => {
PropTypes.checkPropTypes(
AccordionSummary.Naked.propTypes,
{
classes: {
focused:
// `Mui-focused` is the class generated by jss
// `focused` is the custom class
// i.e. this is the focused class when using `<AccordionSummary classes={{ focused: 'focused' }} />`
'Mui-focused focused',
},
children: <div />,
},
'prop',
'MockedName',
);

expect(consoleErrorMock.callCount()).to.equal(1);
expect(consoleErrorMock.messages()[0]).to.include(
'Material-UI: The `classes.focused` key is deprecated.\nUse `classes.focusVisible` instead.',
);
});
});
});