Skip to content

Commit 14d5de1

Browse files
authored
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/
1 parent 9150177 commit 14d5de1

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
@@ -1214,7 +1214,7 @@ describe('MDC-based MatDialog', () => {
12141214
flushMicrotasks();
12151215

12161216
let firstHeader = overlayContainerElement.querySelector(
1217-
'h1[tabindex="-1"]',
1217+
'h2[tabindex="-1"]',
12181218
) as HTMLInputElement;
12191219

12201220
expect(document.activeElement)
@@ -1625,7 +1625,7 @@ describe('MDC-based MatDialog', () => {
16251625
@Component({
16261626
standalone: true,
16271627
imports: [MatDialogTitle],
1628-
template: `@if (showTitle()) { <h1 mat-dialog-title>This is the first title</h1> }`,
1628+
template: `@if (showTitle()) { <h2 mat-dialog-title>This is the first title</h2> }`,
16291629
})
16301630
class DialogCmp {
16311631
showTitle = signal(true);
@@ -2240,13 +2240,13 @@ class PizzaMsg {
22402240
@Component({
22412241
template: `
22422242
@if (shouldShowTitle('first')) {
2243-
<h1 mat-dialog-title>This is the first title</h1>
2243+
<h2 mat-dialog-title>This is the first title</h2>
22442244
}
22452245
@if (shouldShowTitle('second')) {
2246-
<h1 mat-dialog-title>This is the second title</h1>
2246+
<h2 mat-dialog-title>This is the second title</h2>
22472247
}
22482248
@if (shouldShowTitle('third')) {
2249-
<h1 mat-dialog-title>This is the third title</h1>
2249+
<h2 mat-dialog-title>This is the third title</h2>
22502250
}
22512251
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
22522252
<mat-dialog-actions align="end">
@@ -2275,13 +2275,13 @@ class ContentElementDialog {
22752275
template: `
22762276
<ng-template>
22772277
@if (shouldShowTitle('first')) {
2278-
<h1 mat-dialog-title>This is the first title</h1>
2278+
<h2 mat-dialog-title>This is the first title</h2>
22792279
}
22802280
@if (shouldShowTitle('second')) {
2281-
<h1 mat-dialog-title>This is the second title</h1>
2281+
<h2 mat-dialog-title>This is the second title</h2>
22822282
}
22832283
@if (shouldShowTitle('third')) {
2284-
<h1 mat-dialog-title>This is the third title</h1>
2284+
<h2 mat-dialog-title>This is the third title</h2>
22852285
}
22862286
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
22872287
<mat-dialog-actions align="end">

0 commit comments

Comments
 (0)