FieldGroup
하나의 라벨과 오류 메시지 아래에 입력과 버튼을 가로로 묶는 필드 그룹
개요
FieldGroup은 라벨 하나에 입력 여러 개, 또는 입력과 버튼을 함께 묶을 때 사용합니다.
FieldGroup 안에 FieldGroupLabel·FieldGroupWrapper·ErrorMessage를 배치하고, FieldGroupWrapper 안에 Input과 Button을 가로로 나열합니다.
FieldGroup은 Field 없이 Input 여러 개(또는 입력과 버튼)를 하나의 라벨·오류로 묶을 때도 사용합니다. 주소 검색이나 인증번호 입력처럼 AddressField·VerificationCodeField 같은 완성된 입력 컴포넌트가 있으면 그 컴포넌트를 사용합니다.
기본 예시
FieldGroupWrapper 안의 Input은 남은 폭을 나눠 채우고, 버튼은 내용 폭을 유지합니다. 버튼 폭을 고정하려면 감싸서 지정합니다.
'use client';
import { useState } from 'react';
import { Button } from '@bigmobility/vinyl-ui/button';
import {
ErrorMessage,
FieldGroup,
FieldGroupLabel,
FieldGroupWrapper,
Input,
} from '@bigmobility/vinyl-ui/field';
import { styled } from 'styled-system/jsx';
const ActionButton = styled(Button, {
base: {
width: '8.8rem',
},
});
export default function FieldGroupExample() {
const [postcode, setPostcode] = useState('');
const [error, setError] = useState('');
return (
<FieldGroup hasError={!!error}>
<FieldGroupLabel>주소</FieldGroupLabel>
<FieldGroupWrapper>
<Input
name="postcode"
value={postcode}
placeholder="우편번호"
aria-label="우편번호"
onChange={(event) => setPostcode(event.target.value)}
/>
<ActionButton variant="emphasis">검색</ActionButton>
</FieldGroupWrapper>
<ErrorMessage>{error}</ErrorMessage>
</FieldGroup>
);
}필수
required를 주면 라벨 오른쪽에 필수 표시 점이 붙고, 그룹 안 Input에 required가 전달됩니다.
<FieldGroup required>
<FieldGroupLabel>주소</FieldGroupLabel>
<FieldGroupWrapper>
<Input
name="postcode"
value={postcode}
aria-label="우편번호"
onChange={handleChange}
/>
<ActionButton variant="emphasis">검색</ActionButton>
</FieldGroupWrapper>
</FieldGroup>오류
hasError를 주면 그룹 안 Input이 오류 스타일로 바뀌고 ErrorMessage가 입력 줄 아래에 나타납니다. 그룹 상태를 따르는 Input이 같은 오류 메시지를 aria-describedby로 가리킵니다.
<FieldGroup hasError>
<FieldGroupLabel>주소</FieldGroupLabel>
<FieldGroupWrapper>
<Input
name="postcode"
value={postcode}
aria-label="우편번호"
onChange={handleChange}
/>
<ActionButton variant="emphasis">검색</ActionButton>
</FieldGroupWrapper>
<ErrorMessage>우편번호를 확인해 주세요</ErrorMessage>
</FieldGroup>비활성
disabled를 주면 그룹의 <fieldset>이 비활성화되어 중첩된 입력과 버튼도 함께 비활성화됩니다.
<FieldGroup disabled>
<FieldGroupLabel>주소</FieldGroupLabel>
<FieldGroupWrapper>
<Input
name="postcode"
value={postcode}
aria-label="우편번호"
onChange={handleChange}
/>
<ActionButton variant="emphasis">검색</ActionButton>
</FieldGroupWrapper>
</FieldGroup>Props
FieldGroup
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
id | string | No | — | 그룹 id. 오류 메시지 id의 기준. 미지정 시 자동 생성 |
hasError | boolean | No | false | 오류 상태 — 그룹 안 Input 스타일·aria, ErrorMessage 노출 제어 |
required | boolean | No | false | 필수 표시 (FieldGroupLabel·Input에 전파) |
disabled | boolean | No | false | 그룹 안의 입력과 버튼을 함께 비활성화 |
children | ReactNode | No | — | FieldGroupLabel, FieldGroupWrapper, ErrorMessage |
FieldGroupLabel
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
required | boolean | No | — | 필수 표시. 지정하면 FieldGroup 값보다 우선 |
children | ReactNode | No | — | 그룹 이름 |
FieldGroupWrapper
<div>의 표준 속성을 그대로 사용합니다. 자식으로 Input과 Button을 가로로 나열합니다.
접근성
FieldGroup은<fieldset>,FieldGroupLabel은<legend>로 렌더링되어 스크린 리더가 그룹 이름을 읽습니다.- 그룹 라벨은 각 입력의 라벨이 아니므로, 입력마다
aria-label이나Label로 이름을 붙입니다. - 오류 상태의
Input은aria-invalid와aria-describedby(그룹 오류 메시지 id)를 갖습니다. Field와FieldGroup을 중첩하면 입력의 필수 여부, 오류 상태, 오류 메시지 연결은 가장 가까운 쪽을 따릅니다. 입력에 직접 지정한 속성이 우선합니다. 바깥FieldGroup이 비활성화되면 내부 입력에disabled={false}를 지정해도 비활성화됩니다.- 오류 상태는
FieldGroup의hasError로 줍니다.Input에만hasError를 주고 그룹hasError가false이면ErrorMessage가 나타나지 않아 입력이 보이지 않는 메시지를 가리킵니다. 그룹 안ErrorMessage에는id를 주지 말고 필요하면FieldGroup에id를 줍니다(ErrorMessage에id를 주면 입력이 가리키는 id와 달라집니다).
토큰 커스터마이징
FieldGroup은 아래 시맨틱 토큰을 참조합니다. 입력·버튼·오류 메시지 토큰은 Field와 Button을 따릅니다. (테마 참고).
| 토큰 | 미리보기 | 용도 |
|---|---|---|
text.input | 그룹 라벨 | |
layout.primary | 필수 표시 점 | |
text.issue | 오류 메시지 |
이 밖에 타이포는 라벨에 body.medium-light를 사용합니다.