Skip to content

Commit 32bd0b1

Browse files
authored
[fix]: Accessible name for dialog (#34519)
1 parent 75d09d6 commit 32bd0b1

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Accesible name and title for dialog",
4+
"packageName": "@fluentui/web-components",
5+
"email": "jes@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/web-components/src/dialog-body/dialog-body.stories.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ export const Default: Story = {
123123
</p>
124124
`,
125125

126-
titleSlottedContent: () => html` <div slot="title">Dialog Body</div> `,
126+
titleSlottedContent: () => html` <h2 slot="title">Dialog Body</h2> `,
127127
},
128128
};
129129

130130
export const Basic: Story = {
131131
args: {
132-
titleSlottedContent: () => html` <div slot="title">Basic</div> `,
132+
titleSlottedContent: () => html` <h2 slot="title">Basic</h2> `,
133133
slottedContent: () => html`
134134
<p>
135135
A dialog should have no more than
@@ -162,14 +162,14 @@ export const Actions: Story = {
162162
titleActionSlottedContent: () => html`
163163
<fluent-button appearance="transparent" icon-only slot="title-action"> ${info20Regular} </fluent-button>
164164
`,
165-
titleSlottedContent: () => html` <div slot="title">Actions</div> `,
165+
titleSlottedContent: () => html` <h2 slot="title">Actions</h2> `,
166166
},
167167
};
168168

169169
export const NoClose: Story = {
170170
args: {
171171
closeSlottedContent: () => html``,
172-
titleSlottedContent: () => html` <div slot="title">No Close Slot</div> `,
172+
titleSlottedContent: () => html` <h2 slot="title">No Close Slot</h2> `,
173173
slottedContent: () => html`
174174
<p>Omitting the close slot will prevent the default close button from being rendered in a non-modal dialog.</p>
175175
`,
@@ -181,7 +181,7 @@ export const CustomClose: Story = {
181181
slottedContent: () => html`
182182
<p>This dialog has a custom <code>close</code> slot that is rendered in place of the default close button.</p>
183183
`,
184-
titleSlottedContent: () => html` <div slot="title">Custom Title Action</div> `,
184+
titleSlottedContent: () => html` <h2 slot="title">Custom Title Action</h2> `,
185185

186186
closeSlottedContent: () => html`
187187
<fluent-button slot="close" appearance="transparent" icon-only @click="${() => alert('This is a custom action')}">

packages/web-components/src/dialog-body/dialog-body.styles.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ export const styles = css`
7979
margin-inline-start: auto;
8080
}
8181
82+
::slotted([slot='title']) {
83+
font: inherit;
84+
padding: 0;
85+
margin: 0;
86+
}
87+
8288
/* align title content to the end when there is no title*/
8389
:not(:has(:is([slot='title'], [slot='title-action']))) .title {
8490
justify-content: end;

packages/web-components/src/dialog/dialog.stories.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ const closeTemplate = html`
5757

5858
const storyTemplate = html<StoryArgs<FluentDialog & FluentDialogBody>>`
5959
<fluent-button @click="${story => story.storyDialog?.show()}">Open Dialog</fluent-button>
60-
<fluent-dialog id="dialog-default" type="${story => story.type}" ${ref('storyDialog')}>
60+
<fluent-dialog
61+
id="dialog-default"
62+
type="${story => story.type}"
63+
${ref('storyDialog')}
64+
aria-label="${story => story.ariaLabel}"
65+
>
6166
<fluent-dialog-body>
6267
${story => story.actionSlottedContent?.()} ${story => story.slottedContent?.()}
6368
${story => story.titleActionSlottedContent?.()} ${story => story.closeSlottedContent?.()}
@@ -100,7 +105,8 @@ export default {
100105

101106
export const Default: Story = {
102107
args: {
103-
titleSlottedContent: () => html` <div slot="title">Default Dialog</div> `,
108+
titleSlottedContent: () => html` <h2 slot="title">Default Dialog</h2> `,
109+
ariaLabel: 'Default Dialog',
104110
slottedContent: () => html`
105111
<p>
106112
The dialog component is a window overlaid on either the primary window or another dialog window. Windows under a
@@ -114,7 +120,8 @@ export const Default: Story = {
114120

115121
export const WithTitleAction: Story = {
116122
args: {
117-
titleSlottedContent: () => html` <div slot="title">Title Action Slot</div> `,
123+
titleSlottedContent: () => html` <h2 slot="title">Title Action Slot</h2> `,
124+
ariaLabel: 'Title Action Slot',
118125
titleActionSlottedContent: () => html`
119126
<fluent-button appearance="transparent" icon-only slot="title-action"> ${info20Regular} </fluent-button>
120127
`,
@@ -126,7 +133,8 @@ export const WithTitleAction: Story = {
126133
export const ModalType: Story = {
127134
args: {
128135
type: DialogType.modal,
129-
titleSlottedContent: () => html` <div slot="title">Modal</div> `,
136+
titleSlottedContent: () => html` <h2 slot="title">Modal</h2> `,
137+
ariaLabel: 'Model',
130138
slottedContent: () => html`
131139
<p>
132140
A modal is a type of dialog that temporarily halts the main workflow to convey a significant message or require
@@ -144,7 +152,8 @@ export const NonModalType: Story = {
144152
render: renderComponent(html<StoryArgs<FluentDialog>>` <div style="min-height: 300px">${storyTemplate}</div> `),
145153
args: {
146154
type: DialogType.nonModal,
147-
titleSlottedContent: () => html` <div slot="title">Non-modal</div> `,
155+
titleSlottedContent: () => html` <h2 slot="title">Non-modal</h2> `,
156+
ariaLabel: 'Non-modal',
148157
slottedContent: () => html`
149158
<p>
150159
A non-modal dialog by default presents no backdrop, allowing elements outside of the dialog to be interacted
@@ -165,7 +174,8 @@ export const AlertType: Story = {
165174
args: {
166175
type: DialogType.alert,
167176
closeSlottedContent: () => html``,
168-
titleSlottedContent: () => html` <div slot="title">Non-modal</div> `,
177+
titleSlottedContent: () => html` <h2 slot="title">Alert</h2> `,
178+
ariaLabel: 'Alert',
169179
actionSlottedContent: () => closeButtonTemplate,
170180
slottedContent: () => html`
171181
<p>
@@ -179,7 +189,8 @@ export const AlertType: Story = {
179189

180190
export const Actions: Story = {
181191
args: {
182-
titleSlottedContent: () => html` <div slot="title">Actions</div> `,
192+
titleSlottedContent: () => html` <h2 slot="title">Actions</h2> `,
193+
ariaLabel: 'Actions',
183194
actionSlottedContent: () => html`
184195
<fluent-button size="small" slot="action">Something</fluent-button>
185196
<fluent-button size="small" slot="action">Something Else</fluent-button>
@@ -215,13 +226,15 @@ export const CustomClose: Story = {
215226
and a custom icon. Clicking the button will trigger a JavaScript alert.
216227
</p>
217228
`,
218-
titleSlottedContent: () => html` <div slot="title">Custom Close Slot</div> `,
229+
titleSlottedContent: () => html` <h2 slot="title">Custom Close Slot</h2> `,
230+
ariaLabel: 'Custom Close Slot',
219231
},
220232
};
221233
222234
export const NoClose: Story = {
223235
args: {
224-
titleSlottedContent: () => html` <div slot="title">No Close Slot</div> `,
236+
titleSlottedContent: () => html` <h2 slot="title">No Close Slot</h2> `,
237+
ariaLabel: 'No Close Slot',
225238
closeSlottedContent: () => html``,
226239
slottedContent: () => html`
227240
<p>
@@ -236,13 +249,15 @@ export const NoClose: Story = {
236249
export const ModalWithNoTitleOrTitleActions: Story = {
237250
args: {
238251
type: DialogType.modal,
252+
ariaLabel: 'No Title',
239253
slottedContent: () => html` <p>A dialog without a <code>title</code> slot or <code>title-action</code> slot</p> `,
240254
},
241255
};
242256
243257
export const ModalWithNoTitle: Story = {
244258
args: {
245259
type: DialogType.modal,
260+
ariaLabel: 'No Title',
246261
titleActionSlottedContent: () => html`
247262
<fluent-button appearance="transparent" icon-only slot="title-action"> ${info20Regular} </fluent-button>
248263
`,
@@ -273,7 +288,8 @@ export const AlertWithNoTitleOrActions: Story = {
273288

274289
export const TwoColumnLayout: Story = {
275290
args: {
276-
titleSlottedContent: () => html` <div slot="title">Two Column Layout</div> `,
291+
titleSlottedContent: () => html` <h2 slot="title">Two Column Layout</h2> `,
292+
ariaLabel: 'Two Column Layout',
277293
slottedContent: () => html<StoryArgs<FluentDialog>>`
278294
<div style="margin-bottom: 12px;">
279295
<fluent-text block>
@@ -317,7 +333,8 @@ export const TwoColumnLayout: Story = {
317333

318334
export const ScrollingLongContent: Story = {
319335
args: {
320-
titleSlottedContent: () => html` <div slot="title">Scrolling Long Content</div> `,
336+
titleSlottedContent: () => html` <h2 slot="title">Scrolling Long Content</h2> `,
337+
ariaLabel: 'Scrolling Long Content',
321338
slottedContent: () => html`
322339
<p>
323340
By default content provided in the default slot should grow until it fits viewport size. Overflow content will

0 commit comments

Comments
 (0)