A11Y: correctly sets role=dialog and aria-labelledby for d-modals (#11850)

This commit is contained in:
Joffrey JAFFEUX 2021-01-26 15:26:30 +01:00 committed by GitHub
parent 3c028cb67f
commit 1989a326c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { computed } from "@ember/object";
import Component from "@ember/component";
import I18n from "I18n";
import afterTransition from "discourse/lib/after-transition";
@ -12,10 +13,16 @@ export default Component.extend({
"modalStyle",
"hasPanels",
],
attributeBindings: ["data-keyboard", "aria-modal"],
attributeBindings: [
"data-keyboard",
"aria-modal",
"role",
"ariaLabelledby:aria-labelledby",
],
dismissable: true,
title: null,
subtitle: null,
role: "dialog",
init() {
this._super(...arguments);
@ -33,6 +40,10 @@ export default Component.extend({
// Inform screenreaders of the modal
"aria-modal": "true",
ariaLabelledby: computed("title", function () {
return this.title ? "discourse-modal-title" : null;
}),
@on("didInsertElement")
setUp() {
$("html").on("keyup.discourse-modal", (e) => {

View File

@ -8,7 +8,7 @@
{{#if title}}
<div class="title">
<h3>{{title}}</h3>
<h3 id="discourse-modal-title">{{title}}</h3>
{{#if subtitle}}
<p>{{subtitle}}</p>