Skip to content

Commit a9c13ff

Browse files
sstrubbergdakahn
andauthored
feat(modal): deprecate iconDescription (#9828)
* 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>
1 parent 559412c commit a9c13ff

5 files changed

Lines changed: 26 additions & 28 deletions

File tree

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,7 +3811,6 @@ Map {
38113811
"Modal" => Object {
38123812
"defaultProps": Object {
38133813
"hasScrollingContent": false,
3814-
"iconDescription": "Close",
38153814
"modalHeading": "",
38163815
"modalLabel": "",
38173816
"onKeyDown": [Function],
@@ -3841,9 +3840,7 @@ Map {
38413840
"hasScrollingContent": Object {
38423841
"type": "bool",
38433842
},
3844-
"iconDescription": Object {
3845-
"type": "string",
3846-
},
3843+
"iconDescription": [Function],
38473844
"id": Object {
38483845
"type": "string",
38493846
},

packages/react/src/components/Modal/Modal-story.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const props = {
6868
'[data-modal-primary-focus]'
6969
),
7070
size: select('Size (size)', sizes, 'md'),
71-
iconDescription: text('Close icon description (iconDescription)', 'Close'),
7271
onBlur: action('onBlur'),
7372
onClick: action('onClick'),
7473
onFocus: action('onFocus'),

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,14 @@ describe('Modal', () => {
4747
expect(getModal(modal).props().id).toEqual('modal-1');
4848
});
4949

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

54-
it('adds new iconDescription when passed via props', () => {
55-
mounted.setProps({ iconDescription: 'new description' });
56-
expect(mounted.props().iconDescription).toEqual('new description');
57-
});
58-
59-
it('should have iconDescription match Icon component description prop', () => {
60-
const description = mounted.find(Close20).props()['aria-label'];
61-
const matches = mounted.props().iconDescription === description;
62-
expect(matches).toEqual(true);
55+
it("icon isn't a focusable tab stop", () => {
56+
const icon = mounted.find(Close20).props().tabIndex;
57+
expect(icon).toEqual('-1');
6358
});
6459

6560
it('enables primary button by default', () => {

packages/react/src/components/Modal/Modal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export default class Modal extends Component {
8080
/**
8181
* Provide a description for "close" icon that can be read by screen readers
8282
*/
83-
iconDescription: PropTypes.string,
83+
iconDescription: deprecate(
84+
PropTypes.string,
85+
'The iconDescription prop is no longer needed and can be safely removed. This prop will be removed in the next major release of Carbon.'
86+
),
8487

8588
/**
8689
* Specify the DOM element ID of the top-level node.
@@ -220,7 +223,6 @@ export default class Modal extends Component {
220223
primaryButtonDisabled: false,
221224
onKeyDown: () => {},
222225
passiveModal: false,
223-
iconDescription: 'Close',
224226
modalHeading: '',
225227
modalLabel: '',
226228
preventCloseOnClickOutside: false,
@@ -417,11 +419,13 @@ export default class Modal extends Component {
417419
className={this.modalCloseButtonClass}
418420
type="button"
419421
onClick={onRequestClose}
420-
title={iconDescription}
421-
aria-label={iconDescription}
422+
title={ariaLabel ? ariaLabel : iconDescription}
423+
aria-label={ariaLabel ? ariaLabel : iconDescription}
422424
ref={this.button}>
423425
<Close20
424-
aria-label={iconDescription}
426+
aria-hidden="true"
427+
aria-label="close"
428+
tabIndex="-1"
425429
className={`${this.modalCloseButtonClass}__icon`}
426430
/>
427431
</button>

packages/react/src/components/ModalWrapper/__snapshots__/ModalWrapper-test.js.snap

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ exports[`ModalWrapper should render 1`] = `
5656
<Modal
5757
aria-label="test modal"
5858
hasScrollingContent={false}
59-
iconDescription="Close"
6059
id="modal"
6160
modalHeading="Transactional Modal"
6261
modalLabel="Test Modal Label"
@@ -110,34 +109,38 @@ exports[`ModalWrapper should render 1`] = `
110109
Transactional Modal
111110
</h3>
112111
<button
113-
aria-label="Close"
114112
className="bx--modal-close"
115113
onClick={[Function]}
116-
title="Close"
117114
type="button"
118115
>
119116
<ForwardRef(Close20)
120-
aria-label="Close"
117+
aria-hidden="true"
118+
aria-label="close"
121119
className="bx--modal-close__icon"
120+
tabIndex="-1"
122121
>
123122
<Icon
124-
aria-label="Close"
123+
aria-hidden="true"
124+
aria-label="close"
125125
className="bx--modal-close__icon"
126126
fill="currentColor"
127127
height={20}
128128
preserveAspectRatio="xMidYMid meet"
129+
tabIndex="-1"
129130
viewBox="0 0 32 32"
130131
width={20}
131132
xmlns="http://www.w3.org/2000/svg"
132133
>
133134
<svg
134-
aria-label="Close"
135+
aria-hidden="true"
136+
aria-label="close"
135137
className="bx--modal-close__icon"
136138
fill="currentColor"
137-
focusable="false"
139+
focusable="true"
138140
height={20}
139141
preserveAspectRatio="xMidYMid meet"
140142
role="img"
143+
tabIndex="-1"
141144
viewBox="0 0 32 32"
142145
width={20}
143146
xmlns="http://www.w3.org/2000/svg"

0 commit comments

Comments
 (0)