Skip to content

Commit

Permalink
fix: Fieldset > FormControlのようにネストしている場合不必要にaria-labeledbyが設定されたりするバグを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Sep 17, 2024
1 parent f25b69f commit 8f3ee67
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/smarthr-ui/src/components/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
const statusLabelList = Array.isArray(statusLabelProps) ? statusLabelProps : [statusLabelProps]

const describedbyIds = useMemo(() => {
if (!isRoleGroup) {
return ''
}

const temp = []

if (helpMessage) {
Expand All @@ -169,7 +173,14 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
}

return temp.join(' ')
}, [helpMessage, exampleMessage, supplementaryMessage, errorMessages, managedHtmlFor])
}, [
isRoleGroup,
helpMessage,
exampleMessage,
supplementaryMessage,
errorMessages,
managedHtmlFor,
])
const actualErrorMessages = useMemo(() => {
if (!errorMessages) {
return []
Expand All @@ -191,6 +202,10 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
}, [className, dangerouslyTitleHidden, innerMargin, isRoleGroup])

useEffect(() => {
if (isRoleGroup) {
return
}

const inputWrapper = inputWrapperRef?.current

if (inputWrapper) {
Expand All @@ -205,9 +220,13 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
input.setAttribute('id', managedHtmlFor)
}
}
}, [managedHtmlFor])
}, [managedHtmlFor, isRoleGroup])

useEffect(() => {
if (isRoleGroup) {
return
}

const inputWrapper = inputWrapperRef?.current

if (inputWrapper) {
Expand All @@ -222,7 +241,7 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
input.setAttribute('aria-describedby', describedbyIds)
}
}
}, [describedbyIds])
}, [describedbyIds, isRoleGroup])

return (
<Stack
Expand Down

0 comments on commit 8f3ee67

Please sign in to comment.