Skip to content

Commit 376f142

Browse files
rpkollermgol
andauthored
Dialog: Add aria-modal support
Reflect the `modal` dialog option into the `aria-modal` attribute - when `modal` is `true`, set `aria-modal` to `"true"`. This helps some accessibility tools like VoiceOver with their rotor functionality as it reduces the number of elements presented. Fixes gh-2246 Closes gh-2257 Co-authored-by: Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
1 parent 1f251ca commit 376f142

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/unit/dialog/core.js

+33
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@ QUnit.test( "ARIA", function( assert ) {
8484
element.remove();
8585
} );
8686

87+
QUnit.test( "aria-modal", function( assert ) {
88+
assert.expect( 9 );
89+
90+
var element, wrapper;
91+
92+
element = $( "<div>" ).dialog( { modal: true } );
93+
wrapper = element.dialog( "widget" );
94+
assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" );
95+
element.dialog( "option", "modal", false );
96+
assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" );
97+
element.dialog( "option", "modal", true );
98+
assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" );
99+
element.remove();
100+
101+
element = $( "<div>" ).dialog( { modal: false } );
102+
wrapper = element.dialog( "widget" );
103+
assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" );
104+
element.dialog( "option", "modal", true );
105+
assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" );
106+
element.dialog( "option", "modal", false );
107+
assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" );
108+
element.remove();
109+
110+
element = $( "<div>" ).dialog();
111+
wrapper = element.dialog( "widget" );
112+
assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option not set, aria-modal attribute not added" );
113+
element.dialog( "option", "modal", true );
114+
assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" );
115+
element.dialog( "option", "modal", false );
116+
assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" );
117+
element.remove();
118+
} );
119+
87120
QUnit.test( "widget method", function( assert ) {
88121
assert.expect( 1 );
89122
var dialog = $( "<div>" ).appendTo( "#qunit-fixture" ).dialog();

ui/widgets/dialog.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ $.widget( "ui.dialog", {
347347

348348
// Setting tabIndex makes the div focusable
349349
tabIndex: -1,
350-
role: "dialog"
350+
role: "dialog",
351+
"aria-modal": this.options.modal ? "true" : null
351352
} )
352353
.appendTo( this._appendTo() );
353354

@@ -762,6 +763,10 @@ $.widget( "ui.dialog", {
762763
if ( key === "title" ) {
763764
this._title( this.uiDialogTitlebar.find( ".ui-dialog-title" ) );
764765
}
766+
767+
if ( key === "modal" ) {
768+
uiDialog.attr( "aria-modal", value ? "true" : null );
769+
}
765770
},
766771

767772
_size: function() {

0 commit comments

Comments
 (0)