Lynx

KeyboardAvoidingScrollView

A component that adjusts vertical scroll position and bottom margin so the soft keyboard does not cover the active input.

Engine ≥ 4.1<input><textarea>
Available since@seed-design/lynx-react@0.4.0

Installation

npm install @seed-design/lynx-react

Also add the Text Field registry snippet used in the example below.

npx @seed-design/cli add ui:text-field

Props

Prop

Type

id?string | undefined
hidden?boolean | undefined
focusable?boolean | undefined
bounces?boolean | undefined
enable-scroll?boolean | undefined
scroll-bar-enable?boolean | undefined
upper-threshold?number | undefined
lower-threshold?number | undefined
initial-scroll-offset?number | undefined
initial-scroll-to-index?number | undefined
bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Target>> | undefined
bindscrolltoupper?((e: ScrollToUpperEvent) => void) | undefined
bindscrolltolower?((e: ScrollToLowerEvent) => void) | undefined
bindscroll?((e: ScrollEvent) => void) | undefined
bindscrollend?((e: ScrollEndEvent) => void) | undefined
bindcontentsizechanged?((e: ContentSizeChangedEvent) => void) | undefined
style?CSSProperties | undefined
children?ReactNode
className?string | undefined
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined
bindtouchstart?EventHandler<BaseTouchEvent<Target>> | undefined
bindtouchend?EventHandler<BaseTouchEvent<Target>> | undefined
bindtouchcancel?EventHandler<BaseTouchEvent<Target>> | undefined
main-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefined

Usage

Place it in the outermost area of a vertically scrolling input screen. keyboardGap is the gap between the keyboard and the active input area. scrollBehavior determines how to move to the avoidance position.

Place input elements inside TextField provided by the Text Field Input and Text Field Textarea registry snippets. It tracks the input area and bottom based on the Field boundary that this TextField creates internally. Input elements automatically pass focus and blur. Auto-height-adjusting TextField.Textarea also passes layout changes, so no separate registration props are needed.

On Android, if this component handles keyboard avoidance exclusively, specify android-set-soft-input-mode="nothing" on the input element. This prevents overlapping with separate pan or resize of the host window.

Examples

Single-line Input

When focus moves to TextField.Input at the bottom of the screen, it automatically scrolls to create a 24px gap between the input area and the keyboard.

Loading Lynx example…

This example uses native keyboard behavior. Run it with Lynx Explorer from the QR code tab and tap the address input area at the bottom of the screen to verify.

Auto-resizing Textarea

When multiple lines are entered in TextField.Textarea and the height changes, the position of the active input area is recalculated.

Loading Lynx example…

This example uses native input element auto-resize and keyboard avoidance behavior. Run it with Lynx Explorer from the QR code tab and enter multiple lines to verify.

Web Version Differences

  • Uses Lynx keyboard global event and native node measurement instead of the browser's visualViewport or CSS viewport units.
  • Adds only the necessary bottom spacer when the keyboard opens and pauses automatic movement during user scrolling.
  • Browser form submission and automatic focus movement are not provided.

Unsupported Lynx Features

  • Horizontal and nested scroll views are not supported.
  • Keyboard toolbar height and caret-unit avoidance for large textareas are not yet implemented.

Table of contents