Skip to content

Commit a2afe00

Browse files
fix(modal): fix aria label not showing up (#12013)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent ec338ee commit a2afe00

File tree

2 files changed

+66
-78
lines changed

2 files changed

+66
-78
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const Modal = React.forwardRef(function Modal(
156156
);
157157

158158
const ariaLabel =
159-
modalLabel || ['aria-label'] || modalAriaLabel || modalHeading;
159+
modalLabel || rest['aria-label'] || modalAriaLabel || modalHeading;
160160
const getAriaLabelledBy = modalLabel ? modalLabelId : modalHeadingId;
161161

162162
const hasScrollingContentProps = hasScrollingContent

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

Lines changed: 65 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import React, { useState } from 'react';
99
import ReactDOM from 'react-dom';
10-
import { action } from '@storybook/addon-actions';
1110
import Modal from './Modal';
1211
import Button from '../Button';
1312
import Select from '../Select';
@@ -17,70 +16,6 @@ import SelectItem from '../SelectItem';
1716
import TextInput from '../TextInput';
1817
import mdx from './Modal.mdx';
1918

20-
const buttons = {
21-
'None (0)': '0',
22-
'One (1)': '1',
23-
'Two (2)': '2',
24-
'Three (3)': '3',
25-
};
26-
27-
const props = {
28-
modal: () => ({
29-
numberOfButtons: ('Number of Buttons', buttons, '2'),
30-
className: 'some-class',
31-
open: true,
32-
danger: false,
33-
alert: false,
34-
shouldSubmitOnEnter: false,
35-
hasScrollingContent: false,
36-
hasForm: false,
37-
modalHeading: 'Modal heading',
38-
modalLabel: 'Label',
39-
modalAriaLabel:
40-
'A label to be read by screen readers on the modal root node',
41-
selectorPrimaryFocus: '[data-modal-primary-focus]',
42-
size: 'md',
43-
onBlur: action('onBlur'),
44-
onClick: action('onClick'),
45-
onFocus: action('onFocus'),
46-
onRequestClose: action('onRequestClose'),
47-
onRequestSubmit: action('onRequestSubmit'),
48-
onSecondarySubmit: action('onSecondarySubmit'),
49-
preventCloseOnClickOutside: true,
50-
primaryButtonDisabled: false,
51-
primaryButtonText: 'Primary button',
52-
}),
53-
modalFooter: (numberOfButtons) => {
54-
const secondaryButtons = () => {
55-
switch (numberOfButtons) {
56-
case '2':
57-
return {
58-
secondaryButtonText: 'Secondary button',
59-
};
60-
case '3':
61-
return {
62-
secondaryButtons: [
63-
{
64-
buttonText: 'Keep both',
65-
onClick: action('onClick'),
66-
},
67-
{
68-
buttonText: 'Rename',
69-
onClick: action('onClick'),
70-
},
71-
],
72-
};
73-
default:
74-
return null;
75-
}
76-
};
77-
return {
78-
passiveModal: false || numberOfButtons === '0',
79-
...secondaryButtons(),
80-
};
81-
},
82-
};
83-
8419
export default {
8520
title: 'Components/Modal',
8621
component: Modal,
@@ -157,18 +92,15 @@ export const DangerModal = () => {
15792
);
15893
};
15994

160-
export const Playground = () => {
161-
const { size, numberOfButtons, hasScrollingContent, ...modalProps } =
162-
props.modal();
163-
const { passiveModal, ...footerProps } = props.modalFooter(numberOfButtons);
95+
export const Playground = (args) => {
16496
return (
16597
<Modal
166-
passiveModal={numberOfButtons === '0' || passiveModal}
167-
size={size || undefined}
168-
hasScrollingContent={hasScrollingContent}
169-
aria-label={hasScrollingContent ? 'Modal content' : undefined}
170-
{...modalProps}
171-
{...footerProps}>
98+
open
99+
modalHeading="Add a custom domain"
100+
primaryButtonText="Add"
101+
secondaryButtonText="Cancel"
102+
aria-label="Modal content"
103+
{...args}>
172104
<p style={{ marginBottom: '1rem' }}>
173105
Custom domains direct requests for your apps in this Cloud Foundry
174106
organization to a URL that you own. A custom domain can be a shared
@@ -185,8 +117,7 @@ export const Playground = () => {
185117
<SelectItem value="us-south" text="US South" />
186118
<SelectItem value="us-east" text="US East" />
187119
</Select>
188-
<br />
189-
{hasScrollingContent && (
120+
{args.hasScrollingContent && (
190121
<>
191122
<p>
192123
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id
@@ -244,6 +175,63 @@ export const Playground = () => {
244175
);
245176
};
246177

178+
Playground.argTypes = {
179+
children: {
180+
table: {
181+
disable: true,
182+
},
183+
},
184+
className: {
185+
table: {
186+
disable: true,
187+
},
188+
},
189+
id: {
190+
table: {
191+
disable: true,
192+
},
193+
},
194+
modalHeading: {
195+
control: 'text',
196+
},
197+
modalLabel: {
198+
control: 'text',
199+
},
200+
onKeyDown: {
201+
action: 'clicked',
202+
},
203+
onRequestClose: {
204+
action: 'clicked',
205+
},
206+
onRequestSubmit: {
207+
action: 'clicked',
208+
},
209+
onSecondarySubmit: {
210+
action: 'clicked',
211+
},
212+
primaryButtonText: {
213+
control: 'text',
214+
},
215+
secondaryButtons: {
216+
table: {
217+
disable: true,
218+
},
219+
},
220+
secondaryButtonText: {
221+
control: 'text',
222+
},
223+
selectorPrimaryFocus: {
224+
table: {
225+
disable: true,
226+
},
227+
},
228+
selectorsFloatingMenus: {
229+
table: {
230+
disable: true,
231+
},
232+
},
233+
};
234+
247235
export const WithStateManager = () => {
248236
/**
249237
* Simple state manager for modals.

0 commit comments

Comments
 (0)