cheogram-www
created pr with
cheogram-www/support-suffix-fields.1
commented
Changes are available at https://tangled.org/mrry.band/cheogram-www on branch support-suffix-fields.
cmds
checkout latest patchset:
ssh pr.pico.sh pull cheogram-www:support-suffix-fields | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull cheogram-www:support-suffix-fields [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh cheogram-www:support-suffix-fieldsadd comment to patch request:
ssh pr.pico.sh comment cheogram-www:support-suffix-fields "lgtm!"
Patchset
cheogram-www/support-suffix-fields.1
Support suffix fields in our form rendering
Eric Roberts
2026-11-18T15:27:44ZDisplays inline with other controls like hide/show password, dropdowns, input clearing, etc. The suffix appears to the left of the other controls, so it's closer to the actual input.
Diff stat
2 files changed, 92 insertions(+), 18 deletions(-)
Semantic diff summary
0 added,
1 modified,
0 signature changed,
0 removed
across 2 analyzed files
+43
-0
src/components/Form.test.tsx
#
| ... | ... | @@ -302,3 +302,46 @@ it("selects a button grid field only when there is one eligible field", () => { | |
| 302 | 302 | getButtonGridField(section([only, field({ name: "other" })]), []), | |
| 303 | 303 | ).toBeNull(); | |
| 304 | 304 | }); | |
| 305 | + | ||
| 306 | + | it.each([ | |
| 307 | + | { type: "text-single", open: false }, | |
| 308 | + | { type: "text-private", open: false }, | |
| 309 | + | { type: "list-single", open: false }, | |
| 310 | + | { type: "list-single", open: true }, | |
| 311 | + | { type: "list-multi", open: true }, | |
| 312 | + | ])( | |
| 313 | + | "renders a suffix on $type (open: $open) without submitting it", | |
| 314 | + | ({ type, open }) => { | |
| 315 | + | const { container } = render( | |
| 316 | + | <form> | |
| 317 | + | <FormSection | |
| 318 | + | section={section([ | |
| 319 | + | field({ | |
| 320 | + | type, | |
| 321 | + | open, | |
| 322 | + | value: ["one"], | |
| 323 | + | suffixLabel: "minutes", | |
| 324 | + | options: [{ label: "One", value: "one" }], | |
| 325 | + | }), | |
| 326 | + | ])} | |
| 327 | + | /> | |
| 328 | + | </form>, | |
| 329 | + | ); | |
| 330 | + | ||
| 331 | + | expect(screen.getByText("minutes")).toBeDefined(); | |
| 332 | + | expect( | |
| 333 | + | new FormData(container.querySelector("form")!).getAll("choice"), | |
| 334 | + | ).toEqual(["one"]); | |
| 335 | + | if (open) | |
| 336 | + | expect(screen.getByRole("button", { name: "Open" })).toBeDefined(); | |
| 337 | + | if (type === "text-private") { | |
| 338 | + | fireEvent.click( | |
| 339 | + | screen.getByRole("button", { name: "Display the password" }), | |
| 340 | + | ); | |
| 341 | + | expect( | |
| 342 | + | container.querySelector('input[name="choice"]')?.getAttribute("type"), | |
| 343 | + | ).toBe("text"); | |
| 344 | + | expect(screen.getByText("minutes")).toBeDefined(); | |
| 345 | + | } | |
| 346 | + | }, | |
| 347 | + | ); |
+49
-18
src/components/Form.tsx
#
| ... | ... | @@ -356,6 +356,9 @@ const FormField = ({ | |
| 356 | 356 | ? "any" | |
| 357 | 357 | : undefined; | |
| 358 | 358 | const readOnly = isResult || field.type == "fixed"; | |
| 359 | + | const suffix = field.suffixLabel ? ( | |
| 360 | + | <InputAdornment position="end">{field.suffixLabel}</InputAdornment> | |
| 361 | + | ) : null; | |
| 359 | 362 | ||
| 360 | 363 | if (field.type == "boolean") { | |
| 361 | 364 | return ( |
| ... | ... | @@ -404,7 +407,19 @@ const FormField = ({ | |
| 404 | 407 | setMultiAutocompleteValue(newValue.map(openOptionValue)) | |
| 405 | 408 | } | |
| 406 | 409 | renderInput={(params) => ( | |
| 407 | - | <TextField {...params} label={field.label} /> | |
| 410 | + | <TextField | |
| 411 | + | {...params} | |
| 412 | + | label={field.label} | |
| 413 | + | InputProps={{ | |
| 414 | + | ...params.InputProps, | |
| 415 | + | endAdornment: ( | |
| 416 | + | <> | |
| 417 | + | {suffix} | |
| 418 | + | {params.InputProps.endAdornment} | |
| 419 | + | </> | |
| 420 | + | ), | |
| 421 | + | }} | |
| 422 | + | /> | |
| 408 | 423 | )} | |
| 409 | 424 | /> | |
| 410 | 425 | </> |
| ... | ... | @@ -428,7 +443,19 @@ const FormField = ({ | |
| 428 | 443 | setAutocompleteValue(openOptionValue(newValue)); | |
| 429 | 444 | }} | |
| 430 | 445 | renderInput={(params) => ( | |
| 431 | - | <TextField {...params} label={field.label} /> | |
| 446 | + | <TextField | |
| 447 | + | {...params} | |
| 448 | + | label={field.label} | |
| 449 | + | InputProps={{ | |
| 450 | + | ...params.InputProps, | |
| 451 | + | endAdornment: ( | |
| 452 | + | <> | |
| 453 | + | {suffix} | |
| 454 | + | {params.InputProps.endAdornment} | |
| 455 | + | </> | |
| 456 | + | ), | |
| 457 | + | }} | |
| 458 | + | /> | |
| 432 | 459 | )} | |
| 433 | 460 | /> | |
| 434 | 461 | </> |
| ... | ... | @@ -478,22 +505,26 @@ const FormField = ({ | |
| 478 | 505 | }, | |
| 479 | 506 | input: { | |
| 480 | 507 | readOnly, | |
| 481 | - | endAdornment: | |
| 482 | - | field.type == "text-private" ? ( | |
| 483 | - | <InputAdornment position="end"> | |
| 484 | - | <IconButton | |
| 485 | - | title={ | |
| 486 | - | showPassword | |
| 487 | - | ? "Hide the password" | |
| 488 | - | : "Display the password" | |
| 489 | - | } | |
| 490 | - | onClick={() => setShowPassword((show) => !show)} | |
| 491 | - | edge="end" | |
| 492 | - | > | |
| 493 | - | {showPassword ? <VisibilityOff /> : <Visibility />} | |
| 494 | - | </IconButton> | |
| 495 | - | </InputAdornment> | |
| 496 | - | ) : undefined, | |
| 508 | + | endAdornment: ( | |
| 509 | + | <> | |
| 510 | + | {suffix} | |
| 511 | + | {field.type == "text-private" ? ( | |
| 512 | + | <InputAdornment position="end"> | |
| 513 | + | <IconButton | |
| 514 | + | title={ | |
| 515 | + | showPassword | |
| 516 | + | ? "Hide the password" | |
| 517 | + | : "Display the password" | |
| 518 | + | } | |
| 519 | + | onClick={() => setShowPassword((show) => !show)} | |
| 520 | + | edge="end" | |
| 521 | + | > | |
| 522 | + | {showPassword ? <VisibilityOff /> : <Visibility />} | |
| 523 | + | </IconButton> | |
| 524 | + | </InputAdornment> | |
| 525 | + | ) : null} | |
| 526 | + | </> | |
| 527 | + | ), | |
| 497 | 528 | }, | |
| 498 | 529 | }} | |
| 499 | 530 | > |