Skip to content

Commit

Permalink
chore: FormControlの内部処理decorateFirstInputElementを最適化する
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Sep 13, 2024
1 parent 75d9dc4 commit d69ee4f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/smarthr-ui/src/components/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ const ErrorMessageList = React.memo<{
}

return (
<ul id={`${managedHtmlFor}_errorMessages`} className={errorListStyle} role="alert">
<div id={`${managedHtmlFor}_errorMessages`} className={errorListStyle} role="alert">
{errorMessages.map((message, index) => (
<li key={index}>
<p key={index}>
<FaCircleExclamationIcon text={message} className={errorIconStyle} />
</li>
</p>
))}
</ul>
</div>
)
})

Expand Down Expand Up @@ -377,6 +377,11 @@ const decorateFirstInputElement = (
params: DecorateFirstInputElementParams,
) => {
const { error } = params

if (!error) {
return children
}

let foundFirstInput = false

const decorate = (targets: ReactNode): ReactNode[] | ReactNode =>
Expand All @@ -390,13 +395,7 @@ const decorateFirstInputElement = (

foundFirstInput = true

const inputAttributes: ComponentProps<typeof Input> = {}

if (error) {
inputAttributes.error = true
}

return React.cloneElement(child, inputAttributes)
return React.cloneElement(child, { error: true } as ComponentProps<typeof Input>)
})

return decorate(children)
Expand Down

0 comments on commit d69ee4f

Please sign in to comment.