A11Y: makes toolbar tabindex independent from its context (#17889)

Prior to this fix, if `<DEditor />` was used in a context where quote would not be the first button, then no  button would be focusable.
This commit is contained in:
Joffrey JAFFEUX 2022-08-12 21:24:20 +02:00 committed by GitHub
parent 494cc2c69d
commit bcb89beb99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -816,7 +816,6 @@ export default Component.extend(ComposerUploadUppy, {
extraButtons(toolbar) {
toolbar.addButton({
tabindex: "0",
id: "quote",
group: "fontStyles",
icon: "far-comment",

View File

@ -363,6 +363,12 @@ export default Component.extend(TextareaTextManipulation, {
if (this.extraButtons) {
this.extraButtons(toolbar);
}
const firstButton = toolbar.groups.mapBy("buttons").flat().firstObject;
if (firstButton) {
firstButton.tabindex = 0;
}
return toolbar;
},

View File

@ -6,6 +6,7 @@ import {
exists,
paste,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import {
getTextareaSelection,
@ -705,6 +706,18 @@ third line`
);
});
test("toolbar buttons tabindex", async function (assert) {
await render(hbs`<DEditor />`);
const buttons = queryAll(".d-editor-button-bar .btn");
assert.strictEqual(
buttons[0].getAttribute("tabindex"),
"0",
"it makes the first button focusable"
);
assert.strictEqual(buttons[1].getAttribute("tabindex"), "-1");
});
testCase("replace-text event by default", async function (assert) {
this.set("value", "red green blue");