From 376f142b9de42241a20efa9c89644ff5425da174 Mon Sep 17 00:00:00 2001 From: Ralf Koller <1665422+rpkoller@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:04:00 +0200 Subject: [PATCH] Dialog: Add aria-modal support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/unit/dialog/core.js | 33 +++++++++++++++++++++++++++++++++ ui/widgets/dialog.js | 7 ++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/unit/dialog/core.js b/tests/unit/dialog/core.js index d307504b8..c6bdec778 100644 --- a/tests/unit/dialog/core.js +++ b/tests/unit/dialog/core.js @@ -84,6 +84,39 @@ QUnit.test( "ARIA", function( assert ) { element.remove(); } ); +QUnit.test( "aria-modal", function( assert ) { + assert.expect( 9 ); + + var element, wrapper; + + element = $( "
" ).dialog( { modal: true } ); + wrapper = element.dialog( "widget" ); + assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" ); + element.dialog( "option", "modal", false ); + assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" ); + element.dialog( "option", "modal", true ); + assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" ); + element.remove(); + + element = $( "
" ).dialog( { modal: false } ); + wrapper = element.dialog( "widget" ); + assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" ); + element.dialog( "option", "modal", true ); + assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" ); + element.dialog( "option", "modal", false ); + assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" ); + element.remove(); + + element = $( "
" ).dialog(); + wrapper = element.dialog( "widget" ); + assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option not set, aria-modal attribute not added" ); + element.dialog( "option", "modal", true ); + assert.equal( wrapper.attr( "aria-modal" ), "true", "modal option set to true, aria-modal attribute added" ); + element.dialog( "option", "modal", false ); + assert.equal( wrapper.attr( "aria-modal" ), undefined, "modal option set to false, aria-modal attribute not added" ); + element.remove(); +} ); + QUnit.test( "widget method", function( assert ) { assert.expect( 1 ); var dialog = $( "
" ).appendTo( "#qunit-fixture" ).dialog(); diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js index 4ba9d1117..756ad1cb1 100644 --- a/ui/widgets/dialog.js +++ b/ui/widgets/dialog.js @@ -347,7 +347,8 @@ $.widget( "ui.dialog", { // Setting tabIndex makes the div focusable tabIndex: -1, - role: "dialog" + role: "dialog", + "aria-modal": this.options.modal ? "true" : null } ) .appendTo( this._appendTo() ); @@ -762,6 +763,10 @@ $.widget( "ui.dialog", { if ( key === "title" ) { this._title( this.uiDialogTitlebar.find( ".ui-dialog-title" ) ); } + + if ( key === "modal" ) { + uiDialog.attr( "aria-modal", value ? "true" : null ); + } }, _size: function() {