Skip to content

Commit

Permalink
Merge pull request #365 from delta10/fix/fielset-description
Browse files Browse the repository at this point in the history
fix: move Fieldset description out of label
  • Loading branch information
justiandevs authored Jan 6, 2025
2 parents 22e7da8 + 4a594b7 commit a0e1730
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/app/[locale]/incident/components/IncidentDescriptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
import { useTranslations } from 'next-intl'
import { IncidentFormFooter } from '@/app/[locale]/incident/components/IncidentFormFooter'
import { usePathname, useRouter } from '@/routing/navigation'
import React, { useEffect } from 'react'
import React, { useEffect, useId } from 'react'
import { getCategoryForDescription } from '@/services/classification'
import { debounce } from 'lodash'
import { useFormStore } from '@/store/form_store'
Expand All @@ -26,6 +26,7 @@ import {
} from '@/components/index'
import { getCurrentStep, getNextStepPath } from '@/lib/utils/stepper'
import { getAttachments } from '@/lib/utils/attachments'
import { clsx } from 'clsx'

export const IncidentDescriptionForm = () => {
const t = useTranslations('describe_report.form')
Expand All @@ -34,6 +35,8 @@ export const IncidentDescriptionForm = () => {
const router = useRouter()
const pathname = usePathname()
const step = getCurrentStep(pathname)
const descriptionId = useId()
const errorMessageId = useId()

useEffect(() => {
router.prefetch('/incident/add')
Expand Down Expand Up @@ -107,6 +110,8 @@ export const IncidentDescriptionForm = () => {
}
}

const invalidFiles = !!form.formState.errors.files?.message

// @ts-ignore
return (
<FormProvider {...form}>
Expand All @@ -124,20 +129,24 @@ export const IncidentDescriptionForm = () => {
{...form.register('description')}
/>

<Fieldset invalid={Boolean(form.formState.errors.files?.message)}>
<Fieldset
invalid={invalidFiles}
aria-describedby={clsx(descriptionId, {
[errorMessageId]: invalidFiles,
})}
>
<FieldsetLegend>
{`${t('describe_textarea_heading')} (${tGeneral('form.not_required_short')})`}
<FormFieldDescription>
{t('describe_upload_description')}
</FormFieldDescription>

{Boolean(form.formState.errors.files?.message) &&
form.formState.errors.files?.message && (
<FormFieldErrorMessage>
{form.formState.errors.files?.message}
</FormFieldErrorMessage>
)}
</FieldsetLegend>
<FormFieldDescription id={descriptionId}>
{t('describe_upload_description')}
</FormFieldDescription>

{invalidFiles && (
<FormFieldErrorMessage id={errorMessageId}>
{form.formState.errors.files?.message}
</FormFieldErrorMessage>
)}

{/* @ts-ignore */}
<FileUpload {...register('files', { required: false })} />
Expand Down

0 comments on commit a0e1730

Please sign in to comment.