Skip to content

Commit 7ef7514

Browse files
PowerKiKicrisbeto
authored andcommitted
docs(material/dialog): use h2 for dialog title (#28519)
Because the vast majority of pages will already have an `<h1>`, and MDN now recommends to avoid using multiple `<h1>` elements on one page. So we should strive to show code examples that can be copy-pasted as is. See also: - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#avoid_using_multiple_h1_elements_on_one_page - https://stackoverflow.com/a/38467898/37706 - https://accessibleweb.com/question-answer/how-should-i-handle-headings-in-a-modal/ (cherry picked from commit 14d5de1)
1 parent d0651a5 commit 7ef7514

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

src/cdk/dialog/dialog.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ describe('Dialog', () => {
875875
flushMicrotasks();
876876

877877
let firstHeader = overlayContainerElement.querySelector(
878-
'h1[tabindex="-1"]',
878+
'h2[tabindex="-1"]',
879879
) as HTMLInputElement;
880880

881881
expect(document.activeElement)
@@ -1270,7 +1270,7 @@ class PizzaMsg {
12701270

12711271
@Component({
12721272
template: `
1273-
<h1>This is the title</h1>
1273+
<h2>This is the title</h2>
12741274
`,
12751275
standalone: true,
12761276
imports: [DialogModule],

src/components-examples/material/dialog/dialog-animations/dialog-animations-example-dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 mat-dialog-title>Delete file</h1>
1+
<h2 mat-dialog-title>Delete file</h2>
22
<mat-dialog-content>
33
Would you like to delete cat.jpeg?
44
</mat-dialog-content>

src/components-examples/material/dialog/dialog-data/dialog-data-example-dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 mat-dialog-title>Favorite Animal</h1>
1+
<h2 mat-dialog-title>Favorite Animal</h2>
22
<mat-dialog-content>
33
My favorite animal is:
44
<ul>

src/components-examples/material/dialog/dialog-elements/dialog-elements-example-dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 mat-dialog-title>Dialog with elements</h1>
1+
<h2 mat-dialog-title>Dialog with elements</h2>
22
<mat-dialog-content>This dialog showcases the title, close, content and actions elements.</mat-dialog-content>
33
<mat-dialog-actions>
44
<button mat-button mat-dialog-close>Close</button>

src/components-examples/material/dialog/dialog-overview/dialog-overview-example-dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 mat-dialog-title>Hi {{data.name}}</h1>
1+
<h2 mat-dialog-title>Hi {{data.name}}</h2>
22
<mat-dialog-content>
33
<p>What's your favorite animal?</p>
44
<mat-form-field>

src/dev-app/slider/slider-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class SliderDemo {
123123
selector: 'slider-dialog-demo',
124124
styleUrls: ['slider-demo.css'],
125125
template: `
126-
<h1 mat-dialog-title>Slider in a dialog</h1>
126+
<h2 mat-dialog-title>Slider in a dialog</h2>
127127
<mat-dialog-content class="demo-dialog-content">
128128
<mat-slider [discrete]="this.data.discrete" [showTickMarks]="this.data.showTickMarks" [color]="this.data.color" step="10">
129129
<input value="50" matSliderThumb>

src/material/dialog/dialog.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ describe('MDC-based MatDialog', () => {
12171217
flushMicrotasks();
12181218

12191219
let firstHeader = overlayContainerElement.querySelector(
1220-
'h1[tabindex="-1"]',
1220+
'h2[tabindex="-1"]',
12211221
) as HTMLInputElement;
12221222

12231223
expect(document.activeElement)
@@ -1628,7 +1628,7 @@ describe('MDC-based MatDialog', () => {
16281628
@Component({
16291629
standalone: true,
16301630
imports: [MatDialogTitle],
1631-
template: `@if (showTitle()) { <h1 mat-dialog-title>This is the first title</h1> }`,
1631+
template: `@if (showTitle()) { <h2 mat-dialog-title>This is the first title</h2> }`,
16321632
})
16331633
class DialogCmp {
16341634
showTitle = signal(true);
@@ -2243,13 +2243,13 @@ class PizzaMsg {
22432243
@Component({
22442244
template: `
22452245
@if (shouldShowTitle('first')) {
2246-
<h1 mat-dialog-title>This is the first title</h1>
2246+
<h2 mat-dialog-title>This is the first title</h2>
22472247
}
22482248
@if (shouldShowTitle('second')) {
2249-
<h1 mat-dialog-title>This is the second title</h1>
2249+
<h2 mat-dialog-title>This is the second title</h2>
22502250
}
22512251
@if (shouldShowTitle('third')) {
2252-
<h1 mat-dialog-title>This is the third title</h1>
2252+
<h2 mat-dialog-title>This is the third title</h2>
22532253
}
22542254
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
22552255
<mat-dialog-actions align="end">
@@ -2278,13 +2278,13 @@ class ContentElementDialog {
22782278
template: `
22792279
<ng-template>
22802280
@if (shouldShowTitle('first')) {
2281-
<h1 mat-dialog-title>This is the first title</h1>
2281+
<h2 mat-dialog-title>This is the first title</h2>
22822282
}
22832283
@if (shouldShowTitle('second')) {
2284-
<h1 mat-dialog-title>This is the second title</h1>
2284+
<h2 mat-dialog-title>This is the second title</h2>
22852285
}
22862286
@if (shouldShowTitle('third')) {
2287-
<h1 mat-dialog-title>This is the third title</h1>
2287+
<h2 mat-dialog-title>This is the third title</h2>
22882288
}
22892289
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
22902290
<mat-dialog-actions align="end">

0 commit comments

Comments
 (0)