Lynx UI logo
Lynx UI

<Form>

A headless Form component for ReactLynx. It provides form context and a submit button that collects field values.

Basic Usage

Use <Form> to manage form state, handle form validation, and submission

Avoiding Keyboard Overlap

Prevent the on-screen keyboard from obscuring the input field by automatically adjusting the view when the keyboard appears

Structure

<FormRoot initialValues={}>
  <FormField as="RadioGroupRoot" name="select">
    {data.map(() => (
      <Radio>
        <RadioIndicator />
      </Radio>
    ))}
  </FormField>

  <FormField as="Input" name="input1" />
  <FormField as="Input" name="input2" />

  <FormSubmitButton onSubmit={handleSubmit}></FormSubmitButton>
</FormRoot>

API

FormRoot

children
iOS
Android
Harmony
TypeReactNode
The content of the form.
initialValues
iOS
Android
Harmony
TypeRecord
The initial values of the form fields.
onChanged
iOS
Android
Harmony
Type(values: Record) => void
Callback function triggered when any field's value changes. It receives the entire form's data.
onSubmit
iOS
Android
Harmony
Type(values: Record) => void
Callback function triggered when the form is submitted.

FormField

as
iOS
Android
Harmony
TypeInput | RadioGroupRoot | Checkbox | TextArea | Switch
Specifies the type of component to render.
children
iOS
Android
Harmony
TypeReactNode
The child elements of the form field, usually used for labels or complex structures.
className
iOS
Android
Harmony
Typestring
className
confirmType
iOS
Android
Harmony
Typesend | search | go | done | next·Default'send'
The type of confirm button
id
iOS
Android
Harmony
Typestring·Default'input'
The id of the input
inputFilter
iOS
Android
Harmony
Typestring
Filter the input content and process it in the form of regular expressions
maxLength
iOS
Android
Harmony
Typenumber·Default140
Max input length
name
iOS
Android
Harmony
Typestring
The unique identifier for the form field.
onBlur
iOS
Android
Harmony
Type(value: string) => void
Blurred
onChanged
iOS
Android
Harmony
Type(value: unknown) => void
Callback function triggered when this specific field's value changes.
onConfirm
iOS
Android
Harmony
Type(value: string) => void
Confirm button clicked
onFocus
iOS
Android
Harmony
Type(value: string) => void
Focused
onSelectionChange
iOS
Android
Harmony
Type(selectionStart: number, selectionEnd: number) => void
Input selection changed
placeholder
iOS
Android
Harmony
Typestring
Placeholder
readonly
iOS
Android
Harmony
Typeboolean·Defaultfalse
Interaction enabled
ref
TypeForwardedRef
showSoftInputOnFocus
iOS
Android
Harmony
Typeboolean·Defaulttrue
Show soft input keyboard while focused
style
iOS
Android
Harmony
TypeCSSProperties
style
type
iOS
Android
Harmony
Typenumber | text | digit | password | tel | email·Default"text"
Input content type
disabled
iOS
Android
Harmony
Typeboolean·Defaultfalse
If set to true, the RadioGroup can not accept interactions.
checkboxProps
iOS
Android
TypeViewProps
Checkbox supports original view props to be directly spread in this prop.
indeterminate
iOS
Android
Typeboolean·Defaultfalse
The indeterminate state of the Checkbox.
bounces
iOS
Typeboolean·Defaulttrue
Bounce effect for iOS
lineSpacing
iOS
Android
Typenumber | px | rpx
Line spacing
maxLines
iOS
Android
Harmony
Typenumber·Default40
Max input lines
switchProps
iOS
Android
TypeViewProps
Switch supports original view props to be directly spread in this prop.

FormSubmitButton

buttonProps
iOS
Android
Harmony
TypeViewProps
Button supports original view props to be directly spread in this prop.
className
iOS
Android
Harmony
Typestring
className
disabled
iOS
Android
Harmony
Typeboolean·Defaultfalse
Determines whether the button is disabled.
onSubmit
iOS
Android
Harmony
Type(values: Record) => void
Callback function triggered when the submit button is clicked, after the form's internal submit logic.
style
iOS
Android
Harmony
TypeCSSProperties
style
children
iOS
Android
Harmony
Type| ReactNode | ((state: {active: boolean, disabled: boolean}) => ReactNode)
children

State-based styling & rendering

This component exposes each of its internal states through two interchangeable channels, and the table below maps them one-to-one:

  • CSS className — a class like ui-<state> is toggled on the root node, so you can style it with selectors such as .ui-<state> { ... }.
  • Render-prop field — when children is a function, the same state is passed in via children({ <state>: boolean, ... }) for runtime-driven rendering.
ui-active
Render Propactive·Typeboolean
Whether the button is currently being pressed (and not disabled). Applied when `status.active` is true.
ui-disabled
Render Propdisabled·Typeboolean
Whether the button is disabled. Applied when `status.disabled` is true.
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.