Skip to content

Commit

Permalink
Radio/checkbox: Include description in label, set correct label styli…
Browse files Browse the repository at this point in the history
…ng (#1031)
  • Loading branch information
oliver3 authored Feb 17, 2025
1 parent b6c76a5 commit 75999d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
20 changes: 10 additions & 10 deletions frontend/app/module/users/create/UserCreateRolePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ describe("UserCreateRolePage", () => {

expect(await screen.findByRole("heading", { level: 1, name: "Gebruiker toevoegen" })).toBeInTheDocument();

expect(await screen.findByLabelText("Beheerder")).not.toBeChecked();
expect(await screen.findByLabelText("Coördinator")).not.toBeChecked();
expect(await screen.findByLabelText("Invoerder")).not.toBeChecked();
expect(await screen.findByLabelText(/Beheerder/)).not.toBeChecked();
expect(await screen.findByLabelText(/Coördinator/)).not.toBeChecked();
expect(await screen.findByLabelText(/Invoerder/)).not.toBeChecked();
});

test("Shows form previously selected", async () => {
renderPage({ user: { role: "typist" } });

expect(await screen.findByLabelText("Beheerder")).not.toBeChecked();
expect(await screen.findByLabelText("Coördinator")).not.toBeChecked();
expect(await screen.findByLabelText("Invoerder")).toBeChecked();
expect(await screen.findByLabelText(/Beheerder/)).not.toBeChecked();
expect(await screen.findByLabelText(/Coördinator/)).not.toBeChecked();
expect(await screen.findByLabelText(/Invoerder/)).toBeChecked();
});

test("Shows validation error when nothing selected", async () => {
Expand All @@ -59,10 +59,10 @@ describe("UserCreateRolePage", () => {
});

test.each([
["Beheerder", { role: "administrator", type: "fullname" }, "/users/create/details"],
["Coördinator", { role: "coordinator", type: "fullname" }, "/users/create/details"],
["Invoerder", { role: "typist" }, "/users/create/type"],
])("Continue after selection as %s", async (label: string, update: unknown, newPath: string) => {
[/Beheerder/, { role: "administrator", type: "fullname" }, "/users/create/details"],
[/Coördinator/, { role: "coordinator", type: "fullname" }, "/users/create/details"],
[/Invoerder/, { role: "typist" }, "/users/create/type"],
])("Continue after selection as %s", async (label: RegExp, update: unknown, newPath: string) => {
const updateUser = vi.fn();
renderPage({ user: {}, updateUser });

Expand Down
3 changes: 2 additions & 1 deletion frontend/lib/ui/CheckboxAndRadio/CheckboxAndRadio.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
> div:global(.labels) {
display: flex;
flex-direction: column;
color: var(--base-black);

> * {
padding-left: 0.5rem;
Expand All @@ -150,7 +151,7 @@
cursor: pointer;
}

span:global(.description) {
div:global(.description) {
color: var(--color-help-text);
}
}
Expand Down
10 changes: 5 additions & 5 deletions frontend/lib/ui/CheckboxAndRadio/CheckboxAndRadio.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as React from "react";

import { cn } from "@kiesraad/util";

import cls from "./CheckboxAndRadio.module.css";

export interface CheckboxAndRadioProps extends React.InputHTMLAttributes<HTMLInputElement> {
Expand Down Expand Up @@ -34,7 +32,7 @@ export const CheckboxAndRadio = React.forwardRef<HTMLInputElement, CheckboxAndRa
ref,
) => {
return (
<div className={cn(cls["checkbox-and-radio"])} id={`${type}-container-${id}`}>
<div className={cls.checkboxAndRadio} id={`${type}-container-${id}`}>
<input
className={`${type}${indeterminate ? " indeterminate" : ""}`}
type={type}
Expand All @@ -49,8 +47,10 @@ export const CheckboxAndRadio = React.forwardRef<HTMLInputElement, CheckboxAndRa
{...inputProps}
/>
<div className="labels">
<label htmlFor={id}>{label}</label>
{children !== undefined && <span className="description">{children}</span>}
<label htmlFor={id}>
{label}
{children !== undefined && <div className="description">{children}</div>}
</label>
</div>
</div>
);
Expand Down

0 comments on commit 75999d8

Please sign in to comment.