Skip to content

Commit

Permalink
Add description option for inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerdavis1 committed Jan 8, 2024
1 parent 643442c commit d2ed1ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/components/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ export function ErrorList({
)
}

export function Description({ text }: { text: string }) {
return <p className="text-sm text-muted-foreground">{text}</p>
}

export function Field({
labelProps,
inputProps,
errors,
className,
description,
}: {
labelProps: Omit<React.LabelHTMLAttributes<HTMLLabelElement>, 'className'>
inputProps: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'className'>
errors?: ListOfErrors
className?: string
description?: string
}) {
const fallbackId = useId()
const id = inputProps.id ?? fallbackId
Expand All @@ -60,6 +66,7 @@ export function Field({
aria-describedby={errorId}
{...inputProps}
/>
{description && <Description text={description} />}
<div className="min-h-[32px] px-4 pb-3 pt-1">
{errorId ? <ErrorList id={errorId} errors={errors} /> : null}
</div>
Expand Down
11 changes: 8 additions & 3 deletions app/routes/_auth+/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default function OnboardingPage() {
<Field
labelProps={{
htmlFor: fields.username.id,
children: 'Username (Cannot be an email address)',
children: 'Username',
}}
inputProps={{
...conform.input(fields.username),
Expand All @@ -181,17 +181,22 @@ export default function OnboardingPage() {
typeof fields.username.initialError !== 'undefined',
}}
errors={fields.username.errors}
description="Cannot be an email address"
/>
<Field
labelProps={{ htmlFor: fields.name.id, children: 'Name' }}
labelProps={{ htmlFor: fields.name.id, children: 'Full Name' }}
inputProps={{
...conform.input(fields.name),
autoComplete: 'name',
}}
errors={fields.name.errors}
/>
<Field
labelProps={{ htmlFor: fields.phone.id, children: 'Phone Number' }}
labelProps={{
htmlFor: fields.phone.id,
children: 'Phone Number',
}}
description="Must be 10 digits"
inputProps={{
...conform.input(fields.phone, { type: 'tel' }),
autoComplete: 'tel',
Expand Down

0 comments on commit d2ed1ec

Please sign in to comment.