Skip to content

Commit

Permalink
feat(modal): deprecate iconDescription (#9828)
Browse files Browse the repository at this point in the history
* feat(modal): deprecate iconDescription new tests

* feat(modal): update test

co-authored: @aledavila

* feat(modal): updated snappy

* Update packages/react/src/components/Modal/Modal-test.js

Co-authored-by: DAK <40970507+dakahn@users.noreply.github.com>

* feat(modal): added test

* feat(modal): updated snappy

* feat(Modal): aria lable on the close icon

* feat(Modal): updated wrapper test

Co-authored-by: DAK <40970507+dakahn@users.noreply.github.com>
  • Loading branch information
sstrubberg and dakahn authored Oct 21, 2021
1 parent 559412c commit a9c13ff
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3811,7 +3811,6 @@ Map {
"Modal" => Object {
"defaultProps": Object {
"hasScrollingContent": false,
"iconDescription": "Close",
"modalHeading": "",
"modalLabel": "",
"onKeyDown": [Function],
Expand Down Expand Up @@ -3841,9 +3840,7 @@ Map {
"hasScrollingContent": Object {
"type": "bool",
},
"iconDescription": Object {
"type": "string",
},
"iconDescription": [Function],
"id": Object {
"type": "string",
},
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Modal/Modal-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const props = {
'[data-modal-primary-focus]'
),
size: select('Size (size)', sizes, 'md'),
iconDescription: text('Close icon description (iconDescription)', 'Close'),
onBlur: action('onBlur'),
onClick: action('onClick'),
onFocus: action('onFocus'),
Expand Down
17 changes: 6 additions & 11 deletions packages/react/src/components/Modal/Modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@ describe('Modal', () => {
expect(getModal(modal).props().id).toEqual('modal-1');
});

it('has the expected default iconDescription', () => {
expect(mounted.props().iconDescription).toEqual('Close');
it('should not place the svg icon in the accessibility tree', () => {
const ariaHidden = mounted.find(Close20).props()['aria-hidden'];
expect(ariaHidden).toEqual('true');
});

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

it('should have iconDescription match Icon component description prop', () => {
const description = mounted.find(Close20).props()['aria-label'];
const matches = mounted.props().iconDescription === description;
expect(matches).toEqual(true);
it("icon isn't a focusable tab stop", () => {
const icon = mounted.find(Close20).props().tabIndex;
expect(icon).toEqual('-1');
});

it('enables primary button by default', () => {
Expand Down
14 changes: 9 additions & 5 deletions packages/react/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export default class Modal extends Component {
/**
* Provide a description for "close" icon that can be read by screen readers
*/
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 @@ -220,7 +223,6 @@ export default class Modal extends Component {
primaryButtonDisabled: false,
onKeyDown: () => {},
passiveModal: false,
iconDescription: 'Close',
modalHeading: '',
modalLabel: '',
preventCloseOnClickOutside: false,
Expand Down Expand Up @@ -417,11 +419,13 @@ export default class Modal extends Component {
className={this.modalCloseButtonClass}
type="button"
onClick={onRequestClose}
title={iconDescription}
aria-label={iconDescription}
title={ariaLabel ? ariaLabel : iconDescription}
aria-label={ariaLabel ? ariaLabel : iconDescription}
ref={this.button}>
<Close20
aria-label={iconDescription}
aria-hidden="true"
aria-label="close"
tabIndex="-1"
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,34 +109,38 @@ 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"
aria-label="close"
className="bx--modal-close__icon"
tabIndex="-1"
>
<Icon
aria-label="Close"
aria-hidden="true"
aria-label="close"
className="bx--modal-close__icon"
fill="currentColor"
height={20}
preserveAspectRatio="xMidYMid meet"
tabIndex="-1"
viewBox="0 0 32 32"
width={20}
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-label="Close"
aria-hidden="true"
aria-label="close"
className="bx--modal-close__icon"
fill="currentColor"
focusable="false"
focusable="true"
height={20}
preserveAspectRatio="xMidYMid meet"
role="img"
tabIndex="-1"
viewBox="0 0 32 32"
width={20}
xmlns="http://www.w3.org/2000/svg"
Expand Down

0 comments on commit a9c13ff

Please sign in to comment.