Lynx

Field Button

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.

Available since@seed-design/lynx-react@0.7.0, @seed-design/lynx-css@0.11.0
Loading Lynx example…

Installation

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

Props

FieldButton

Prop

Type

children?React.ReactNode
label?React.ReactNode
labelWeight?"medium" | "bold" | undefined
indicator?React.ReactNode
prefixIcon?React.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>> | undefined
prefix?React.ReactNode
suffixIcon?React.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>> | undefined
suffix?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
required?boolean | undefined
showRequiredIndicator?boolean | undefined
showClearButton?boolean | undefined
buttonProps?SeedInputButton.ButtonProps | undefined
clearButtonProps?FieldButtonClearButtonProps | undefined
fieldRef?React.Ref<NodesRef> | undefined
inputButtonRef?React.Ref<NodesRef> | undefined
style?CSSProperties | undefined
className?string | undefined

FieldButtonValue

Prop

Type

style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

FieldButtonPlaceholder

Prop

Type

style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

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"].
Loading Lynx example…

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.

Loading Lynx example…

FieldButtonValue & FieldButtonPlaceholder

FieldButtonValue and FieldButtonPlaceholder are Lynx <text> 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"].

Loading Lynx example…

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.

<FieldButton
  label="Username"
  description="You don't have to use your real name."
  buttonProps={{
    "accessibility-label": `Open username selection screen. Currently selected name: ${username || "none"}`,
    bindtap: openUsernamePicker,
  }}
>
  {username ? (
    <FieldButtonValue>{username}</FieldButtonValue>
  ) : (
    <FieldButtonPlaceholder>Kim Haneul</FieldButtonPlaceholder>
  )}
</FieldButton>

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.

Loading Lynx example…

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.

Loading Lynx example…

State

Enabled

Loading Lynx example…

Disabled

In disabled state, the button tap handler is not executed and the Clear Button is not rendered.

Loading Lynx example…

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.

Loading Lynx example…

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.

Loading Lynx example…

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

Loading Lynx example…

Suffix

Loading Lynx example…

Both Affixes

Loading Lynx example…

Indicator

You can use indicator or showRequiredIndicator. For required items, also specify required together.

Loading Lynx example…

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 <view> instead of HTML <button>.
  • Use buttonProps.bindtap instead of onClick. If a main thread handler is needed, you can use buttonProps["main-thread:bindtap"].
  • Use buttonProps["accessibility-label"] instead of aria-label.
  • Manage the selected value with the consumer's React state instead of values and onValuesChange.
  • size="responsive" is not supported. Specify large or medium.

Unsupported Lynx Features

  • HTML form submit, hidden input, browser validation, and React Hook Form integration are not supported.
  • DOM id-based aria-describedby connection and aria-haspopup are not supported.

Table of contents