본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

@atlaskit/form

원문 보기 위키 갱신

@atlaskit/form은 폼을 만들 때 필요한 컴포넌트 모음이에요. 검증(validation), 상태 관리, 에러/도움말/성공 메시지 표시까지 한번에 처리해 준답니다. Field, Fieldset, Form, 각종 폼 필드 래퍼, 그리고 Label, ErrorMessage, ValidMessage 같은 메시지 컴포넌트들이 함께 들어 있어요. 유효성 검사는 물론 접근성(accessibility)까지 챙기고 싶을 때 딱 맞는 패키지예요.

출처: 문서

본문

Legend 컴포넌트

fieldset 그룹을 위한 legend 컴포넌트예요. 관련된 필드들을 묶을 때 Fieldset과 함께 사용해요.

  • Keywords: form, legend, fieldset
  • Categories: form
  • Status: general-availability

예제

import { Checkbox } from '@atlaskit/checkbox/checkbox';
import { CheckboxField } from '@atlaskit/form/checkbox-field';
import { Fieldset } from '@atlaskit/form/fieldset';
import Form from '@atlaskit/form/form';
import { Box } from '@atlaskit/primitives/compiled/box';
const FormFieldsetExample = (): React.JSX.Element => (
	<Box>
		<Form onSubmit={(data) => console.log(data)}>
			<Fieldset legend="Apps">
				<CheckboxField name="app" value="jira">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Jira" />}
				</CheckboxField>
				<CheckboxField name="app" value="confluence">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Confluence" />}
				</CheckboxField>
				<CheckboxField name="app" value="bitbucket">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Bitbucket" />}
				</CheckboxField>
			</Fieldset>
			<Fieldset legend="Teams">
				<CheckboxField name="teams" value="dst">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Design System Team" />}
				</CheckboxField>
				<CheckboxField name="teams" value="design-ops">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Design Ops" />}
				</CheckboxField>
				<CheckboxField name="teams" value="content">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Content Ops" />}
				</CheckboxField>
			</Fieldset>
		</Form>
	</Box>
);
export default FormFieldsetExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal (required)

사용 가이드

  • Fieldset과 함께 사용해서 필드 그룹을 설명해요
  • 접근성을 위해 필수예요

내용 가이드

  • 명확하고 설명적인 legend 텍스트를 사용해요

CharacterCounter 컴포넌트

텍스트 입력의 문자 수를 표시해 주는 컴포넌트예요. 단독으로 쓰거나 CharacterCounterField와 함께 쓸 수 있어요.

  • Keywords: form, character, counter
  • Categories: form
  • Status: general-availability

예제

import React, { useState } from 'react';
import { CharacterCounter } from '@atlaskit/form/character-counter';
import { Label } from '@atlaskit/form/label/default';
import { Box } from '@atlaskit/primitives/compiled/box';
import { Stack } from '@atlaskit/primitives/compiled/stack';
import TextArea from '@atlaskit/textarea/text-area';
import TextField from '@atlaskit/textfield/text-field';
/**
 * Standalone CharacterCounter example - used outside of Form context
 * This is useful when you need character counting in custom implementations
 * that don't use the Form component or have a specific layout requirements
 * that CharacterCounterField does not provide. Generally speaking, it is
 * recommended to use CharacterCounterField for consistent styling.
 */
const StandaloneCharacterCounterExample = (): React.JSX.Element => {
	const [textFieldValue, setTextFieldValue] = useState('');
	const [textAreaValue, setTextAreaValue] = useState('');
	const textFieldId = 'standalone-text-field';
	const textAreaId = 'standalone-text-area';
	// Character limits
	const maxCharacters = 50;
	const minCharacters = 10;
	const textAreaMaxCharacters = 200;
	// Calculate error states for styling
	const isTextFieldTooLong = textFieldValue.length > maxCharacters;
	const isTextAreaTooShort = textAreaValue.length < minCharacters;
	const isTextAreaTooLong = textAreaValue.length > textAreaMaxCharacters;
	const hasTextAreaError = isTextAreaTooShort || isTextAreaTooLong;
	return (
		<Stack space="space.200">
			{/* Example 1: TextField with maximum character limit */}
			<Box>
				<Label htmlFor={textFieldId}>Display name</Label>
				<TextField
					id={textFieldId}
					value={textFieldValue}
					onChange={(e) => setTextFieldValue(e.currentTarget.value)}
					aria-describedby={`${textFieldId}-character-counter`}
					isInvalid={isTextFieldTooLong}
				/>
				<CharacterCounter
					currentValue={textFieldValue}
					maxCharacters={maxCharacters}
					inputId={textFieldId}
					shouldShowAsError={isTextFieldTooLong}
				/>
			</Box>
			{/* Example 2: TextArea with both minimum and maximum limits */}
			<Box>
				<Label htmlFor={textAreaId}>Bio</Label>
				<TextArea
					id={textAreaId}
					value={textAreaValue}
					onChange={(e) => setTextAreaValue(e.currentTarget.value)}
					aria-describedby={`${textAreaId}-character-counter`}
					resize="auto"
					minimumRows={3}
					isInvalid={hasTextAreaError}
					isRequired
				/>
				<CharacterCounter
					currentValue={textAreaValue}
					minCharacters={minCharacters}
					maxCharacters={textAreaMaxCharacters}
					inputId={textAreaId}
					shouldShowAsError={hasTextAreaError}
				/>
			</Box>
		</Stack>
	);
};
export default StandaloneCharacterCounterExample;

Props

Prop Type Description
currentValue string Current value of the input field
inputId string ID of the associated input for accessibility
maxCharacters number Maximum number of characters allowed (optional)
minCharacters number Minimum number of characters required (optional)
overMaximumMessage string Optional custom message to display when character limit is exceeded
shouldShowAsError boolean Whether to style violations as errors (red text + icon)
underMaximumMessage string Optional custom message to display when character limit is not exceeded
underMinimumMessage string Optional custom message to display when minimum character requirement is not met

사용 가이드

  • 텍스트 입력의 문자 수를 표시할 때 사용해요
  • 현재 길이와 최대 길이를 제공해요
  • 통일된 스타일링을 위해서는 CharacterCounterField를 사용하는 걸 권장해요

CharacterCounterField 컴포넌트

문자 수 표시가 포함된 폼 필드예요. Field와 CharacterCounter를 결합한 것이에요.

  • Keywords: form, character, counter, field
  • Categories: form
  • Status: general-availability

예제

import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { CharacterCounterField } from '@atlaskit/form/character-counter-field';
import { type FieldProps } from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import { Text } from '@atlaskit/primitives/compiled/text';
import TextArea from '@atlaskit/textarea/text-area';
import TextField from '@atlaskit/textfield/text-field';
/**
 * Mock i18n setup - in a real app, these would come from your i18n library
 * Example: import { useIntl } from 'react-intl';
 */
const messages = {
	'bio.underMinimum': 'Enter at least {minimum} characters.',
	'bio.overMaximum': 'Your bio exceeds the maximum length of {maximum} characters',
};
// Mock formatMessage - in a real app: const { formatMessage } = useIntl();
const formatMessage = (
	messageDescriptor: { id: keyof typeof messages },
	values?: Record<string, string | number>,
): string => {
	let message = messages[messageDescriptor.id];
	if (values) {
		Object.entries(values).forEach(([key, value]) => {
			message = message.replace(new RegExp(`\\{${key}\\}`, 'g'), String(value));
		});
	}
	return message;
};
const FormCharacterCounterExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
			}}
		>
			<FormHeader title="Profile">
				<Text as="p" aria-hidden="true">
					Required fields are marked with an asterisk <RequiredAsterisk />
				</Text>
			</FormHeader>
			<FormSection>
				{/* Example 1: Maximum characters only with default messages */}
				<CharacterCounterField
					name="displayName"
					label="Display name"
					isRequired
					maxCharacters={50}
					helperMessage="The name you’d like other people to see."
					validate={(value) =>
						value === 'Atlas' ? 'Atlas is already in use, try something else' : undefined
					}
				>
					{({ fieldProps }: { fieldProps: FieldProps<string> }) => (
						<TextField autoComplete="name" {...fieldProps} />
					)}
				</CharacterCounterField>
				{/* Example 2: Minimum characters only with default messages */}
				<CharacterCounterField<string, HTMLTextAreaElement>
					name="tagline"
					label="Professional tagline"
					minCharacters={10}
					helperMessage="A short headline that describes what you do."
				>
					{({ fieldProps }) => <TextArea {...fieldProps} resize="auto" minimumRows={2} />}
				</CharacterCounterField>
				{/* Example 3: Using i18n messages with character counter */}
				<CharacterCounterField<string, HTMLTextAreaElement>
					name="bio"
					label="Bio"
					isRequired
					minCharacters={10}
					maxCharacters={200}
					helperMessage="Tell us about yourself, your interests, and experience."
					underMinimumMessage={formatMessage({ id: 'bio.underMinimum' }, { minimum: 10 })}
					overMaximumMessage={formatMessage({ id: 'bio.overMaximum' }, { maximum: 200 })}
				>
					{({ fieldProps }) => <TextArea {...fieldProps} resize="auto" minimumRows={3} />}
				</CharacterCounterField>
			</FormSection>
			<FormFooter align="start">
				<ButtonGroup label="Form submit options">
					<Button type="submit" appearance="primary">
						Save profile
					</Button>
					<Button appearance="subtle">Cancel</Button>
				</ButtonGroup>
			</FormFooter>
		</Form>
	</Flex>
);
export default FormCharacterCounterExample;

Props

Prop Type Description
children (args: { fieldProps: FieldProps<FieldValue, Element>; error?: string; valid: boolean; meta: Meta; }) => ReactNode The input component to render (required)
defaultValue FieldValue | ((currentDefaultValue?: FieldValue) => FieldValue) Sets the default value of the field
elementAfterLabel string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Element displayed after the label, and after the red asterisk if field is required
helperMessage string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Helper text displayed above the input to provide additional context or instructions
id string Passed to the ID attribute of the field
isDisabled boolean Sets whether the field is disabled
isRequired boolean Sets whether the field is required for submission
label string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Label displayed above the form field
maxCharacters number Maximum number of characters allowed
minCharacters number Minimum number of characters required
name string Specifies the name of the field (required)
overMaximumMessage string Custom message displayed when input exceeds the maximum character limit
underMaximumMessage string Custom message displayed when input is under the maximum limit
underMinimumMessage string Custom message displayed when input is under the minimum requirement
validate (value: FieldValue, formState: Object, fieldState: Meta) => string | void | Promise<string | void> Checks whether the field input is valid

사용 가이드

  • 문자 수 제한이 중요한 경우(예: 설명, 요약)에 사용해요
  • 제한을 위해 maxLength를 제공해요
  • 현재 개수와 제한을 표시해요

CheckboxField 컴포넌트

체크박스 입력을 위한 폼 필드예요. Checkbox에 폼 필드 동작을 감싼 것이에요.

  • Keywords: form, checkbox, field
  • Categories: form
  • Status: general-availability

예제

import Button from '@atlaskit/button/default/button';
import { Checkbox } from '@atlaskit/checkbox/checkbox';
import { CheckboxField } from '@atlaskit/form/checkbox-field';
import { Fieldset } from '@atlaskit/form/fieldset';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { Flex } from '@atlaskit/primitives/compiled/flex';
const FormCheckboxExample = (): React.JSX.Element => {
	return (
		<Flex direction="column">
			<Form onSubmit={(data) => console.log(data)}>
				<Fieldset legend="Apps">
					<CheckboxField name="app" value="jira">
						{({ fieldProps }) => <Checkbox {...fieldProps} label="Jira" />}
					</CheckboxField>
					<CheckboxField name="app" value="confluence">
						{({ fieldProps }) => <Checkbox {...fieldProps} label="Confluence" />}
					</CheckboxField>
					<CheckboxField name="app" value="bitbucket">
						{({ fieldProps }) => <Checkbox {...fieldProps} label="Bitbucket" />}
					</CheckboxField>
				</Fieldset>
				<FormFooter align="start">
					<Button type="submit" appearance="primary">
						Submit
					</Button>
				</FormFooter>
			</Form>
		</Flex>
	);
};
export default FormCheckboxExample;

Props

Prop Type Description
children (args: { fieldProps: CheckboxFieldProps; error?: string; valid: boolean; meta: Meta; }) => React.ReactNode Content to render in the checkbox field (required)
defaultIsChecked boolean Sets the default state of the checkbox as checked
isDisabled boolean Sets whether the field is disabled
isRequired boolean Sets whether the field is required for submission
label string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Label displayed beside the checkbox
name string Specifies the name of the field (required)
value string The value of the checkbox

사용 가이드

  • 단일 또는 그룹 체크박스 옵션에 사용해요
  • name과 value props를 제공해요
  • @atlaskit/checkbox의 Checkbox와 함께 동작해요

Field 컴포넌트

라벨, 검증, 에러 처리를 제공하는 폼 필드 래퍼예요. component prop을 통해 어떤 폼 컨트롤과도 함께 쓸 수 있어요.

  • Keywords: form, field, input, validation
  • Categories: form
  • Status: general-availability

예제

import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import TextField from '@atlaskit/textfield/text-field';
const FormFieldExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form onSubmit={(data) => console.log('form data', data)}>
			<>
				<Field
					name="username"
					defaultValue=""
					label="Username"
					isRequired
					helperMessage="Your username can have up to 16 characters."
					validMessage="Username is valid."
					validate={(value) => {
						if (!value) {
							return 'Username is required.';
						} else if (value && value.length > 16) {
							return 'Username must be 16 characters or less.';
						}
					}}
					component={({ fieldProps }) => <TextField {...fieldProps} />}
				/>
				<FormFooter align="start">
					<ButtonGroup label="Form submit options">
						<Button type="submit" appearance="primary">
							Submit
						</Button>
						<Button appearance="subtle">Cancel</Button>
					</ButtonGroup>
				</FormFooter>
			</>
		</Form>
	</Flex>
);
export default FormFieldExample;

Props

Prop Type Description
children (args: { fieldProps: FieldProps<FieldValue, Element>; error?: string; valid: boolean; meta: Meta; }) => React.ReactNode Content to render in the field
component (args: { fieldProps: FieldProps<FieldValue, Element>; }) => React.ReactNode Content to render in the field
defaultValue FieldValue | ((currentDefaultValue?: FieldValue) => FieldValue) Sets the default value of the field
elementAfterLabel string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Element displayed after the label, and after the red asterisk if field is required
errorMessage string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Renders an ErrorMessage with the provided content when using the component prop
helperMessage string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Renders a HelperMessage with the provided content when using the component prop
id string Passed to the ID attribute of the field
isDisabled boolean Sets whether the field is disabled
isRequired boolean Sets whether the field is required for submission
label string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Label displayed above the form field
name string Specifies the name of the field (required)
transform (event: FieldValue | React.FormEvent<Element>, current: FieldValue) => FieldValue Access the current field value and transform it to return a different field value
validate (value: FieldValue, formState: Object, fieldState: Meta) => string | void | Promise<string | void> Checks whether the field input is valid
validMessage string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Renders a ValidMessage with the provided content when using the component prop

사용 가이드

  • 각 폼 입력에 사용하고, name, label, component를 제공해요
  • 필수 필드에는 isRequired를 사용해요
  • 검증 로직에는 validate를, 안내 문구에는 helperMessage를 사용해요
  • 메시지는 MessageWrapper 안에 HelperMessage, ErrorMessage, ValidMessage로 감싸요

내용 가이드

  • 명확하고 설명적인 라벨을 사용해요
  • 구체적인 에러 메시지를 제공해요
  • 복잡한 필드에는 도움말 텍스트를 사용해요

Fieldset 컴포넌트

관련된 폼 필드들을 legend와 함께 그룹으로 묶어요. 라디오 그룹이나 논리적으로 묶인 그룹에 사용해요.

  • Keywords: form, fieldset, group
  • Categories: form
  • Status: general-availability

예제

import { Checkbox } from '@atlaskit/checkbox/checkbox';
import { CheckboxField } from '@atlaskit/form/checkbox-field';
import { Fieldset } from '@atlaskit/form/fieldset';
import Form from '@atlaskit/form/form';
import { Box } from '@atlaskit/primitives/compiled/box';
const FormFieldsetExample = (): React.JSX.Element => (
	<Box>
		<Form onSubmit={(data) => console.log(data)}>
			<Fieldset legend="Apps">
				<CheckboxField name="app" value="jira">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Jira" />}
				</CheckboxField>
				<CheckboxField name="app" value="confluence">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Confluence" />}
				</CheckboxField>
				<CheckboxField name="app" value="bitbucket">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Bitbucket" />}
				</CheckboxField>
			</Fieldset>
			<Fieldset legend="Teams">
				<CheckboxField name="teams" value="dst">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Design System Team" />}
				</CheckboxField>
				<CheckboxField name="teams" value="design-ops">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Design Ops" />}
				</CheckboxField>
				<CheckboxField name="teams" value="content">
					{({ fieldProps }) => <Checkbox {...fieldProps} label="Content Ops" />}
				</CheckboxField>
			</Fieldset>
		</Form>
	</Box>
);
export default FormFieldsetExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Content to render in the fieldset (required)
legend string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Label describing the contents of the fieldset

사용 가이드

  • 그룹을 설명할 때 Legend와 함께 사용해요
  • 라디오 그룹과 논리적 필드 그룹에 사용해요
  • 접근성을 높여줘요

Form 컴포넌트

검증과 상태 관리를 갖춘 폼을 만들기 위한 컴포넌트예요.

  • Keywords: form, validation, field, input, submit, state
  • Categories: form
  • Status: general-availability

예제

import Button from '@atlaskit/button/default/button';
import { Checkbox } from '@atlaskit/checkbox/checkbox';
import { CheckboxField } from '@atlaskit/form/checkbox-field';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import TextField from '@atlaskit/textfield/text-field';
const Example = (): React.JSX.Element => (
	<Form onSubmit={(data) => console.log('validated form', data)}>
		<FormHeader title="Basic Form">
			<p>Fill out the form below</p>
		</FormHeader>
		<Field
			name="username"
			label="Username"
			isRequired
			validate={(value) =>
				value && value.length < 3 ? 'Username must be at least 3 characters' : undefined
			}
			component={({ fieldProps }) => <TextField {...fieldProps} />}
		/>
		<CheckboxField name="terms" value="terms">
			{({ fieldProps }) => <Checkbox {...fieldProps} label="I accept the terms" />}
		</CheckboxField>
		<FormFooter>
			<Button type="submit" appearance="primary">
				Create Account
			</Button>
		</FormFooter>
	</Form>
);
export default Example;

Props

Prop Type Description
autocomplete "off" | "on" Indicates whether the value of the form's controls can be automatically completed by the browser
children React.ReactNode | (() => void) | ((args: FormChildrenArgs<FormValues>) => React.ReactNode) The contents rendered inside of the form (required)
formProps { [x: string]: any; } & ExcludeReservedFormProps When Form renders JSX children directly and not using a function to spread formProps manually, the properties in this formProps prop will be spread on an internally rendered HTML form element
id string id attribute applied to the form element
isDisabled boolean Sets the form and its fields as disabled
label string Accessible name to be applied to the form element
labelId string ID of the element that has the accessible name to be applied to the form element
name string name attribute applied to the form element
noValidate boolean Indicates if the inputs within the form will bypass HTML5 constraint validation when submitted
onSubmit (values: FormValues, form: FormApi<FormValues>, callback?: (errors?: Record<string, string>) => void) => void | Object | Promise<...> Event handler called when the form is submitted (required)
xcss false | (XCSSValue<"appearance" | "grid" | "clipPath" | "filter" | "marker" | "mask" | "borderColor" | "translate" | "content" | "color" | "top" | "bottom" | "right" | "left" | "backgroundColor" | ... 486 more ... | "glyphOrientationVertical", DesignTokenStyles, ""> & ... 4 more ... & { ...; }) Apply a subset of permitted styles powered by Atlassian Design System design tokens

사용 가이드

  • 사용자가 정보를 입력하고 제출해야 할 때 사용해요(설정, 작업 항목 만들기)
  • textfield, select, radio, checkbox 등 다른 폼 컨트롤과 함께 사용해요
  • 구조: 제목, 설명, 필수 legend, 별표(asterisk), 도움말 텍스트, 필드 위 라벨, 필요한 곳의 문자 카운터, 섹션, 기본/보조 액션이 담긴 푸터
  • 명확한 필드 라벨과 안내를 제공해요
  • 필수 필드는 별표(*)로 표시해요
  • 구체적인 에러 메시지를 제공해요

내용 가이드

  • 명확하고 간결한 라벨을 사용해요
  • 중요한 정보는 placeholder만으로 전달하지 말고 라벨과 도움말 텍스트를 사용해요(예외: 아이콘 + 라벨이 있는 검색)
  • 구체적인 에러 메시지를 제공해요
  • 일관된 용어를 사용해요
  • 항상 보이는 라벨을 포함해요(예외: 검색 필드)
  • 필드 길이를 의도한 내용물 길이에 맞춰요

접근성 가이드

  • 적절할 때 첫 번째 필드에 autofocus를 적용해요
  • 모든 필드에 보이는 라벨을 사용해요(검색은 예외)
  • 제출 버튼을 절대 비활성화하지 말고, 사용자가 어떻게 진행해야 하는지 알 수 있도록 검증과 안내를 사용해요
  • autofill 토큰을 지원하고, 적절할 때 새로고침에도 폼 상태를 유지해요
  • 명확한 안내와 함께 인라인 검증을 사용해요
  • 모든 폼 필드에 명확한 라벨을 제공해요
  • 필드 사이의 키보드 이동을 보장해요
  • 필수 필드를 명확하게 표시해요

FormFooter 컴포넌트

폼의 푸터 섹션이에요. 보통 제출(submit)과 취소(cancel) 버튼이 들어가요.

  • Keywords: form, footer, actions, buttons
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { ValidMessage } from '@atlaskit/form/valid-message';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import RadioGroup from '@atlaskit/radio/radio-group';
import TextField from '@atlaskit/textfield/text-field';
const FormDefaultExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form<{ schema: string; key: string; type: string }>
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
				return new Promise((resolve) => setTimeout(resolve, 2000)).then(() =>
					!data.schema ? { schema: 'A schema name is required' } : undefined,
				);
			}}
		>
			{({ formProps, submitting }) => (
				<form {...formProps} name="create">
					<FormHeader title="Create schema">
						<p aria-hidden="true">
							Required fields are marked with an asterisk <RequiredAsterisk />
						</p>
					</FormHeader>
					<FormSection>
						<Field
							name="schema"
							label="Schema name"
							isRequired
							defaultValue=""
							validate={(value) => (!value ? 'A schema name is required' : undefined)}
						>
							{({ fieldProps, error }) => {
								return (
									<Fragment>
										<TextField autoComplete="off" {...fieldProps} />
										<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="key"
							label="Key"
							defaultValue=""
							isRequired
							validate={(value) => {
								if (!value) {
									return 'A key is required';
								}
								if (value.length < 8) {
									return 'Key needs to be at least 8 characters.';
								}
							}}
						>
							{({ fieldProps, error, valid, meta }) => {
								return (
									<Fragment>
										<TextField type="key" {...fieldProps} />
										<MessageWrapper>
											<HelperMessage>
												Create a unique key, minimum of 8 characters. Example key: IT-infrastructure
											</HelperMessage>
											{error && <ErrorMessage>{error}</ErrorMessage>}
											{valid && meta.dirty ? <ValidMessage>Key is unique</ValidMessage> : null}
										</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="type"
							defaultValue=""
							label="Schema type"
							component={({ fieldProps }) => (
								<RadioGroup
									options={[
										{
											name: 'type',
											value: 'project-admin',
											label: 'Public',
										},
										{
											name: 'type',
											value: 'admin',
											label: 'Private',
										},
									]}
									{...fieldProps}
								/>
							)}
						/>
					</FormSection>
					<FormFooter align="start">
						<ButtonGroup label="Form submit options">
							<Button type="submit" appearance="primary">
								Create
							</Button>
							<Button appearance="subtle" isLoading={submitting}>
								Cancel
							</Button>
						</ButtonGroup>
					</FormFooter>
				</form>
			)}
		</Form>
	</Flex>
);
export default FormDefaultExample;

Props

Prop Type Description
align "end" | "start" Sets the alignment of the footer contents
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Content to render in the footer of the form

사용 가이드

  • 기본/보조 액션에 사용해요
  • 기본 버튼은 오른쪽에 두고, 닫기(취소)를 위해 Cancel을 포함해요
  • 왼쪽/오른쪽 정렬을 위해 align prop을 사용해요

내용 가이드

  • 버튼 라벨에는 동작 동사(action verb)를 사용해요
  • 기본 버튼은 폼의 동작을 반영해요

FormHeader 컴포넌트

폼의 헤더 섹션이에요. 보통 제목과 선택적인 설명이 들어가요.

  • Keywords: form, header, title, description
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { ValidMessage } from '@atlaskit/form/valid-message';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import RadioGroup from '@atlaskit/radio/radio-group';
import TextField from '@atlaskit/textfield/text-field';
const FormDefaultExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form<{ schema: string; key: string; type: string }>
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
				return new Promise((resolve) => setTimeout(resolve, 2000)).then(() =>
					!data.schema ? { schema: 'A schema name is required' } : undefined,
				);
			}}
		>
			{({ formProps, submitting }) => (
				<form {...formProps} name="create">
					<FormHeader title="Create schema">
						<p aria-hidden="true">
							Required fields are marked with an asterisk <RequiredAsterisk />
						</p>
					</FormHeader>
					<FormSection>
						<Field
							name="schema"
							label="Schema name"
							isRequired
							defaultValue=""
							validate={(value) => (!value ? 'A schema name is required' : undefined)}
						>
							{({ fieldProps, error }) => {
								return (
									<Fragment>
										<TextField autoComplete="off" {...fieldProps} />
										<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="key"
							label="Key"
							defaultValue=""
							isRequired
							validate={(value) => {
								if (!value) {
									return 'A key is required';
								}
								if (value.length < 8) {
									return 'Key needs to be at least 8 characters.';
								}
							}}
						>
							{({ fieldProps, error, valid, meta }) => {
								return (
									<Fragment>
										<TextField type="key" {...fieldProps} />
										<MessageWrapper>
											<HelperMessage>
												Create a unique key, minimum of 8 characters. Example key: IT-infrastructure
											</HelperMessage>
											{error && <ErrorMessage>{error}</ErrorMessage>}
											{valid && meta.dirty ? <ValidMessage>Key is unique</ValidMessage> : null}
										</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="type"
							defaultValue=""
							label="Schema type"
							component={({ fieldProps }) => (
								<RadioGroup
									options={[
										{
											name: 'type',
											value: 'project-admin',
											label: 'Public',
										},
										{
											name: 'type',
											value: 'admin',
											label: 'Private',
										},
									]}
									{...fieldProps}
								/>
							)}
						/>
					</FormSection>
					<FormFooter align="start">
						<ButtonGroup label="Form submit options">
							<Button type="submit" appearance="primary">
								Create
							</Button>
							<Button appearance="subtle" isLoading={submitting}>
								Cancel
							</Button>
						</ButtonGroup>
					</FormFooter>
				</form>
			)}
		</Form>
	</Flex>
);
export default FormDefaultExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Child content to render in the form below the title and description
description string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Description or subtitle of the form
title string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Title of the form

사용 가이드

  • 폼 최상단에 사용해서 맥락을 제공해요
  • 제목과 선택적인 설명 또는 힌트 텍스트를 포함해요
  • 필수 필드 표시에는 RequiredAsterisk legend를 사용해요

내용 가이드

  • 명확하고 설명적인 폼 제목을 사용해요
  • 설명은 간결하게 유지해요

FormSection 컴포넌트

폼 안에서 관련 필드들을 묶어 주는 섹션이에요.

  • Keywords: form, section, group, fields
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { ValidMessage } from '@atlaskit/form/valid-message';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import RadioGroup from '@atlaskit/radio/radio-group';
import TextField from '@atlaskit/textfield/text-field';
const FormDefaultExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form<{ schema: string; key: string; type: string }>
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
				return new Promise((resolve) => setTimeout(resolve, 2000)).then(() =>
					!data.schema ? { schema: 'A schema name is required' } : undefined,
				);
			}}
		>
			{({ formProps, submitting }) => (
				<form {...formProps} name="create">
					<FormHeader title="Create schema">
						<p aria-hidden="true">
							Required fields are marked with an asterisk <RequiredAsterisk />
						</p>
					</FormHeader>
					<FormSection>
						<Field
							name="schema"
							label="Schema name"
							isRequired
							defaultValue=""
							validate={(value) => (!value ? 'A schema name is required' : undefined)}
						>
							{({ fieldProps, error }) => {
								return (
									<Fragment>
										<TextField autoComplete="off" {...fieldProps} />
										<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="key"
							label="Key"
							defaultValue=""
							isRequired
							validate={(value) => {
								if (!value) {
									return 'A key is required';
								}
								if (value.length < 8) {
									return 'Key needs to be at least 8 characters.';
								}
							}}
						>
							{({ fieldProps, error, valid, meta }) => {
								return (
									<Fragment>
										<TextField type="key" {...fieldProps} />
										<MessageWrapper>
											<HelperMessage>
												Create a unique key, minimum of 8 characters. Example key: IT-infrastructure
											</HelperMessage>
											{error && <ErrorMessage>{error}</ErrorMessage>}
											{valid && meta.dirty ? <ValidMessage>Key is unique</ValidMessage> : null}
										</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="type"
							defaultValue=""
							label="Schema type"
							component={({ fieldProps }) => (
								<RadioGroup
									options={[
										{
											name: 'type',
											value: 'project-admin',
											label: 'Public',
										},
										{
											name: 'type',
											value: 'admin',
											label: 'Private',
										},
									]}
									{...fieldProps}
								/>
							)}
						/>
					</FormSection>
					<FormFooter align="start">
						<ButtonGroup label="Form submit options">
							<Button type="submit" appearance="primary">
								Create
							</Button>
							<Button appearance="subtle" isLoading={submitting}>
								Cancel
							</Button>
						</ButtonGroup>
					</FormFooter>
				</form>
			)}
		</Form>
	</Flex>
);
export default FormDefaultExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Content or components to render after the description
description string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Description of the contents of the section
title string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Title of the form section

사용 가이드

  • 관련 필드들을 논리적으로 묶을 때 사용해요
  • 섹션 제목은 선택사항이에요
  • 폼을 훑어보기(scannability) 좋게 만들어 줘요

내용 가이드

  • 제공할 때는 명확한 섹션 제목을 사용해요
  • 관련 필드들을 함께 묶어요

Label 컴포넌트

폼 필드를 위한 라벨 컴포넌트예요. 보통 Field 내부에서 쓰이지만, 단독으로도 쓸 수 있어요.

  • Keywords: form, label
  • Categories: form
  • Status: general-availability

예제

import { Label } from '@atlaskit/form/label/default';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import TextField from '@atlaskit/textfield/text-field';
const LabelStandaloneExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Label htmlFor="label-standalone-email">Work email</Label>
		<TextField id="label-standalone-email" name="email" type="email" autoComplete="email" />
	</Flex>
);
export default LabelStandaloneExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal (required)
htmlFor string (required)
id string

사용 가이드

  • 필드 라벨에는 Field와 함께 사용해요
  • htmlFor로 폼 컨트롤과 연결해요

내용 가이드

  • 명확하고 설명적인 라벨을 사용해요

ErrorMessage 컴포넌트

폼 필드의 검증 에러 텍스트를 표시해요.

  • Keywords: form, error, message, validation
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import { Text } from '@atlaskit/primitives/compiled/text';
import Select from '@atlaskit/select/default';
import { type ValueType } from '@atlaskit/select/types';
import TextField from '@atlaskit/textfield/text-field';
interface Option {
	label: string;
	value: string;
}
const members = [
	{ label: 'Arni Singh', value: 'asingh' },
	{ label: 'Hermione Walters', value: 'hwalters' },
	{ label: 'Parvi Karan', value: 'pkaran' },
	{ label: 'Charlie Li', value: 'cli' },
	{ label: 'Silus Graham', value: 'sgraham' },
	{ label: 'Jorge Oroza', value: 'joroza' },
];
const userNameData = ['jsmith', 'mchan'];
const errorMessages = {
	shortUsername: 'Enter a team name longer than 4 characters.',
	usernameInUse: 'This team name is already taken. Use a different name',
	usernameIsRequired: 'A team name is required.',
	selectError: 'Select at least one team member.',
};
const checkUserName = (value: string | undefined) => {
	return value && userNameData.includes(value);
};
export default function FieldLevelValidationExample(): React.JSX.Element {
	const handleSubmit = (formState: { command: string }) => {
		console.log('form state', formState);
	};
	return (
		<Flex direction="column">
			<Form noValidate onSubmit={handleSubmit}>
				<FormHeader title="Create team">
					<Text as="p" aria-hidden={true}>
						Required fields are marked with an asterisk <RequiredAsterisk />
					</Text>
				</FormHeader>
				<Field
					name="team"
					label="Team name"
					defaultValue=""
					isRequired
					validate={(value) => {
						if (!value) {
							return errorMessages.usernameIsRequired;
						} else if (value.length <= 5) {
							return errorMessages.shortUsername;
						} else if (checkUserName(value)) {
							return errorMessages.usernameInUse;
						}
					}}
					component={({ fieldProps }) => <TextField {...fieldProps} />}
				/>
				<Field<ValueType<Option, true>>
					name="members"
					label="Team members"
					defaultValue={[]}
					isRequired
					validate={(value) => {
						if (!value || value.length === 0) {
							return errorMessages.selectError;
						}
					}}
				>
					{({ fieldProps: { id, ...rest }, error }) => {
						return (
							<Fragment>
								<Select<Option, true>
									placeholder=""
									inputId={id}
									{...rest}
									options={members}
									isMulti
									isClearable
									clearControlLabel="Clear color"
									descriptionId={error ? `${id}-error` : undefined}
								/>
								<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
							</Fragment>
						);
					}}
				</Field>
				<FormFooter align="start">
					<Button type="submit" appearance="primary">
						Create
					</Button>
				</FormFooter>
			</Form>
		</Flex>
	);
}

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal The content of the message (required)

사용 가이드

  • 필드 검증이 실패했을 때 MessageWrapper 안에서 사용해요
  • 구체적이고 실행 가능한 에러 메시지를 보여 줘요
  • 폼 컨트롤 아래에 배치해요

내용 가이드

  • 구체적인 에러 메시지를 제공해요
  • 에러를 어떻게 고칠 수 있는지 설명해요

HelperMessage 컴포넌트

폼 필드를 위한 도움말 또는 힌트 텍스트를 표시해요.

  • Keywords: form, helper, message, help, hint
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { ValidMessage } from '@atlaskit/form/valid-message';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import RadioGroup from '@atlaskit/radio/radio-group';
import TextField from '@atlaskit/textfield/text-field';
const FormDefaultExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form<{ schema: string; key: string; type: string }>
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
				return new Promise((resolve) => setTimeout(resolve, 2000)).then(() =>
					!data.schema ? { schema: 'A schema name is required' } : undefined,
				);
			}}
		>
			{({ formProps, submitting }) => (
				<form {...formProps} name="create">
					<FormHeader title="Create schema">
						<p aria-hidden="true">
							Required fields are marked with an asterisk <RequiredAsterisk />
						</p>
					</FormHeader>
					<FormSection>
						<Field
							name="schema"
							label="Schema name"
							isRequired
							defaultValue=""
							validate={(value) => (!value ? 'A schema name is required' : undefined)}
						>
							{({ fieldProps, error }) => {
								return (
									<Fragment>
										<TextField autoComplete="off" {...fieldProps} />
										<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="key"
							label="Key"
							defaultValue=""
							isRequired
							validate={(value) => {
								if (!value) {
									return 'A key is required';
								}
								if (value.length < 8) {
									return 'Key needs to be at least 8 characters.';
								}
							}}
						>
							{({ fieldProps, error, valid, meta }) => {
								return (
									<Fragment>
										<TextField type="key" {...fieldProps} />
										<MessageWrapper>
											<HelperMessage>
												Create a unique key, minimum of 8 characters. Example key: IT-infrastructure
											</HelperMessage>
											{error && <ErrorMessage>{error}</ErrorMessage>}
											{valid && meta.dirty ? <ValidMessage>Key is unique</ValidMessage> : null}
										</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="type"
							defaultValue=""
							label="Schema type"
							component={({ fieldProps }) => (
								<RadioGroup
									options={[
										{
											name: 'type',
											value: 'project-admin',
											label: 'Public',
										},
										{
											name: 'type',
											value: 'admin',
											label: 'Private',
										},
									]}
									{...fieldProps}
								/>
							)}
						/>
					</FormSection>
					<FormFooter align="start">
						<ButtonGroup label="Form submit options">
							<Button type="submit" appearance="primary">
								Create
							</Button>
							<Button appearance="subtle" isLoading={submitting}>
								Cancel
							</Button>
						</ButtonGroup>
					</FormFooter>
				</form>
			)}
		</Form>
	</Flex>
);
export default FormDefaultExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal The content of the message (required)

사용 가이드

  • 안내나 힌트를 보여 줄 때 MessageWrapper 안에서 사용해요
  • 폼 컨트롤 아래에 배치해요
  • 중요한 정보 전달에 사용해요—placeholder만으로는 부족해요

내용 가이드

  • 명확하고 실행 가능한 안내를 제공해요
  • 도움말 텍스트는 간결하게 유지해요

MessageWrapper 컴포넌트

폼 필드 메시지(HelperMessage, ErrorMessage, ValidMessage)를 감싸는 래퍼예요. 레이아웃과 표시 여부를 관리해요.

  • Keywords: form, message, wrapper
  • Categories: form
  • Status: general-availability

예제

import { ErrorMessage } from '@atlaskit/form/error-message';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { ValidMessage } from '@atlaskit/form/valid-message';
import Link from '@atlaskit/link/link';
import Lozenge from '@atlaskit/lozenge/lozenge';
export default function MessagesExample(): React.JSX.Element {
	return (
		<div>
			{
			<div  style={{ width: 'max-content' }}>
				<MessageWrapper>
					<HelperMessage testId="helper">This is a help message.</HelperMessage>
					<ErrorMessage testId="error">This is an error message.</ErrorMessage>
					<ValidMessage testId="valid">This is a success message.</ValidMessage>
				</MessageWrapper>
			</div>
			{
			<div  style={{ maxWidth: 240 }}>
				<MessageWrapper>
					<HelperMessage testId="helper--long">
						This is a help message, but it's really really really long.
					</HelperMessage>
					<ErrorMessage testId="error--long">
						This is an error message, but it's really really really long.
					</ErrorMessage>
					<ValidMessage testId="valid--long">
						This is a validation message, but it's really really really long.
					</ValidMessage>
				</MessageWrapper>
			</div>
			{
			<div  style={{ maxWidth: 240 }}>
				<MessageWrapper>
					<HelperMessage testId="helper--long">
						This message contains <strong>strong</strong> text.
					</HelperMessage>
					<ErrorMessage testId="error--long">
						This message contains a link to{' '}
						<Link href="http://www.atlassian.com">the Atlassian website</Link>.
					</ErrorMessage>
					<ValidMessage testId="valid--long">
						This message contains a <Lozenge appearance="success">success</Lozenge> lozenge.
					</ValidMessage>
				</MessageWrapper>
			</div>
		</div>
	);
}

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal The content of the message (required)

사용 가이드

  • HelperMessage, ErrorMessage, ValidMessage를 MessageWrapper로 감싸요
  • Field 안에서 폼 컨트롤 아래에 배치해요

ValidMessage 컴포넌트

폼 필드의 성공 또는 유효 상태 피드백을 표시해요.

  • Keywords: form, valid, message, success
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { ValidMessage } from '@atlaskit/form/valid-message';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import RadioGroup from '@atlaskit/radio/radio-group';
import TextField from '@atlaskit/textfield/text-field';
const FormDefaultExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form<{ schema: string; key: string; type: string }>
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
				return new Promise((resolve) => setTimeout(resolve, 2000)).then(() =>
					!data.schema ? { schema: 'A schema name is required' } : undefined,
				);
			}}
		>
			{({ formProps, submitting }) => (
				<form {...formProps} name="create">
					<FormHeader title="Create schema">
						<p aria-hidden="true">
							Required fields are marked with an asterisk <RequiredAsterisk />
						</p>
					</FormHeader>
					<FormSection>
						<Field
							name="schema"
							label="Schema name"
							isRequired
							defaultValue=""
							validate={(value) => (!value ? 'A schema name is required' : undefined)}
						>
							{({ fieldProps, error }) => {
								return (
									<Fragment>
										<TextField autoComplete="off" {...fieldProps} />
										<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="key"
							label="Key"
							defaultValue=""
							isRequired
							validate={(value) => {
								if (!value) {
									return 'A key is required';
								}
								if (value.length < 8) {
									return 'Key needs to be at least 8 characters.';
								}
							}}
						>
							{({ fieldProps, error, valid, meta }) => {
								return (
									<Fragment>
										<TextField type="key" {...fieldProps} />
										<MessageWrapper>
											<HelperMessage>
												Create a unique key, minimum of 8 characters. Example key: IT-infrastructure
											</HelperMessage>
											{error && <ErrorMessage>{error}</ErrorMessage>}
											{valid && meta.dirty ? <ValidMessage>Key is unique</ValidMessage> : null}
										</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="type"
							defaultValue=""
							label="Schema type"
							component={({ fieldProps }) => (
								<RadioGroup
									options={[
										{
											name: 'type',
											value: 'project-admin',
											label: 'Public',
										},
										{
											name: 'type',
											value: 'admin',
											label: 'Private',
										},
									]}
									{...fieldProps}
								/>
							)}
						/>
					</FormSection>
					<FormFooter align="start">
						<ButtonGroup label="Form submit options">
							<Button type="submit" appearance="primary">
								Create
							</Button>
							<Button appearance="subtle" isLoading={submitting}>
								Cancel
							</Button>
						</ButtonGroup>
					</FormFooter>
				</form>
			)}
		</Form>
	</Flex>
);
export default FormDefaultExample;

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal The content of the message (required)

사용 가이드

  • 필드가 검증을 통과했을 때 MessageWrapper 안에서 사용해요
  • 긍정적 피드백을 보여 줘요(예: "Username is available")
  • 어수선함을 막기 위해 아껴서 사용해요

내용 가이드

  • 유효 메시지는 간결하게 유지해요

RangeField 컴포넌트

범위(range)/슬라이더 입력을 위한 폼 필드예요. Range에 폼 필드 동작을 감싼 것이에요.

  • Keywords: form, range, field, slider
  • Categories: form
  • Status: general-availability

예제

import Button from '@atlaskit/button/default/button';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { RangeField } from '@atlaskit/form/range-field';
import { Box } from '@atlaskit/primitives/compiled/box';
import Range from '@atlaskit/range/range';
const FormRangeFieldExample = (): React.JSX.Element => {
	return (
		<Box>
			<Form onSubmit={(data) => console.log(data)}>
				<RangeField name="threshold" defaultValue={50} label="Threshold">
					{({ fieldProps }) => <Range {...fieldProps} min={0} max={70} />}
				</RangeField>
				<FormFooter align="start">
					<Button type="submit" appearance="primary">
						Submit
					</Button>
				</FormFooter>
			</Form>
		</Box>
	);
};
export default FormRangeFieldExample;

Props

Prop Type Description
children (args: { fieldProps: RangeProps; error?: string; meta: Meta; }) => React.ReactNode Content to render in the range field (required)
defaultValue number | ((currentDefaultValue?: number) => number) Sets the default value of the field (required)
id string Value passed to the id attribute of the field
isDisabled boolean Sets whether the field is disabled
label string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Displays a label above the range field and identifies the form fields
name string Specifies the name of the field (required)

사용 가이드

  • 숫자 범위 선택에 사용해요
  • 필요할 때 min, max, step을 제공해요
  • @atlaskit/range의 Range와 함께 동작해요

RequiredAsterisk 컴포넌트

필수 필드를 위한 시각적 표시예요. 폼 접근성을 위해 별표(*)를 렌더링해요.

  • Keywords: form, required, asterisk
  • Categories: form
  • Status: general-availability

예제

import React, { Fragment } from 'react';
import ButtonGroup from '@atlaskit/button/button-group';
import Button from '@atlaskit/button/default/button';
import { ErrorMessage } from '@atlaskit/form/error-message';
import Field from '@atlaskit/form/field';
import Form from '@atlaskit/form/form';
import { FormFooter } from '@atlaskit/form/form-footer';
import { FormHeader } from '@atlaskit/form/form-header';
import { FormSection } from '@atlaskit/form/form-section';
import { HelperMessage } from '@atlaskit/form/helper-message';
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
import { RequiredAsterisk } from '@atlaskit/form/required-asterisk';
import { ValidMessage } from '@atlaskit/form/valid-message';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import RadioGroup from '@atlaskit/radio/radio-group';
import TextField from '@atlaskit/textfield/text-field';
const FormDefaultExample = (): React.JSX.Element => (
	<Flex direction="column">
		<Form<{ schema: string; key: string; type: string }>
			noValidate
			onSubmit={(data) => {
				console.log('form data', data);
				return new Promise((resolve) => setTimeout(resolve, 2000)).then(() =>
					!data.schema ? { schema: 'A schema name is required' } : undefined,
				);
			}}
		>
			{({ formProps, submitting }) => (
				<form {...formProps} name="create">
					<FormHeader title="Create schema">
						<p aria-hidden="true">
							Required fields are marked with an asterisk <RequiredAsterisk />
						</p>
					</FormHeader>
					<FormSection>
						<Field
							name="schema"
							label="Schema name"
							isRequired
							defaultValue=""
							validate={(value) => (!value ? 'A schema name is required' : undefined)}
						>
							{({ fieldProps, error }) => {
								return (
									<Fragment>
										<TextField autoComplete="off" {...fieldProps} />
										<MessageWrapper>{error && <ErrorMessage>{error}</ErrorMessage>}</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="key"
							label="Key"
							defaultValue=""
							isRequired
							validate={(value) => {
								if (!value) {
									return 'A key is required';
								}
								if (value.length < 8) {
									return 'Key needs to be at least 8 characters.';
								}
							}}
						>
							{({ fieldProps, error, valid, meta }) => {
								return (
									<Fragment>
										<TextField type="key" {...fieldProps} />
										<MessageWrapper>
											<HelperMessage>
												Create a unique key, minimum of 8 characters. Example key: IT-infrastructure
											</HelperMessage>
											{error && <ErrorMessage>{error}</ErrorMessage>}
											{valid && meta.dirty ? <ValidMessage>Key is unique</ValidMessage> : null}
										</MessageWrapper>
									</Fragment>
								);
							}}
						</Field>
						<Field
							name="type"
							defaultValue=""
							label="Schema type"
							component={({ fieldProps }) => (
								<RadioGroup
									options={[
										{
											name: 'type',
											value: 'project-admin',
											label: 'Public',
										},
										{
											name: 'type',
											value: 'admin',
											label: 'Private',
										},
									]}
									{...fieldProps}
								/>
							)}
						/>
					</FormSection>
					<FormFooter align="start">
						<ButtonGroup label="Form submit options">
							<Button type="submit" appearance="primary">
								Create
							</Button>
							<Button appearance="subtle" isLoading={submitting}>
								Cancel
							</Button>
						</ButtonGroup>
					</FormFooter>
				</form>
			)}
		</Form>
	</Flex>
);
export default FormDefaultExample;

사용 가이드

  • 필수 필드 legend를 표시하려면 FormHeader에서 사용해요
  • 또는 별표를 자동으로 처리하는 Field의 isRequired를 사용해요

내용 가이드

  • "Required fields are marked with an asterisk" 텍스트와 함께 써요

더 알아보기 (Learn more)