implement FormField component — label, input, hint, and error group#115
Open
daatsuka wants to merge 2 commits intoKingFRANKHOOD:mainfrom
Open
implement FormField component — label, input, hint, and error group#115daatsuka wants to merge 2 commits intoKingFRANKHOOD:mainfrom
daatsuka wants to merge 2 commits intoKingFRANKHOOD:mainfrom
Conversation
Collaborator
|
Kindly resolve the merge conflicts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the
FormFieldcomponent infrontend/src/components/ui/FormField.tsxand re-exports it (along withFormFieldProps) from the barrel fileindex.ts. TheFormFieldfunction accepts a label, name, optional hint, optional error, and a single child element, then usesReact.cloneElementto injectid,aria-describedby, andaria-invalidonto the child so the surrounding label and descriptors are wired up for accessibility without the consumer having to manage those attributes manually. When an error string is present the hint is hidden and a danger-colored error row (with analert-circleIcon) takes its place; when no error exists but a hint is provided, the hint renders beneath the input. Theclsxpackage was added as a new dependency to handle conditional className merging inside the wrapper<div>.The design keeps
FormFieldintentionally agnostic about which input component it wraps — it only requires a singleReact.ReactElementchild, and the child's type is declared asReact.ReactElement<Record<string, unknown>>to satisfy React 19 / TypeScript strict mode without importing every possible input component type. This means the sameFormFieldworks around<InputField>, a plain<input>, or any future select/textarea component with zero coupling. Thearia-describedbypointer is computed once at the top of the function (hintId/errorId) and conditionally passed throughcloneElement, so there is exactly one source of truth for which descriptor element is visible versus referenced.I verified this locally by running
npm run buildinsidefrontend/to confirm the TypeScript compilation succeeds with the updatedReactElementgeneric, checked thatclsxresolves correctly in the lockfile, and confirmed no runtime errors when renderingFormFieldwith and without theerrorandhintprops in the dev server.Closes #31