Skip to content

Commit

Permalink
Fix accessiblity for value displays
Browse files Browse the repository at this point in the history
  • Loading branch information
sp-pau-tena committed Oct 27, 2023
1 parent f2fe73d commit 77742c8
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pautena/react-design-system",
"version": "0.14.4",
"version": "0.14.5",
"description": "My custom design system on top of MUI",
"main": "dist/cjs/index.js",
"module": "dist/index.js",
Expand Down
9 changes: 9 additions & 0 deletions src/value-boolean/value-boolean.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ValueBoolean } from "./value-boolean";
import { render, screen } from "../tests/testing-library";
import userEvent from "@testing-library/user-event";
import { vi } from "vitest";
import { within } from "@testing-library/react";

describe("ValueBoolean", () => {
const renderComponent = ({
Expand Down Expand Up @@ -128,5 +129,13 @@ describe("ValueBoolean", () => {

expect(screen.getByRole("checkbox")).toBeChecked();
});

it("should have the edit button accessible by label", () => {
renderComponent({ editable: true });

expect(
within(screen.getByLabelText(/hello world/i)).getByRole("button", { name: /edit/i }),
).toBeVisible();
});
});
});
9 changes: 9 additions & 0 deletions src/value-datetime/value-datetime.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import userEvent from "@testing-library/user-event";
import { pickDatetime } from "../tests/actions";
import { assertDatetimeInputValue } from "../tests/assertions";
import { vi } from "vitest";
import { within } from "@testing-library/react";

const DummyValue = new Date(2022, 7, 10, 0, 0);
const NewValue = new Date(2021, 8, 9, 11, 21);
Expand Down Expand Up @@ -136,5 +137,13 @@ describe("ValueDatetime", () => {
fmt: datetimeFormat,
});
});

it("should have the edit button accessible by label", () => {
renderComponent({ editable: true });

expect(
within(screen.getByLabelText(/hello world/i)).getByRole("button", { name: /edit/i }),
).toBeVisible();
});
});
});
4 changes: 2 additions & 2 deletions src/value-datetime/value-datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export const ValueDatetime = ({
}}
/>
) : (
<Box display="flex" alignItems="center">
<Typography variant={dense ? "body1" : "h5"} noWrap aria-labelledby={id}>
<Box display="flex" alignItems="center" aria-labelledby={id}>
<Typography variant={dense ? "body1" : "h5"} noWrap>
{value}
</Typography>
{editable && <ValueEditButton dense={dense} onClick={startEdit} />}
Expand Down
9 changes: 9 additions & 0 deletions src/value-rating/value-rating.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render, screen } from "../tests/testing-library";
import { ValueRating } from "./value-rating";
import userEvent from "@testing-library/user-event";
import { vi } from "vitest";
import { within } from "@testing-library/react";

describe("ValueRating", () => {
const renderComponent = ({
Expand Down Expand Up @@ -100,5 +101,13 @@ describe("ValueRating", () => {

expect(screen.getAllByTestId("StarIcon")).toHaveLength(3);
});

it("should have the edit button accessible by label", () => {
renderComponent({ editable: true });

expect(
within(screen.getByLabelText(/hello world/i)).getByRole("button", { name: /edit/i }),
).toBeVisible();
});
});
});
3 changes: 1 addition & 2 deletions src/value-rating/value-rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export const ValueRating = ({

return (
<ValueContent label={label} tooltip={value.toString()} dense={dense}>
<Box display="flex" alignItems="center">
<Box display="flex" alignItems="center" aria-labelledby={id}>
<Rating
aria-labelledby={id}
readOnly={!isEditing}
max={maxRating}
size={dense ? "small" : "medium"}
Expand Down
9 changes: 9 additions & 0 deletions src/value-text/value-text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render, screen } from "../tests/testing-library";
import { ValueText } from "./value-text";
import userEvent from "@testing-library/user-event";
import { vi } from "vitest";
import { within } from "@testing-library/react";

const DummyValue = "Lorem ipsum sit amet";

Expand Down Expand Up @@ -124,5 +125,13 @@ describe("ValueText", () => {
expect(onEdit).toHaveBeenCalledTimes(1);
expect(onEdit).toHaveBeenCalledWith("new value");
});

it("should have the edit button accessible by label", () => {
renderComponent({ editable: true });

expect(
within(screen.getByLabelText(/hello world/i)).getByRole("button", { name: /edit/i }),
).toBeVisible();
});
});
});
4 changes: 2 additions & 2 deletions src/value-text/value-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const ValueText = ({
sx={{ marginY: !dense ? 1 : 0 }}
/>
) : (
<Box display="flex">
<Typography variant={dense ? "body1" : "h5"} noWrap aria-labelledby={id}>
<Box display="flex" aria-labelledby={id}>
<Typography variant={dense ? "body1" : "h5"} noWrap>
{value}
</Typography>
{editable && <ValueEditButton dense={dense} onClick={startEdit} />}
Expand Down

0 comments on commit 77742c8

Please sign in to comment.