React

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.

Available since@seed-design/react@1.1.0, @seed-design/css@1.1.0

Installation

npx @seed-design/cli@latest add ui:field-button

Props

FieldButton

Prop

Type

label?React.ReactNode
indicator?React.ReactNode
prefixIcon?React.ReactNode
prefix?React.ReactNode
suffixIcon?React.ReactNode
suffix?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
showRequiredIndicator?boolean | undefined
showClearButton?boolean | undefined
buttonProps?SeedFieldButton.ButtonProps | undefined
rootRef?React.Ref<HTMLDivElement> | undefined
name?string | undefined
values?string[] | undefined
onValuesChange?((values: string[]) => void) | undefined

FieldButtonValue

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.

  • buttonProps
    • onClick: Button click handler
    • aria-label: Accessibility label for the button
  • children
    • Composed using FieldButtonValue or FieldButtonPlaceholder, etc.
    • FieldButtonValue and FieldButtonPlaceholder are functionally identical except for styling differences. Screen readers do not read or distinguish between the two elements. For accessibility, provide an appropriate value to buttonProps["aria-label"]. See the Accessibility section for details.

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.

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.

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.

Form and Bottom Sheet

React Hook Form

Multiple Values (React Hook Form (Field Array))

Multiple Values (Native form)

State

Enabled

Disabled

  • The <input type="hidden" /> rendered when providing values is also disabled, so its value is not sent on form submission.
  • The <button> element is also disabled and cannot be clicked.

Read Only

  • The <input type="hidden" /> rendered when providing values is not affected.
  • The <button> element is disabled and cannot be clicked.

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.

Customizable Parts

Prefix

Suffix

Both Affixes

Indicator

Table of contents