cheogram-www

created pr with cheogram-www/radios-for-five-or-fewer.1 on 2026-11-20T18:53:54Z · by 3c31bc8c
commented on 2026-11-20T18:53:54Z · by 3c31bc8c
Changes are available at https://tangled.org/mrry.band/cheogram-www radios-for-five-or-fewer
cmds
checkout latest patchset:
ssh pr.pico.sh pull cheogram-www:radios-for-five-or-fewer | git am -3
checkout specific patchset revision:
ssh pr.pico.sh pull cheogram-www:radios-for-five-or-fewer [rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh cheogram-www:radios-for-five-or-fewer
add comment to patch request:
ssh pr.pico.sh comment cheogram-www:radios-for-five-or-fewer "lgtm!"

Patchset cheogram-www/radios-for-five-or-fewer.1 on 2026-11-20T18:53:54Z · commit efeeef4

Show radios for five or fewer
Eric Roberts 2026-11-18T22:10:15Z
When there aren't many options in a list it's inconvenient to have to
open a dropdown. Primarily we also want this for registration flow so we
can pick payment method with a radio.
Semantic diff summary
0 added, 3 modified, 0 signature changed, 0 removed across 2 analyzed files
+35 -0 src/components/Form.test.tsx #
......@@ -60,6 +60,41 @@ const choice = field({
6060 ],
6161 });
6262
63+it("renders five choices as radio options", () => {
64+ render(
65+ <FormSection
66+ section={section([
67+ field({
68+ options: Array.from({ length: 5 }, (_, i) => ({
69+ label: `Option ${i}`,
70+ value: String(i),
71+ })),
72+ }),
73+ ])}
74+ />,
75+ );
76+ expect(
77+ screen.getAllByRole("radio").map((radio) => radio.getAttribute("value")),
78+ ).toEqual(["0", "1", "2", "3", "4"]);
79+});
80+
81+it("keeps six choices as a dropdown", () => {
82+ render(
83+ <FormSection
84+ section={section([
85+ field({
86+ options: Array.from({ length: 6 }, (_, i) => ({
87+ label: String(i),
88+ value: String(i),
89+ })),
90+ }),
91+ ])}
92+ />,
93+ );
94+ expect(screen.getByRole("combobox")).toBeDefined();
95+ expect(screen.queryByRole("radio")).toBeNull();
96+});
97+
6398 it("renders a single-choice field as buttons and submits the selected option", () => {
6499 const onSubmit = vi.fn();
65100 const { container } = render(
+31 -0 src/components/Form.tsx #
......@@ -15,6 +15,8 @@ import {
1515 FormHelperText,
1616 FormLabel,
1717 MenuItem,
18+ Radio,
19+ RadioGroup,
1820 IconButton,
1921 TextField,
2022 Stack,
......@@ -462,6 +464,35 @@ const FormField = ({
462464 );
463465 }
464466
467+ if (!readOnly && field.type === "list-single" && field.options.length <= 5) {
468+ return (
469+ <FormControl fullWidth required={field.required}>
470+ <FormLabel id={selectId}>{field.label}</FormLabel>
471+ <RadioGroup
472+ aria-labelledby={selectId}
473+ aria-describedby={field.desc ? datalistId : undefined}
474+ name={field.name}
475+ defaultValue={field.value[0] ?? ""}
476+ >
477+ {field.options.map((option) => (
478+ <FormControlLabel
479+ key={option.value}
480+ value={option.value}
481+ control={
482+ <Radio slotProps={{ input: { required: field.required } }} />
483+ }
484+ label={option.label ?? option.value}
485+ />
486+ ))}
487+ </RadioGroup>
488+ {suffix}
489+ {field.desc && (
490+ <FormHelperText id={datalistId}>{field.desc}</FormHelperText>
491+ )}
492+ </FormControl>
493+ );
494+ }
495+
465496 if (multiple) {
466497 // Terrible hack: https://github.com/mui/material-ui/issues/48678
467498 setTimeout(() => {
Back to top