Lynx

Swipeable Menu Sheet

Provides options related to user actions as a draggable sheet at the bottom of the screen.

Engine ≥ 3.6<overlay>
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:swipeable-menu-sheet

Usage

Combine Root, Trigger, Content, Group, Item provided by Registry. Trigger renders a native <view> that wraps children, so it does not support replacing children like asChild.

import { useState } from "@lynx-js/react";
import { ActionButton } from "@seed-design/lynx-react";
import {
  SwipeableMenuSheetContent,
  SwipeableMenuSheetGroup,
  SwipeableMenuSheetItem,
  SwipeableMenuSheetRoot,
  SwipeableMenuSheetTrigger,
} from "@/components/ui/swipeable-menu-sheet";

export function App() {
  const [open, setOpen] = useState(false);

  function handleEdit() {
    "background only";
    setOpen(false);
  }

  return (
    <SwipeableMenuSheetRoot open={open} onOpenChange={setOpen}>
      <SwipeableMenuSheetTrigger accessibility-label="Open post management menu">
        <ActionButton variant="neutralSolid">Open menu</ActionButton>
      </SwipeableMenuSheetTrigger>
      <SwipeableMenuSheetContent title="Post management">
        <SwipeableMenuSheetGroup>
          <SwipeableMenuSheetItem label="Edit" bindtap={handleEdit} />
          <SwipeableMenuSheetItem label="Delete" tone="critical" />
        </SwipeableMenuSheetGroup>
      </SwipeableMenuSheetContent>
    </SwipeableMenuSheetRoot>
  );
}

Item's bindtap only performs the action and does not automatically close the sheet. If you need to close it after the action, control open like the example above or call close() on the SwipeableMenuSheetRoot ref. For Content without a title, you must provide an accessibility-label so native assistive technologies can read the name.

Props

SwipeableMenuSheetRoot

Select controlled or uncontrolled open state with open?: boolean, defaultOpen?: boolean. skipAnimation?: boolean skips open and close animations. The format of onOpenChange is (open: boolean, details: { reason: "trigger" | "closeButton" | "interactOutside" | "drag" }) => void.

Prop

Type

open?boolean | undefined
defaultOpen?boolean | undefined
onOpenChange?((open: boolean, details: SwipeableMenuSheetOpenChangeDetails) => void) | undefined

SwipeableMenuSheetTrigger

Prop

Type

style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined

SwipeableMenuSheetContent

Specifying labelAlign?: "left" | "center" sets the default label alignment for Group and Item inside. The default value of showCloseButton?: boolean is false. When false, no separate hidden close button is rendered, and users can close by tapping the background or dragging downward.

Prop

Type

title?React.ReactNode
description?React.ReactNode
labelAlign?SwipeableMenuSheetLabelAlign | undefined

SwipeableMenuSheetGroup

You can override Content's default alignment in the group with labelAlign?: "left" | "center".

Prop

Type

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

SwipeableMenuSheetItem

label is required, and you can add description and prefixIcon. The default value of tone?: "neutral" | "critical" is "neutral". labelAlign?: "left" | "center" overrides the alignment interpreted in Item, Group, Content order.

Prop

Type

prefixIcon?React.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>> | undefined
labelReact.ReactNode
description?React.ReactNode
className?string | undefined
style?CSSProperties | undefined
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined
main-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefined
tone?SwipeableMenuSheetItemTone | undefined
labelAlign?SwipeableMenuSheetLabelAlign | undefined

Examples

Trigger

Tapping SwipeableMenuSheetTrigger opens the sheet. The open state can be closed by tapping the background, dragging downward, or clicking the close button shown with showCloseButton.

Loading Lynx example…

Controlled

Control the open state in other ways besides Trigger with open and onOpenChange. The new open value must also be reflected when closed by background tap and drag.

Loading Lynx example…

With Title

Display a title in the sheet header with title in Content.

Loading Lynx example…

With Title and Description

description displays additional description below the title.

Loading Lynx example…

Close Button

Setting showCloseButton displays a close button at the bottom of the sheet.

Loading Lynx example…

Label Align

labelAlign can override the Content's default in Group and Item in sequence.

labelAlign="left" with Prefix Icon

Items with a prefix icon typically use left alignment.

Loading Lynx example…

labelAlign="center" without Prefix Icon

Items without a prefix icon can use center alignment.

Loading Lynx example…

Overriding labelAlign

Override parent alignment with labelAlign on a group or individual item.

Loading Lynx example…

onOpenChange Details

The second argument of onOpenChange is { reason }. When opening, it is "trigger", and when closing, it is one of "closeButton", "interactOutside", "drag".

Loading Lynx example…

Skip Animation

Setting skipAnimation opens and closes immediately without enter/exit animations.

Loading Lynx example…

Web Version Differences

Lynx SwipeableMenuSheet has the following differences from the React version.

  • Trigger wrapper: Trigger renders a native <view> wrapper and does not provide an API to replace children like asChild.
  • Native interaction: Uses native <view>/<text> and bindtap instead of HTML elements and onClick.
  • Accessibility: Uses Lynx native accessibility attributes such as accessibility-label, accessibility-role-description instead of DOM ARIA attributes.
  • Close fallback: showCloseButton={false} does not create a hidden close button.
  • Close reason: Does not provide an escapeKeyDown reason corresponding to keyboard ESC.

Table of contents