Skip to content

Commit d564731

Browse files
authored
Dialog: Add option to put the dialog title in a header element
Implement a new option: `uiDialogTitleHeadingLevel`, allowing to change the `span` wrapping the dialog title into a heading element (`h1`-`h6`). Value `0` represents the `span`, values 1-6 - a heading at the specified level. Fixes gh-2271 Closes gh-2275
1 parent fd1b8a0 commit d564731

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

tests/unit/dialog/common-deprecated.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ common.testWidget( "dialog", {
3434
resizable: true,
3535
show: null,
3636
title: null,
37+
uiDialogTitleHeadingLevel: 0,
3738
width: 300,
3839

3940
// Callbacks

tests/unit/dialog/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ common.testWidget( "dialog", {
3333
resizable: true,
3434
show: null,
3535
title: null,
36+
uiDialogTitleHeadingLevel: 0,
3637
width: 300,
3738

3839
// Callbacks

tests/unit/dialog/core.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,44 @@ QUnit.test( "aria-modal", function( assert ) {
117117
element.remove();
118118
} );
119119

120+
QUnit.test( "ui dialog title heading level", function( assert ) {
121+
assert.expect( 8 );
122+
123+
var element, nodeName;
124+
125+
element = $( "<div>" ).dialog( { modal: true } );
126+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
127+
assert.equal( nodeName, "span", "Element wrapping the dialog title is span" );
128+
129+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: 0 } );
130+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
131+
assert.equal( nodeName, "span", "Element wrapping the dialog title is span" );
132+
133+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: 1 } );
134+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
135+
assert.equal( nodeName, "h1", "Element wrapping the dialog title is h1" );
136+
137+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: 6 } );
138+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
139+
assert.equal( nodeName, "h6", "Element wrapping the dialog title is h6" );
140+
141+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: 9 } );
142+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
143+
assert.equal( nodeName, "span", "Element wrapping the dialog title is span" );
144+
145+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: -9 } );
146+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
147+
assert.equal( nodeName, "span", "Element wrapping the dialog title is span" );
148+
149+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: 2.3 } );
150+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
151+
assert.equal( nodeName, "span", "Element wrapping the dialog title is span" );
152+
153+
element = $( "<div>" ).dialog( { modal: true, uiDialogTitleHeadingLevel: "foo" } );
154+
nodeName = element.dialog( "widget" ).find( ".ui-dialog-title" ).get( 0 ).nodeName.toLowerCase();
155+
assert.equal( nodeName, "span", "Element wrapping the dialog title is span" );
156+
} );
157+
120158
QUnit.test( "widget method", function( assert ) {
121159
assert.expect( 1 );
122160
var dialog = $( "<div>" ).appendTo( "#qunit-fixture" ).dialog();

ui/widgets/dialog.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ $.widget( "ui.dialog", {
8181
resizable: true,
8282
show: null,
8383
title: null,
84+
uiDialogTitleHeadingLevel: 0,
8485
width: 300,
8586

8687
// Callbacks
@@ -437,7 +438,13 @@ $.widget( "ui.dialog", {
437438
}
438439
} );
439440

440-
uiDialogTitle = $( "<span>" ).uniqueId().prependTo( this.uiDialogTitlebar );
441+
var uiDialogHeadingLevel = Number.isInteger( this.options.uiDialogTitleHeadingLevel ) &&
442+
this.options.uiDialogTitleHeadingLevel > 0 &&
443+
this.options.uiDialogTitleHeadingLevel <= 6 ?
444+
"h" + this.options.uiDialogTitleHeadingLevel : "span";
445+
446+
uiDialogTitle = $( "<" + uiDialogHeadingLevel + ">" )
447+
.uniqueId().prependTo( this.uiDialogTitlebar );
441448
this._addClass( uiDialogTitle, "ui-dialog-title" );
442449
this._title( uiDialogTitle );
443450

0 commit comments

Comments
 (0)