Skip to content

Commit 8737a75

Browse files
authoredJul 1, 2024··
feat: FormControl / Fieldset 内における入力要素の error 状態紐づけ制御用 props を足す (#4748)
* feat: FormControl / Fieldset 内における入力要素の error 状態紐づけ制御用 props を足す * chore: Story を追加
1 parent fe5b59e commit 8737a75

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
 

‎packages/smarthr-ui/src/components/FormControl/FormControl.stories.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default {
1717
title: 'Forms(フォーム)/FormControl',
1818
component: FormControl,
1919
}
20-
2120
export const All: StoryFn = () => (
2221
<Stack gap={2} as="dl">
2322
<Stack>
@@ -126,6 +125,20 @@ export const All: StoryFn = () => (
126125
</FormControl>
127126
</dd>
128127
</Stack>
128+
<Stack>
129+
<Text italic color="TEXT_GREY" as="dt">
130+
入力要素への error 自動紐づけ(VRT 用の自動紐づけを切った場合)
131+
</Text>
132+
<dd>
133+
<FormControl
134+
title="氏名"
135+
autoBindErrorInput={false}
136+
errorMessages="氏名が入力されていません。"
137+
>
138+
<Input name="fullname" value="草野栄一郎" />
139+
</FormControl>
140+
</dd>
141+
</Stack>
129142
</Stack>
130143
)
131144
All.storyName = 'all'

‎packages/smarthr-ui/src/components/FormControl/FormControl.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type Props = PropsWithChildren<{
4747
exampleMessage?: ReactNode
4848
/** タイトルの下に表示するエラーメッセージ */
4949
errorMessages?: ReactNode | ReactNode[]
50+
/** エラーがある場合に自動的に入力要素を error にするかどうか */
51+
autoBindErrorInput?: boolean
5052
/** フォームコントロールの下に表示する補足メッセージ */
5153
supplementaryMessage?: ReactNode
5254
/** `true` のとき、文字色を `TEXT_DISABLED` にする */
@@ -133,6 +135,7 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
133135
helpMessage,
134136
exampleMessage,
135137
errorMessages,
138+
autoBindErrorInput = true,
136139
supplementaryMessage,
137140
as = 'div',
138141
className,
@@ -233,7 +236,7 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
233236
{decorateFirstInputElement(children, {
234237
managedHtmlFor,
235238
describedbyIds,
236-
error: actualErrorMessages.length > 0,
239+
error: autoBindErrorInput && actualErrorMessages.length > 0,
237240
})}
238241
</div>
239242

0 commit comments

Comments
 (0)
Please sign in to comment.