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

chore(modal): added deprecation warning for iconDescription #9787

Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3778,9 +3778,7 @@ Map {
"hasScrollingContent": Object {
"type": "bool",
},
"iconDescription": Object {
"type": "string",
},
"iconDescription": [Function],
"id": Object {
"type": "string",
},
Expand Down
14 changes: 7 additions & 7 deletions packages/react/src/components/Modal/Modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ describe('Modal', () => {
expect(getModal(modal).props().id).toEqual('modal-1');
});

it('has the expected default iconDescription', () => {
expect(mounted.props().iconDescription).toEqual('Close');
it('has the expected default ariaLabel', () => {
expect(mounted.props().ariaLabel).toEqual('Close');
});

it('adds new iconDescription when passed via props', () => {
mounted.setProps({ iconDescription: 'new description' });
expect(mounted.props().iconDescription).toEqual('new description');
it('adds new ariaLabel when passed via props', () => {
mounted.setProps({ ariaLabel: 'new description' });
expect(mounted.props().ariaLabel).toEqual('new description');
});

it('should have iconDescription match Icon component description prop', () => {
it('should have ariaLabel match Icon component description prop', () => {
const description = mounted.find(Close20).props()['aria-label'];
const matches = mounted.props().iconDescription === description;
const matches = mounted.props().ariaLabel === description;
expect(matches).toEqual(true);
});

Expand Down
20 changes: 14 additions & 6 deletions packages/react/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ export default class Modal extends Component {
hasScrollingContent: PropTypes.bool,

/**
* Provide a description for "close" icon that can be read by screen readers
* The iconDescription prop is deprecated. Use aria-label, aria-labelledby, or aria-describedby to label your component
*/
iconDescription: PropTypes.string,
iconDescription: deprecate(
PropTypes.string,
'The iconDescription prop is no longer needed and can be safely removed. This prop will be removed in the next major release of Carbon.'
),

/**
* Specify the DOM element ID of the top-level node.
Expand Down Expand Up @@ -217,7 +220,8 @@ export default class Modal extends Component {
primaryButtonDisabled: false,
onKeyDown: () => {},
passiveModal: false,
iconDescription: 'Close',
// iconDescription is deprecated in v11 use aria-label instead
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, do we usually remove the default prop value even if the prop hasn't been deprecated yet?

// iconDescription: 'Close',
modalHeading: '',
modalLabel: '',
preventCloseOnClickOutside: false,
Expand Down Expand Up @@ -409,16 +413,20 @@ export default class Modal extends Component {
Array.isArray(secondaryButtons) && secondaryButtons.length === 2,
});

// ['aria-label']: ariaLabel,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be commented out?


const modalButton = (
<button
className={this.modalCloseButtonClass}
type="button"
onClick={onRequestClose}
title={iconDescription}
aria-label={iconDescription}
// iconDescription is deprecated in v11. Use ariaLabel instead.
title={ariaLabel ? ariaLabel : iconDescription}
// iconDescription is deprecated in v11. Use ariaLabel instead.
aria-label={ariaLabel ? ariaLabel : iconDescription}
ref={this.button}>
<Close20
aria-label={iconDescription}
aria-hidden="true"
className={`${this.modalCloseButtonClass}__icon`}
/>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ exports[`ModalWrapper should render 1`] = `
<Modal
aria-label="test modal"
hasScrollingContent={false}
iconDescription="Close"
id="modal"
modalHeading="Transactional Modal"
modalLabel="Test Modal Label"
Expand Down Expand Up @@ -110,18 +109,16 @@ exports[`ModalWrapper should render 1`] = `
Transactional Modal
</h3>
<button
aria-label="Close"
className="bx--modal-close"
onClick={[Function]}
title="Close"
type="button"
>
<ForwardRef(Close20)
aria-label="Close"
aria-hidden="true"
className="bx--modal-close__icon"
>
<Icon
aria-label="Close"
aria-hidden="true"
className="bx--modal-close__icon"
fill="currentColor"
height={20}
Expand All @@ -131,13 +128,12 @@ exports[`ModalWrapper should render 1`] = `
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-label="Close"
aria-hidden={true}
className="bx--modal-close__icon"
fill="currentColor"
focusable="false"
height={20}
preserveAspectRatio="xMidYMid meet"
role="img"
viewBox="0 0 32 32"
width={20}
xmlns="http://www.w3.org/2000/svg"
Expand Down