Skip to content

Commit

Permalink
Alternative solution
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 9, 2024
1 parent f4752cb commit 3f29079
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions packages/dnb-eufemia/src/extensions/forms/FieldBlock/FieldBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Space, FormLabel, FormStatus } from '../../../components'
import { FormError, ComponentProps, FieldProps } from '../types'
import FieldBlockContext from './FieldBlockContext'
import { findElementInChildren } from '../../../shared/component-helper'
import type { FormLabelAllProps } from '../../../components/FormLabel'

export type Props = Pick<
FieldProps,
Expand Down Expand Up @@ -146,22 +147,13 @@ function FieldBlock(props: Props) {
? 'info'
: null

const Label = useCallback(
({ children }) => {
return (
<FormLabel
element={enableFieldset ? 'legend' : 'label'}
forId={enableFieldset ? undefined : forId}
space={{ top: 0, bottom: 'x-small' }}
size={size}
disabled={disabled}
>
{children}
</FormLabel>
)
},
[enableFieldset, forId, size, disabled]
)
const labelProps: FormLabelAllProps = {
element: enableFieldset ? 'legend' : 'label',
forId: enableFieldset ? undefined : forId,
space: { top: 0, bottom: 'x-small' },
size,
disabled,
}

return (
<FieldBlockContext.Provider
Expand All @@ -179,14 +171,14 @@ function FieldBlock(props: Props) {
{labelDescription || labelSecondary ? (
<div className="dnb-forms-field-block__label">
{label || labelDescription ? (
<Label>
<FormLabel {...labelProps}>
{label}
{labelDescription && (
<span className="dnb-forms-field-block__label-description">
{labelDescription}
</span>
)}
</Label>
</FormLabel>
) : (
<>&nbsp;</>
)}
Expand All @@ -197,7 +189,7 @@ function FieldBlock(props: Props) {
)}
</div>
) : (
label && <Label>{label}</Label>
label && <FormLabel {...labelProps}>{label}</FormLabel>
)}

<div
Expand Down

0 comments on commit 3f29079

Please sign in to comment.