feat: Make color ARIA labels better (#3871)
* Make color aria labels better * Use isTransparent helper * Fix import * Try to fix test * More test fixes * Reuse variable
This commit is contained in:
parent
d607249205
commit
621812d0eb
@ -1,5 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Popover } from "./Popover";
|
import { Popover } from "./Popover";
|
||||||
|
import { isTransparent } from "../utils";
|
||||||
|
|
||||||
import "./ColorPicker.scss";
|
import "./ColorPicker.scss";
|
||||||
import { isArrowKey, KEYS } from "../keys";
|
import { isArrowKey, KEYS } from "../keys";
|
||||||
@ -14,7 +15,7 @@ const isValidColor = (color: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getColor = (color: string): string | null => {
|
const getColor = (color: string): string | null => {
|
||||||
if (color === "transparent") {
|
if (isTransparent(color)) {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,36 +138,41 @@ const Picker = ({
|
|||||||
}}
|
}}
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
>
|
>
|
||||||
{colors.map((_color, i) => (
|
{colors.map((_color, i) => {
|
||||||
<button
|
const _colorWithoutHash = _color.replace("#", "");
|
||||||
className="color-picker-swatch"
|
return (
|
||||||
onClick={(event) => {
|
<button
|
||||||
(event.currentTarget as HTMLButtonElement).focus();
|
className="color-picker-swatch"
|
||||||
onChange(_color);
|
onClick={(event) => {
|
||||||
}}
|
(event.currentTarget as HTMLButtonElement).focus();
|
||||||
title={`${_color} — ${keyBindings[i].toUpperCase()}`}
|
onChange(_color);
|
||||||
aria-label={_color}
|
}}
|
||||||
aria-keyshortcuts={keyBindings[i]}
|
title={`${t(`colors.${_colorWithoutHash}`)}${
|
||||||
style={{ color: _color }}
|
!isTransparent(_color) ? ` (${_color})` : ""
|
||||||
key={_color}
|
} — ${keyBindings[i].toUpperCase()}`}
|
||||||
ref={(el) => {
|
aria-label={t(`colors.${_colorWithoutHash}`)}
|
||||||
if (el && i === 0) {
|
aria-keyshortcuts={keyBindings[i]}
|
||||||
firstItem.current = el;
|
style={{ color: _color }}
|
||||||
}
|
key={_color}
|
||||||
if (el && _color === color) {
|
ref={(el) => {
|
||||||
activeItem.current = el;
|
if (el && i === 0) {
|
||||||
}
|
firstItem.current = el;
|
||||||
}}
|
}
|
||||||
onFocus={() => {
|
if (el && _color === color) {
|
||||||
onChange(_color);
|
activeItem.current = el;
|
||||||
}}
|
}
|
||||||
>
|
}}
|
||||||
{_color === "transparent" ? (
|
onFocus={() => {
|
||||||
<div className="color-picker-transparent"></div>
|
onChange(_color);
|
||||||
) : undefined}
|
}}
|
||||||
<span className="color-picker-keybinding">{keyBindings[i]}</span>
|
>
|
||||||
</button>
|
{isTransparent(_color) ? (
|
||||||
))}
|
<div className="color-picker-transparent"></div>
|
||||||
|
) : undefined}
|
||||||
|
<span className="color-picker-keybinding">{keyBindings[i]}</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
{showInput && (
|
{showInput && (
|
||||||
<ColorInput
|
<ColorInput
|
||||||
color={color}
|
color={color}
|
||||||
|
@ -282,5 +282,52 @@
|
|||||||
"fileSavedToFilename": "Saved to {filename}",
|
"fileSavedToFilename": "Saved to {filename}",
|
||||||
"canvas": "canvas",
|
"canvas": "canvas",
|
||||||
"selection": "selection"
|
"selection": "selection"
|
||||||
|
},
|
||||||
|
"colors": {
|
||||||
|
"ffffff": "White",
|
||||||
|
"f8f9fa": "Gray 0",
|
||||||
|
"f1f3f5": "Gray 1",
|
||||||
|
"fff5f5": "Red 0",
|
||||||
|
"fff0f6": "Pink 0",
|
||||||
|
"f8f0fc": "Grape 0",
|
||||||
|
"f3f0ff": "Violet 0",
|
||||||
|
"edf2ff": "Indigo 0",
|
||||||
|
"e7f5ff": "Blue 0",
|
||||||
|
"e3fafc": "Cyan 0",
|
||||||
|
"e6fcf5": "Teal 0",
|
||||||
|
"ebfbee": "Green 0",
|
||||||
|
"f4fce3": "Lime 0",
|
||||||
|
"fff9db": "Yellow 0",
|
||||||
|
"fff4e6": "Orange 0",
|
||||||
|
"transparent": "Transparent",
|
||||||
|
"ced4da": "Gray 4",
|
||||||
|
"868e96": "Gray 6",
|
||||||
|
"fa5252": "Red 6",
|
||||||
|
"e64980": "Pink 6",
|
||||||
|
"be4bdb": "Grape 6",
|
||||||
|
"7950f2": "Violet 6",
|
||||||
|
"4c6ef5": "Indigo 6",
|
||||||
|
"228be6": "Blue 6",
|
||||||
|
"15aabf": "Cyan 6",
|
||||||
|
"12b886": "Teal 6",
|
||||||
|
"40c057": "Green 6",
|
||||||
|
"82c91e": "Lime 6",
|
||||||
|
"fab005": "Yellow 6",
|
||||||
|
"fd7e14": "Orange 6",
|
||||||
|
"000000": "Black",
|
||||||
|
"343a40": "Gray 8",
|
||||||
|
"495057": "Gray 7",
|
||||||
|
"c92a2a": "Red 9",
|
||||||
|
"a61e4d": "Pink 9",
|
||||||
|
"862e9c": "Grape 9",
|
||||||
|
"5f3dc4": "Violet 9",
|
||||||
|
"364fc7": "Indigo 9",
|
||||||
|
"1864ab": "Blue 9",
|
||||||
|
"0b7285": "Cyan 9",
|
||||||
|
"087f5b": "Teal 9",
|
||||||
|
"2b8a3e": "Green 9",
|
||||||
|
"5c940d": "Lime 9",
|
||||||
|
"e67700": "Yellow 9",
|
||||||
|
"d9480f": "Orange 9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import { ShortcutName } from "../actions/shortcuts";
|
|||||||
import { copiedStyles } from "../actions/actionStyles";
|
import { copiedStyles } from "../actions/actionStyles";
|
||||||
import { API } from "./helpers/api";
|
import { API } from "./helpers/api";
|
||||||
import { setDateTimeForTests } from "../utils";
|
import { setDateTimeForTests } from "../utils";
|
||||||
|
import { t } from "../i18n";
|
||||||
|
|
||||||
const checkpoint = (name: string) => {
|
const checkpoint = (name: string) => {
|
||||||
expect(renderScene.mock.calls.length).toMatchSnapshot(
|
expect(renderScene.mock.calls.length).toMatchSnapshot(
|
||||||
@ -314,9 +315,9 @@ describe("contextMenu element", () => {
|
|||||||
|
|
||||||
// Change some styles of second rectangle
|
// Change some styles of second rectangle
|
||||||
clickLabeledElement("Stroke");
|
clickLabeledElement("Stroke");
|
||||||
clickLabeledElement("#c92a2a");
|
clickLabeledElement(t("colors.c92a2a"));
|
||||||
clickLabeledElement("Background");
|
clickLabeledElement("Background");
|
||||||
clickLabeledElement("#e64980");
|
clickLabeledElement(t("colors.e64980"));
|
||||||
// Fill style
|
// Fill style
|
||||||
fireEvent.click(screen.getByTitle("Cross-hatch"));
|
fireEvent.click(screen.getByTitle("Cross-hatch"));
|
||||||
// Stroke width
|
// Stroke width
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from "./test-utils";
|
} from "./test-utils";
|
||||||
import { defaultLang } from "../i18n";
|
import { defaultLang } from "../i18n";
|
||||||
import { FONT_FAMILY } from "../constants";
|
import { FONT_FAMILY } from "../constants";
|
||||||
|
import { t } from "../i18n";
|
||||||
|
|
||||||
const { h } = window;
|
const { h } = window;
|
||||||
|
|
||||||
@ -168,9 +169,9 @@ describe("regression tests", () => {
|
|||||||
mouse.up(10, 10);
|
mouse.up(10, 10);
|
||||||
|
|
||||||
clickLabeledElement("Background");
|
clickLabeledElement("Background");
|
||||||
clickLabeledElement("#fa5252");
|
clickLabeledElement(t("colors.fa5252"));
|
||||||
clickLabeledElement("Stroke");
|
clickLabeledElement("Stroke");
|
||||||
clickLabeledElement("#5f3dc4");
|
clickLabeledElement(t("colors.5f3dc4"));
|
||||||
expect(API.getSelectedElement().backgroundColor).toBe("#fa5252");
|
expect(API.getSelectedElement().backgroundColor).toBe("#fa5252");
|
||||||
expect(API.getSelectedElement().strokeColor).toBe("#5f3dc4");
|
expect(API.getSelectedElement().strokeColor).toBe("#5f3dc4");
|
||||||
});
|
});
|
||||||
@ -939,7 +940,7 @@ describe("regression tests", () => {
|
|||||||
// change background color since default is transparent
|
// change background color since default is transparent
|
||||||
// and transparent elements can't be selected by clicking inside of them
|
// and transparent elements can't be selected by clicking inside of them
|
||||||
clickLabeledElement("Background");
|
clickLabeledElement("Background");
|
||||||
clickLabeledElement("#fa5252");
|
clickLabeledElement(t("colors.fa5252"));
|
||||||
mouse.down();
|
mouse.down();
|
||||||
mouse.up(1000, 1000);
|
mouse.up(1000, 1000);
|
||||||
|
|
||||||
@ -1046,7 +1047,7 @@ describe("regression tests", () => {
|
|||||||
expect(screen.queryByText(/fill/i)).toBeNull();
|
expect(screen.queryByText(/fill/i)).toBeNull();
|
||||||
|
|
||||||
clickLabeledElement("Background");
|
clickLabeledElement("Background");
|
||||||
clickLabeledElement("#fa5252");
|
clickLabeledElement(t("colors.fa5252"));
|
||||||
// select rectangle
|
// select rectangle
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
mouse.click();
|
mouse.click();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user