Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radio/checkbox: Include description in label, set correct label styling #1031

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading