# Field Button URL: /lynx/components/input-button Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/input-button.mdx A button in the form of an input field, used to open selection dialogs or pickers. When selection is complete, the selected value is displayed in the button label. 사용 가능 버전: @seed-design/lynx-react@0.7.0, @seed-design/lynx-css@0.11.0 ## Preview ```tsx import "./styles"; import { useCallback, useState } from "@lynx-js/react"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder, FieldButtonValue, } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState(null); const selectValue = useCallback(() => { "background only"; setValue("판교동"); }, []); const clearValue = useCallback(() => { "background only"; setValue(null); }, []); return ( {value == null ? ( 동네를 선택해 주세요 ) : ( {value} )} ); } ``` ## Installation - npm: npx @seed-design/cli@latest add ui:field-button - pnpm: pnpm dlx @seed-design/cli@latest add ui:field-button - yarn: yarn dlx @seed-design/cli@latest add ui:field-button - bun: bun x @seed-design/cli@latest add ui:field-button ## Props ### `FieldButton` ### `FieldButtonValue` ### `FieldButtonPlaceholder` ## Examples ### Basic Usage `FieldButton` has an appearance similar to `TextField` but is a button that opens a selection dialog or picker without directly editing the value. - **`buttonProps`** - **`bindtap`**: Button tap handler - **`accessibility-label`**: Button's accessibility label - **`children`** - Composed of `FieldButtonValue` or `FieldButtonPlaceholder` - Both elements differ only in style and are hidden from the accessibility tree. Describe the current value and action that occurs when the button is pressed with `buttonProps["accessibility-label"]`. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder, FieldButtonValue, } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [selectedCity, setSelectedCity] = useState(""); function selectCity() { "background only"; setSelectedCity("서울"); } function clearCity() { "background only"; setSelectedCity(""); } return ( {selectedCity ? ( {selectedCity} ) : ( 도시를 선택해주세요 )} ); } ``` ### Clear Button Setting `showClearButton` to `true` displays the Clear Button. Clear the selected value managed by the consumer in `clearButtonProps.bindtap`. If `FieldButton` is in `disabled` or `readOnly` state, the Clear Button is not displayed. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder, FieldButtonValue, } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("판교동"); function selectValue() { "background only"; setValue("정자동"); } function clearValue() { "background only"; setValue(""); } return ( {value ? ( {value} ) : ( 동네를 선택해주세요 )} ); } ``` ### `FieldButtonValue` & `FieldButtonPlaceholder` `FieldButtonValue` and `FieldButtonPlaceholder` are Lynx `` elements placed as children of `FieldButton`. Both elements are hidden from the accessibility tree to prevent screen readers from reading them twice. Provide the current value and button action together with `buttonProps["accessibility-label"]`. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder, FieldButtonValue, } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState(""); function toggleValue() { "background only"; setValue((current) => (current ? "" : "값 설정됨")); } return ( FieldButtonValue FieldButtonPlaceholder {value ? ( {value} ) : ( 탭하여 값 설정 )} ); } ``` ### Accessibility **Provide `accessibility-label` to the button inside Field Button.** Describe which selection screen opens when the button is pressed, and if there is a currently selected value, include it as well. ```tsx {username ? ( {username} ) : ( Kim Haneul )} ``` ### Use Cases #### Controlled State Lynx does not support HTML Form. Manage the selected value with React state and update the value in `buttonProps.bindtap` after opening the picker. Clear Button empties the same state in `clearButtonProps.bindtap`. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder, FieldButtonValue, } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [selectedCity, setSelectedCity] = useState(""); function selectCity() { "background only"; setSelectedCity("서울"); } function clearCity() { "background only"; setSelectedCity(""); } return ( {selectedCity ? ( {selectedCity} ) : ( 도시를 선택해주세요 )} ); } ``` #### Bottom Sheet or Picker Open a Bottom Sheet or picker in `buttonProps.bindtap` and render the selection result with `FieldButtonValue`. Field Button does not determine which selection UI to open. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { ActionButton, BottomSheet, useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder, FieldButtonValue, } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [open, setOpen] = useState(false); const [value, setValue] = useState(""); function openPicker() { "background only"; setOpen(true); } function selectValue() { "background only"; setValue("판교동"); setOpen(false); } function clearValue() { "background only"; setValue(""); } return ( {value ? ( {value} ) : ( 동네를 선택해주세요 )} 동네 선택 거래할 동네를 선택해주세요. 판교동 선택 ); } ``` ### State #### Enabled ```tsx import "./styles"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); function handleTap() { "background only"; } return ( 플레이스홀더 플레이스홀더 ); } ``` #### Disabled In `disabled` state, the button tap handler is not executed and the Clear Button is not rendered. ```tsx import "./styles"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); function handleTap() { "background only"; } return ( 플레이스홀더 플레이스홀더 ); } ``` #### Read Only In `readOnly` state, the current value is displayed but the button tap handler is not executed and the Clear Button is not rendered. ```tsx import "./styles"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 플레이스홀더 플레이스홀더 ); } ``` ### Size Define the Field Button size with `size`. The default is `large`. Lynx supports `large` and `medium`. `responsive` is not supported due to the lack of CSS viewport breakpoints. ```tsx import "./styles"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 플레이스홀더 플레이스홀더 ); } ``` ### Customizable Parts Do not convey meaning with icons alone. Describe the selection target and current value as text in `label`, `description`, and `buttonProps["accessibility-label"]`. #### Prefix ```tsx import "./styles"; import IconMagnifyingglassLine from "@karrotmarket/lynx-monochrome-icon/IconMagnifyingglassLine"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( example.com } buttonProps={{ "accessibility-label": "검색 조건 선택" }} > 검색 조건 ); } ``` #### Suffix ```tsx import "./styles"; import IconWonLine from "@karrotmarket/lynx-monochrome-icon/IconWonLine"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 170 } buttonProps={{ "accessibility-label": "거래 금액 선택" }} > 50,000 ); } ``` #### Both Affixes ```tsx import "./styles"; import IconPlusCircleLine from "@karrotmarket/lynx-monochrome-icon/IconPlusCircleLine"; import IconWonLine from "@karrotmarket/lynx-monochrome-icon/IconWonLine"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 25 } suffixIcon={} buttonProps={{ "accessibility-label": "추가 금액 선택" }} > 50,000 ); } ``` #### Indicator You can use `indicator` or `showRequiredIndicator`. For required items, also specify `required` together. ```tsx import "./styles"; import { useSeedClassName, VStack } from "@seed-design/lynx-react"; import { FieldButton, FieldButtonPlaceholder } from "@/components/ui/field-button"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 플레이스홀더 플레이스홀더 ); } ``` ## Web Version Differences The body applies Content Scale that maintains the background and scales only content, while ClearButton applies Root Scale that scales its own area. When combining Primitives directly, Button must be placed as a direct child of Root or inside a Fragment for the body Content Scale to be applied. If Button is wrapped by a custom component, the body Content Scale is not applied. - Apply tap handler and `accessibility-*` attributes to Lynx `` instead of HTML `