Field Button
A button in the form of an input field, used to open selection windows or pickers. When selection is complete, the selected value is displayed in the button label.
import { FieldButton } from "seed-design/ui/field-button";
export default function FieldButtonPreview() {
return (
<FieldButton
label="레이블"
description="버튼에 대한 설명을 작성해주세요"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "알림 표시",
}}
/>
);
}Installation
npx @seed-design/cli@latest add ui:field-buttonpnpm dlx @seed-design/cli@latest add ui:field-buttonyarn dlx @seed-design/cli@latest add ui:field-buttonbun x @seed-design/cli@latest add ui:field-buttonInstall dependencies
npm install @karrotmarket/react-monochrome-icon @seed-design/css @seed-design/reactyarn add @karrotmarket/react-monochrome-icon @seed-design/css @seed-design/reactpnpm add @karrotmarket/react-monochrome-icon @seed-design/css @seed-design/reactbun add @karrotmarket/react-monochrome-icon @seed-design/css @seed-design/reactCopy the code below and paste it in
/**
* @file ui:field-button
* @requires @seed-design/react@^2.0.0
* @requires @seed-design/css@^2.0.0
**/
"use client";
import * as React from "react";
import {
FieldButton as SeedFieldButton,
VisuallyHidden,
Icon,
PrefixIcon,
} from "@seed-design/react";
import type { FieldLabelVariantProps } from "@seed-design/css/recipes/field-label";
import {
IconExclamationmarkCircleFill,
IconXmarkCircleFill,
} from "@karrotmarket/react-monochrome-icon";
export interface FieldButtonProps extends Omit<SeedFieldButton.RootProps, "prefix"> {
label?: React.ReactNode;
/**
* @default "medium"
*/
labelWeight?: FieldLabelVariantProps["weight"];
indicator?: React.ReactNode;
prefixIcon?: React.ReactNode;
prefix?: React.ReactNode;
suffixIcon?: React.ReactNode;
suffix?: React.ReactNode;
description?: React.ReactNode;
errorMessage?: React.ReactNode;
showRequiredIndicator?: boolean;
showClearButton?: boolean;
buttonProps?: SeedFieldButton.ButtonProps;
rootRef?: React.Ref<HTMLDivElement>;
}
/**
* @see https://crispy.carrot-soft.tech/react/components/field-button
*/
export const FieldButton = React.forwardRef<HTMLButtonElement, FieldButtonProps>(
(
{
label,
labelWeight,
indicator,
prefix,
prefixIcon,
suffix,
suffixIcon,
description,
errorMessage,
showRequiredIndicator,
showClearButton,
buttonProps,
rootRef,
children,
...otherProps
},
ref,
) => {
const renderHeader = label || indicator;
const renderDescription = !!description;
const renderErrorMessage = errorMessage && otherProps.invalid;
const renderFooter = renderDescription || renderErrorMessage;
if (
!buttonProps?.["aria-labelledby"] &&
!buttonProps?.["aria-label"] &&
process.env.NODE_ENV !== "production"
) {
console.warn("FieldButton: aria-labelledby or aria-label should be provided to buttonProps.");
}
if (!otherProps.onValuesChange && showClearButton) {
console.warn(
"FieldButton: FieldButton without onValuesChange works as a display component, but it needs onValuesChange to work correctly with a clear button.",
);
}
return (
<SeedFieldButton.Root ref={rootRef} {...otherProps}>
{renderHeader && (
<SeedFieldButton.Header>
<SeedFieldButton.Label weight={labelWeight}>
{label}
{showRequiredIndicator && <SeedFieldButton.RequiredIndicator />}
{indicator && (
<SeedFieldButton.IndicatorText>{indicator}</SeedFieldButton.IndicatorText>
)}
</SeedFieldButton.Label>
</SeedFieldButton.Header>
)}
<SeedFieldButton.Control>
<SeedFieldButton.Button ref={ref} {...buttonProps} />
{prefixIcon && <SeedFieldButton.PrefixIcon svg={prefixIcon} />}
{prefix && <SeedFieldButton.PrefixText>{prefix}</SeedFieldButton.PrefixText>}
{children}
{showClearButton && (
// You may implement your own i18n for clear button label
<SeedFieldButton.ClearButton aria-label="지우기">
<Icon svg={<IconXmarkCircleFill />} />
</SeedFieldButton.ClearButton>
)}
{suffix && <SeedFieldButton.SuffixText>{suffix}</SeedFieldButton.SuffixText>}
{suffixIcon && <SeedFieldButton.SuffixIcon svg={suffixIcon} />}
</SeedFieldButton.Control>
{renderFooter && (
<SeedFieldButton.Footer>
{renderDescription &&
(renderErrorMessage ? (
<VisuallyHidden asChild>
<SeedFieldButton.Description>{description}</SeedFieldButton.Description>
</VisuallyHidden>
) : (
<SeedFieldButton.Description>{description}</SeedFieldButton.Description>
))}
{renderErrorMessage && (
<SeedFieldButton.ErrorMessage>
<PrefixIcon svg={<IconExclamationmarkCircleFill />} />
{errorMessage}
</SeedFieldButton.ErrorMessage>
)}
</SeedFieldButton.Footer>
)}
{otherProps.values?.map((_, index) => (
<SeedFieldButton.HiddenInput key={index} valueIndex={index} />
))}
</SeedFieldButton.Root>
);
},
);
FieldButton.displayName = "FieldButton";
export interface FieldButtonValueProps extends SeedFieldButton.ValueProps {}
/**
* @see https://crispy.carrot-soft.tech/react/components/field-button
*/
export const FieldButtonValue = SeedFieldButton.Value;
export interface FieldButtonPlaceholderProps extends SeedFieldButton.PlaceholderProps {}
/**
* @see https://crispy.carrot-soft.tech/react/components/field-button
*/
export const FieldButtonPlaceholder = SeedFieldButton.Placeholder;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
Props
FieldButton
Prop
Type
label?React.ReactNodeindicator?React.ReactNodeprefixIcon?React.ReactNodeprefix?React.ReactNodesuffixIcon?React.ReactNodesuffix?React.ReactNodedescription?React.ReactNodeerrorMessage?React.ReactNodeshowRequiredIndicator?boolean | undefinedshowClearButton?boolean | undefinedbuttonProps?SeedFieldButton.ButtonProps | undefinedrootRef?React.Ref<HTMLDivElement> | undefinedname?string | undefinedvalues?string[] | undefinedonValuesChange?((values: string[]) => void) | undefinedFieldButtonValue
Prop
Type
FieldButtonPlaceholder
Prop
Type
Examples
Basic Usage
FieldButton has a similar appearance to TextField, but is fundamentally a component that includes a <button> element internally. Users can control button properties through the buttonProps prop.
buttonPropsonClick: Button click handleraria-label: Accessibility label for the button
children- Composed using
FieldButtonValueorFieldButtonPlaceholder, etc. FieldButtonValueandFieldButtonPlaceholderare functionally identical except for styling differences. Screen readers do not read or distinguish between the two elements. For accessibility, provide an appropriate value tobuttonProps["aria-label"]. See the Accessibility section for details.
- Composed using
import { FieldButton, FieldButtonPlaceholder, FieldButtonValue } from "seed-design/ui/field-button";
import { useState } from "react";
export default function FieldButtonBasicUsage() {
const [selectedCity, setSelectedCity] = useState<string>("");
return (
<FieldButton
label="도시"
showClearButton={!!selectedCity}
values={[selectedCity]}
onValuesChange={([value]) => setSelectedCity(value)}
buttonProps={{
onClick: () => {
// Open your picker dialog/sheet here
setSelectedCity("서울");
},
"aria-label": selectedCity ? `도시 변경. 현재: ${selectedCity}` : "도시 선택",
}}
>
{selectedCity ? (
<FieldButtonValue>{selectedCity}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>도시를 선택해주세요</FieldButtonPlaceholder>
)}
</FieldButton>
);
}Clear Button
When the showClearButton prop is set to true, a Clear Button is displayed. When showClearButton is set to true, the onValuesChange prop must be provided.
If FieldButton is in a disabled or readOnly state, the Clear Button is not displayed.
import { FieldButton, FieldButtonValue, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { useState } from "react";
export default function FieldButtonFormControl() {
const [value, setValue] = useState(
"Do nostrud duis deserunt occaecat sit ex veniam fugiat commodo voluptate voluptate.",
);
return (
<FieldButton
values={[value]}
onValuesChange={([value]) => setValue(value ?? "")}
showClearButton={value !== ""}
buttonProps={{
onClick: () => setValue(window.prompt("값을 입력해주세요") || value),
"aria-label": `값 입력.${value ? ` 현재 값은 ${value}입니다.` : ""}`,
}}
>
{value ? (
<FieldButtonValue>입력한 값: {value}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>값을 입력하려면 클릭하세요</FieldButtonPlaceholder>
)}
</FieldButton>
);
}FieldButtonValue & FieldButtonPlaceholder
Simple <div> elements that can be used as children inside <FieldButton>.
Screen readers do not read FieldButtonValue and FieldButtonPlaceholder. Ensure accessibility by providing an appropriate value to buttonProps["aria-label"]. See the Accessibility section for details.
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonValue, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { useCallback, useState } from "react";
export default function FieldButtonValuePlaceholder() {
const [value, setValue] = useState<string>("");
const toggleValue = useCallback(() => {
setValue((prev) => (prev ? "" : "값 설정됨"));
}, []);
return (
<HStack width="full" gap="x3">
<FieldButton
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "알림 표시",
}}
>
<FieldButtonValue>FieldButtonValue</FieldButtonValue>
</FieldButton>
<FieldButton
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "알림 표시",
}}
>
<FieldButtonPlaceholder>FieldButtonPlaceholder</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
buttonProps={{
onClick: toggleValue,
"aria-label": "값 설정",
}}
>
{value ? (
<FieldButtonValue>{value}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>클릭하여 값 설정</FieldButtonPlaceholder>
)}
</FieldButton>
</HStack>
);
}Accessibility
Provide an aria-label attribute to the button inside Field Button. Users of screen readers should be able to predict what will happen when the Field Button is clicked, and if there is a currently selected value, you must let them know what that value is.
<FieldButton
label="Username" // Screen readers read the label.
description="You do not need to use your real name." // Screen readers read the description along with the button.
buttonProps={{
// Tell users what will happen when the button is clicked and what the currently selected value is.
"aria-label": `Open username selection screen. Currently selected name: ${username || "None"}`,
"aria-haspopup": "dialog",
onClick: () => setIsUsernamePickerOpen(true),
}}
>
{username ? (
<FieldButtonValue>{username}</FieldButtonValue> // Screen readers do not read FieldButtonValue.
) : (
<FieldButtonPlaceholder>Kim Ha-neul</FieldButtonPlaceholder> // Screen readers do not read FieldButtonPlaceholder.
)}
</FieldButton>Sighted users can easily predict that Field Button is a clickable element and what action will occur when clicked. However, screen reader users find it difficult to understand what will happen when Field Button is clicked if the button does not have an aria-label attribute.
Use Cases
Form
When providing the values prop to FieldButton, it also renders <input type="hidden" /> so it can be used for form submission.
import { VStack, HStack } from "@seed-design/react";
import { FieldButton, FieldButtonValue } from "seed-design/ui/field-button";
import { ActionButton } from "seed-design/ui/action-button";
import { TextField, TextFieldInput } from "seed-design/ui/text-field";
import { useState, type FormEvent } from "react";
export default function FieldButtonForm() {
const [count, setCount] = useState(0);
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
window.alert(JSON.stringify(Object.fromEntries(formData.entries()), null, 2));
};
return (
<VStack asChild width="full" gap="spacingY.componentDefault">
<form onSubmit={handleSubmit}>
<HStack gap="x3">
<TextField
label="TextField"
description="이것은 TextField입니다. FieldButton과 어떻게 다른지 비교해보세요."
name="text-field-text"
>
<TextFieldInput placeholder="TextFieldInput" />
</TextField>
<FieldButton
label="input을 포함한 FieldButton"
description={`이 FieldButton은 <input type="hidden" /> 요소를 한 개 포함하고 있습니다. 자세한 내용은 예시 코드를 참고하세요.`}
name="field-button-count"
values={[`${count}`]}
buttonProps={{
onClick: () => setCount((prev) => prev + 1),
"aria-label": "카운트 증가",
}}
>
<FieldButtonValue>현재 카운트: {count}</FieldButtonValue>
</FieldButton>
</HStack>
<ActionButton type="submit" variant="neutralSolid">
제출
</ActionButton>
</form>
</VStack>
);
}Form and Bottom Sheet
import { useState } from "react";
import { HStack, VStack } from "@seed-design/react";
import { FieldButton, FieldButtonValue, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { ActionButton } from "seed-design/ui/action-button";
import {
BottomSheetRoot,
BottomSheetContent,
BottomSheetBody,
BottomSheetFooter,
} from "seed-design/ui/bottom-sheet";
import { TextField, TextFieldInput } from "seed-design/ui/text-field";
import { Portal } from "@seed-design/react";
interface ProductFormData {
category: string;
name: string;
}
export default function FieldButtonFormBottomSheet() {
const [formData, setFormData] = useState<ProductFormData>({
category: "",
name: "",
});
const [isCategorySheetOpen, setIsCategorySheetOpen] = useState(false);
const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
window.alert(JSON.stringify(formData));
};
const updateFormData = (field: keyof ProductFormData) => (value: string) => {
setFormData((prev) => ({ ...prev, [field]: value }));
};
const handleNameClick = () => {
const inputName = window.prompt("상품명을 입력해주세요");
if (inputName === null) return;
updateFormData("name")(inputName);
};
return (
<VStack gap="spacingY.componentDefault" width="full" as="form" onSubmit={handleSubmit}>
<HStack gap="x2">
<BottomSheetRoot open={isCategorySheetOpen} onOpenChange={setIsCategorySheetOpen}>
<FieldButton
label="카테고리"
values={[formData.category]}
onValuesChange={([value]) => updateFormData("category")(value ?? "")}
showClearButton={formData.category !== ""}
buttonProps={{
onClick: () => setIsCategorySheetOpen(true),
"aria-label": "카테고리 선택",
"aria-haspopup": "dialog",
}}
>
{formData.category ? (
<FieldButtonValue>{formData.category}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>카테고리를 선택해주세요</FieldButtonPlaceholder>
)}
</FieldButton>
<Portal>
<CategoryInputSheet
value={formData.category}
onSubmit={(value) => {
updateFormData("category")(value);
setIsCategorySheetOpen(false);
}}
/>
</Portal>
</BottomSheetRoot>
<FieldButton
label="상품명"
showClearButton={formData.name !== ""}
values={[formData.name]}
onValuesChange={([value]) => updateFormData("name")(value)}
buttonProps={{
onClick: handleNameClick,
"aria-label": "상품명 입력",
}}
>
{formData.name ? (
<FieldButtonValue>{formData.name}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>상품명을 입력해주세요</FieldButtonPlaceholder>
)}
</FieldButton>
</HStack>
<ActionButton type="submit" variant="neutralSolid">
제출
</ActionButton>
</VStack>
);
}
interface CategoryInputSheetProps {
value: string;
onSubmit: (value: string) => void;
}
function CategoryInputSheet({ value, onSubmit }: CategoryInputSheetProps) {
const [draft, setDraft] = useState(value);
const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
onSubmit(draft);
event.stopPropagation();
};
return (
<BottomSheetContent title="카테고리 선택">
<form onSubmit={handleSubmit}>
<BottomSheetBody minHeight="x16">
<TextField
label="카테고리를 입력해 주세요"
value={draft}
onValueChange={({ value }) => setDraft(value)}
>
<TextFieldInput type="text" placeholder="예: 전자기기" />
</TextField>
</BottomSheetBody>
<BottomSheetFooter>
<ActionButton type="submit" variant="neutralSolid">
확인
</ActionButton>
</BottomSheetFooter>
</form>
</BottomSheetContent>
);
}React Hook Form
import { VStack, HStack } from "@seed-design/react";
import { FieldButton, FieldButtonValue } from "seed-design/ui/field-button";
import { ActionButton } from "seed-design/ui/action-button";
import { TextField, TextFieldInput } from "seed-design/ui/text-field";
import { useCallback, type FormEvent } from "react";
import { useController, useForm } from "react-hook-form";
interface FormValues {
text: string;
count: number;
}
export default function FieldButtonReactHookFormSimple() {
const { handleSubmit, reset, control } = useForm<FormValues>({
defaultValues: {
text: "",
count: 0,
},
});
const {
field: { onChange: textOnChange, ...textField },
fieldState: textFieldState,
} = useController({
name: "text",
control,
rules: {
required: "필수 입력 항목입니다",
},
});
const {
field: { value: countValue, onChange: countOnChange, ...countField },
fieldState: countFieldState,
} = useController({
name: "count",
control,
rules: {
validate: (value) => value >= 3 || "최소 3회 이상 클릭해야 합니다",
},
});
const onValid = useCallback((data: FormValues) => {
window.alert(JSON.stringify(data, null, 2));
}, []);
const onReset = useCallback(
(event: FormEvent) => {
event.preventDefault();
reset();
},
[reset],
);
return (
<VStack asChild width="full" gap="spacingY.componentDefault">
<form onSubmit={handleSubmit(onValid)} onReset={onReset}>
<HStack gap="x3">
<TextField
label="TextField"
description="이것은 TextField입니다. FieldButton과 어떻게 다른지 비교해보세요."
invalid={textFieldState.invalid}
errorMessage={textFieldState.error?.message}
onValueChange={({ value }) => textOnChange(value)}
showRequiredIndicator
{...textField}
>
<TextFieldInput placeholder="TextFieldInput" />
</TextField>
<FieldButton
label="input을 포함한 FieldButton"
description={`이 FieldButton은 <input type="hidden" /> 요소를 한 개 포함하고 있습니다. 자세한 내용은 예시 코드를 참고하세요.`}
invalid={countFieldState.invalid}
errorMessage={countFieldState.error?.message}
values={[`${countValue}`]}
onValuesChange={([value]) => countOnChange(Number(value))}
buttonProps={{
onClick: () => countOnChange(countValue + 1),
"aria-label": "카운트 증가",
}}
showRequiredIndicator
{...countField}
>
<FieldButtonValue>현재 카운트: {countValue}</FieldButtonValue>
</FieldButton>
</HStack>
<HStack gap="x2">
<ActionButton type="reset" variant="neutralWeak">
초기화
</ActionButton>
<ActionButton type="submit" variant="neutralSolid" flexGrow={1}>
제출
</ActionButton>
</HStack>
</form>
</VStack>
);
}Multiple Values (React Hook Form (Field Array))
import React, { useState, useCallback } from "react";
import { Box, HStack, VStack } from "@seed-design/react";
import { useFieldArray, useForm } from "react-hook-form";
import { FieldButton, FieldButtonValue, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { ActionButton } from "seed-design/ui/action-button";
import {
BottomSheetRoot,
BottomSheetContent,
BottomSheetBody,
BottomSheetFooter,
} from "seed-design/ui/bottom-sheet";
import { TextField, TextFieldInput } from "seed-design/ui/text-field";
import { Portal } from "@seed-design/react";
interface ProductFormData {
tags: { value: string }[];
}
export default function FieldButtonFieldArray() {
const { control, handleSubmit, reset, setValue } = useForm<ProductFormData>({
defaultValues: { tags: [] },
});
const [isTagSheetOpen, setIsTagSheetOpen] = useState(false);
const { fields, append } = useFieldArray({ control, name: "tags" });
const onValid = useCallback((data: ProductFormData) => {
window.alert(JSON.stringify(data, null, 2));
}, []);
const onReset = useCallback(
(event: React.FormEvent) => {
event.preventDefault();
reset();
},
[reset],
);
const handleAddTag = (tag: string) => {
if (tag && !fields.some((field) => field.value === tag)) {
append({ value: tag });
}
setIsTagSheetOpen(false);
};
return (
<VStack
gap="spacingY.componentDefault"
width="full"
as="form"
onSubmit={handleSubmit(onValid)}
onReset={onReset}
>
<BottomSheetRoot open={isTagSheetOpen} onOpenChange={setIsTagSheetOpen}>
<FieldButton
label="태그"
values={fields.map((field) => field.value)}
onValuesChange={(values) =>
setValue(
"tags",
values.map((value) => ({ value })),
)
}
showClearButton={fields.length > 0}
buttonProps={{
onClick: () => setIsTagSheetOpen(true),
"aria-label": fields.length > 0 ? `태그 ${fields.length}개 편집` : "태그 선택",
"aria-haspopup": "dialog",
}}
>
{fields.length > 0 ? (
<FieldButtonValue>{fields.map((field) => field.value).join(", ")}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>태그를 추가해주세요</FieldButtonPlaceholder>
)}
</FieldButton>
<Portal>
<TagInputSheet onSubmit={handleAddTag} existingTags={fields.map((f) => f.value)} />
</Portal>
</BottomSheetRoot>
<HStack gap="x2">
<ActionButton type="reset" variant="neutralWeak">
초기화
</ActionButton>
<ActionButton type="submit" variant="neutralSolid" flexGrow={1}>
제출
</ActionButton>
</HStack>
</VStack>
);
}
interface TagInputSheetProps {
onSubmit: (tag: string) => void;
existingTags: string[];
}
function TagInputSheet({ onSubmit, existingTags }: TagInputSheetProps) {
const [addDraft, setAddDraft] = useState("");
const handleAddSubmit = (event: React.FormEvent) => {
event.preventDefault();
if (!addDraft) return;
if (existingTags.includes(addDraft)) {
window.alert("이미 추가된 태그입니다");
event.stopPropagation();
return;
}
setAddDraft("");
onSubmit(addDraft);
event.stopPropagation();
};
return (
<BottomSheetContent title="태그 입력">
<Box onSubmit={handleAddSubmit} as="form" width="full">
<BottomSheetBody minHeight="x16">
<TextField
label="태그를 입력해주세요"
value={addDraft}
onValueChange={({ value }) => setAddDraft(value)}
>
<TextFieldInput type="text" placeholder="예: 전자기기, 신상품" />
</TextField>
</BottomSheetBody>
<BottomSheetFooter>
<ActionButton type="submit" variant="neutralSolid" disabled={!addDraft}>
추가
</ActionButton>
</BottomSheetFooter>
</Box>
</BottomSheetContent>
);
}Multiple Values (Native form)
import React, { useState, useCallback } from "react";
import { Box, HStack, VStack } from "@seed-design/react";
import { FieldButton, FieldButtonValue, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { ActionButton } from "seed-design/ui/action-button";
import {
BottomSheetRoot,
BottomSheetContent,
BottomSheetBody,
BottomSheetFooter,
} from "seed-design/ui/bottom-sheet";
import { TextField, TextFieldInput } from "seed-design/ui/text-field";
import { Portal } from "@seed-design/react";
export default function FieldButtonMultipleValues() {
const [tags, setTags] = useState<string[]>([]);
const [isTagSheetOpen, setIsTagSheetOpen] = useState(false);
const handleSubmit = useCallback((event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const formValues = { tags: formData.getAll("tags") };
window.alert(JSON.stringify(formValues, null, 2));
}, []);
const handleReset = useCallback((event: React.FormEvent) => {
event.preventDefault();
setTags([]);
}, []);
const handleAddTag = (tag: string) => {
if (tag && !tags.includes(tag)) {
setTags((prev) => [...prev, tag]);
}
setIsTagSheetOpen(false);
};
return (
<VStack gap="spacingY.componentDefault" width="full" asChild>
<form onSubmit={handleSubmit} onReset={handleReset}>
<BottomSheetRoot open={isTagSheetOpen} onOpenChange={setIsTagSheetOpen}>
<FieldButton
label="태그"
description="여러 태그를 추가할 수 있습니다"
name="tags"
values={tags}
onValuesChange={setTags}
showClearButton={tags.length > 0}
buttonProps={{
onClick: () => setIsTagSheetOpen(true),
"aria-label": tags.length > 0 ? `태그 ${tags.length}개 편집` : "태그 선택",
"aria-haspopup": "dialog",
}}
>
{tags.length > 0 ? (
<FieldButtonValue>{tags.join(", ")}</FieldButtonValue>
) : (
<FieldButtonPlaceholder>태그를 추가해주세요</FieldButtonPlaceholder>
)}
</FieldButton>
<Portal>
<TagInputSheet onSubmit={handleAddTag} existingTags={tags} />
</Portal>
</BottomSheetRoot>
<HStack gap="x2">
<ActionButton type="reset" variant="neutralWeak">
초기화
</ActionButton>
<ActionButton type="submit" variant="neutralSolid" flexGrow={1}>
제출
</ActionButton>
</HStack>
</form>
</VStack>
);
}
interface TagInputSheetProps {
onSubmit: (tag: string) => void;
existingTags: string[];
}
function TagInputSheet({ onSubmit, existingTags }: TagInputSheetProps) {
const [addDraft, setAddDraft] = useState("");
const handleAddSubmit = (event: React.FormEvent) => {
event.preventDefault();
if (!addDraft) return;
if (existingTags.includes(addDraft)) {
window.alert("이미 추가된 태그입니다");
event.stopPropagation();
return;
}
onSubmit(addDraft);
setAddDraft("");
event.stopPropagation();
};
return (
<BottomSheetContent title="태그 입력">
<Box onSubmit={handleAddSubmit} as="form" width="full">
<BottomSheetBody minHeight="x16">
<TextField
label="태그를 입력해주세요"
value={addDraft}
onValueChange={({ value }) => setAddDraft(value)}
>
<TextFieldInput type="text" placeholder="예: 전자기기, 신상품" />
</TextField>
</BottomSheetBody>
<BottomSheetFooter>
<ActionButton type="submit" variant="neutralSolid" disabled={!addDraft}>
추가
</ActionButton>
</BottomSheetFooter>
</Box>
</BottomSheetContent>
);
}State
Enabled
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
export default function FieldButtonEnabled() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="설명을 써주세요"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "알림 표시",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="설명을 써주세요"
invalid
errorMessage="오류가 발생한 이유를 써주세요"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "알림 표시",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Disabled
- The
<input type="hidden" />rendered when providingvaluesis alsodisabled, so its value is not sent on form submission. - The
<button>element is alsodisabledand cannot be clicked.
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
export default function FieldButtonDisabled() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="설명을 써주세요"
disabled
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "값 선택",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="설명을 써주세요"
disabled
invalid
errorMessage="오류가 발생한 이유를 써주세요"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "값 선택",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Read Only
- The
<input type="hidden" />rendered when providingvaluesis not affected. - The
<button>element isdisabledand cannot be clicked.
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
export default function FieldButtonReadOnly() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="설명을 써주세요"
readOnly
buttonProps={{
"aria-label": "값 선택",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="설명을 써주세요"
readOnly
invalid
errorMessage="오류가 발생한 이유를 써주세요"
buttonProps={{
"aria-label": "값 선택",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Size
The size of FieldButton is set by size. (default: large)
responsive is a value where size automatically switches based on screen width. In products that support multiple screen widths, use size=responsive to adapt.
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
export default function FieldButtonSize() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="size=large (default)"
size="large"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "선택 화면 열기",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="size=medium"
size="medium"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "선택 화면 열기",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="size=responsive"
size="responsive"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "선택 화면 열기",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Customizable Parts
Prefix
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { IconMagnifyingglassLine } from "@karrotmarket/react-monochrome-icon";
export default function FieldButtonPrefix() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="설명을 써주세요"
prefix="https://"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "URL 입력",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="설명을 써주세요"
prefixIcon={<IconMagnifyingglassLine />}
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "검색",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Suffix
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { IconWonLine } from "@karrotmarket/react-monochrome-icon";
export default function FieldButtonSuffix() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="설명을 써주세요"
suffix="cm"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "키 입력",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="설명을 써주세요"
suffixIcon={<IconWonLine />}
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "금액 입력",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Both Affixes
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
import { IconPlusCircleLine, IconWonLine } from "@karrotmarket/react-monochrome-icon";
export default function FieldButtonBothAffixes() {
return (
<HStack width="full" gap="x3">
<FieldButton
label="라벨"
description="설명을 써주세요"
prefix="만"
suffix="세"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "나이 선택",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="라벨"
description="설명을 써주세요"
prefixIcon={<IconPlusCircleLine />}
suffixIcon={<IconWonLine />}
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "금액 선택",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}Indicator
import { HStack } from "@seed-design/react";
import { FieldButton, FieldButtonPlaceholder } from "seed-design/ui/field-button";
export default function FieldButtonIndicator() {
return (
<HStack gap="x3" width="full">
<FieldButton
label="선택 필드"
labelWeight="bold"
indicator="선택"
description="이 필드는 선택사항입니다"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "선택 값 입력",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
<FieldButton
label="필수 필드"
showRequiredIndicator
description="이 필드는 필수사항입니다"
buttonProps={{
onClick: () => window.alert("버튼 클릭됨"),
"aria-label": "필수 값 입력",
}}
>
<FieldButtonPlaceholder>플레이스홀더</FieldButtonPlaceholder>
</FieldButton>
</HStack>
);
}