打开一张从屏幕边缘滑出、可拖动、可调整大小的面板。

抽屉让一项任务拥有自己的面板(sheet),而不必离开页面。它共享 Dialog 的焦点与关闭行为,并在此基础上加入拖动、吸附点,以及一个可以用键盘操作的手柄。

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { createSignal } from "solid-js"
const goal = { initial: 350, min: 200, max: 400, step: 10 }

function Example() {
  const [calories, setCalories] = createSignal(goal.initial)
  return (
    <Drawer>
      <DrawerTrigger>Open Drawer</DrawerTrigger>
      <DrawerBackdrop />
      <DrawerContent>
        <div data-slot="grip" aria-hidden="true" />

        <div data-slot="stack">
          <DrawerTitle>Move goal</DrawerTitle>
          <DrawerDescription>Set your daily activity goal.</DrawerDescription>
        </div>

        <div data-slot="row">
          <button
            type="button"
            aria-label="Decrease"
            disabled={calories() <= goal.min}
            onClick={() => setCalories(calories() - goal.step)}
          >
            <svg
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="2"
              stroke-linecap="round"
              stroke-linejoin="round"
              aria-hidden="true"
            >
              <path d="M5 12h14" />
            </svg>
          </button>
          <div data-slot="stack">
            <div aria-live="polite">{calories()}</div>
            <div data-slot="hint">Calories/day</div>
          </div>
          <button
            type="button"
            aria-label="Increase"
            disabled={calories() >= goal.max}
            onClick={() => setCalories(calories() + goal.step)}
          >
            <svg
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="2"
              stroke-linecap="round"
              stroke-linejoin="round"
              aria-hidden="true"
            >
              <path d="M5 12h14" />
              <path d="M12 5v14" />
            </svg>
          </button>
        </div>

        <div data-slot="stack">
          <DrawerClose data-variant="solid" value="submit">
            Submit
          </DrawerClose>
          <DrawerClose>Cancel</DrawerClose>
        </div>
      </DrawerContent>
    </Drawer>
  )
}

export { Example }
打开抽屉,调整每日目标,然后按 Submit 或 Cancel。你也可以按 Escape、在外部按压,或者把面板拖向它所在的边缘来关闭它。

安装

npm install @ui-sdk/solid @ui-sdk/core

组合

用下面的组合构建一个 Drawer:

Drawer
├── DrawerTrigger
├── DrawerBackdrop
└── DrawerContent
    ├── DrawerTitle
    ├── DrawerDescription
    └── DrawerClose

内容就是面板。抽屉把它放进一个全屏视口,并用 translate 移动它。给它大小、表面和圆角;定位和位移交给抽屉。给遮罩一个颜色,比如 bg-black/30;不透明度由抽屉管理。

用法

导入各个部件并把它们组合起来:

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"

function Example() {
  return (
    <Drawer>
      <DrawerTrigger>Filters</DrawerTrigger>
      <DrawerBackdrop />
      <DrawerContent>
        <DrawerTitle>Filters</DrawerTitle>
        <DrawerDescription>Narrow down the results.</DrawerDescription>
        <DrawerClose>Done</DrawerClose>
      </DrawerContent>
    </Drawer>
  )
}

export { Example }

可滚动内容

把长内容放进内部的 min-h-0 flex-1 overflow-y-auto 区域。向下拖动会先滚动这个区域;到达顶部后,同一个手势就能移动抽屉。initialFocus="content" 让焦点从面板本身开始。

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { For } from "solid-js"

const paragraphs = [
  "The drawer rises from any edge, rests on snap points and follows your finger with the same spring as a system sheet.",
  "Snap points take fractions of the screen, pixels, rem, percentages or the content's own size. Points that land within a pixel of each other merge into one.",
  "Dragging a list scrolls it until it reaches the top, and then the same gesture moves the drawer, so closing a long sheet never needs two tries.",
  "The handle steps through the snap points with a press, the arrow keys, Home and End. Screen readers on phones adjust it like a slider.",
  "Below a snap point you choose, the page behind stays usable and undimmed, like a map with a sheet of results.",
  "Drawers opened from inside each other stack, and the one beneath steps back while the new one rises.",
  "The on-screen keyboard pushes the drawer up, and the focused field scrolls into view inside it, never the page.",
  "With reduced motion, drawers fade in and out instead of sliding.",
]

function Example() {
  return (
    <Drawer>
      <DrawerTrigger>Scrollable Content</DrawerTrigger>
      <DrawerBackdrop />
      <DrawerContent initialFocus="content">
        <div data-slot="grip" aria-hidden="true" />
        <div data-slot="stack">
          <DrawerTitle>Release notes</DrawerTitle>
          <DrawerDescription>Everything new in the drawer.</DrawerDescription>
        </div>
        <div data-slot="scroll">
          <For each={[...paragraphs, ...paragraphs]}>
            {(paragraph) => <p data-slot="hint">{paragraph}</p>}
          </For>
        </div>
        <div data-slot="stack">
          <DrawerClose data-variant="solid">Got It</DrawerClose>
        </div>
      </DrawerContent>
    </Drawer>
  )
}

export { Example }
打开长面板并滚动它的文字。在顶部向下拖动可以移动面板;使用键盘时,Tab 会到达控件,Escape 会关闭它。

面板里的字段、滑块和颜色区域保留各自的拖动。对于你自己的拖动面,比如画布或地图,给它加上 data-drawer-no-drag,从这里开始的拖动就不会移动抽屉。

方向

side 选择 bottom、top、left 或 right。逻辑方向 start 和 end 跟随文字方向。内容的 data-side 告诉你该给哪条物理边缘设置样式。

侧边抽屉可以启用 preventEdgeSwipe,避免边缘手势触发 iOS Safari 的后退或前进导航。它也会阻止贴在这些边缘上的点击,所以只在你需要这个取舍时使用。

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { For } from "solid-js"

const sides = [
  {
    side: "top",
    label: "Top",
    title: "Notifications",
    description: "You're all caught up.",
  },
  {
    side: "right",
    label: "Right",
    title: "Cart",
    description: "2 items, $84.00.",
  },
  {
    side: "bottom",
    label: "Bottom",
    title: "Share",
    description: "Send this page to your team.",
  },
  {
    side: "left",
    label: "Left",
    title: "Menu",
    description: "Jump to a section of the docs.",
  },
] as const

function Example() {
  return (
    <div data-slot="row">
      <For each={sides}>
        {({ side, label, title, description }) => (
          <Drawer
            side={side}
            preventEdgeSwipe={side === "left" || side === "right"}
          >
            <DrawerTrigger>{label}</DrawerTrigger>
            <DrawerBackdrop />
            <DrawerContent>
              <div data-slot="stack">
                <DrawerTitle>{title}</DrawerTitle>
                <DrawerDescription>{description}</DrawerDescription>
              </div>
              <DrawerClose data-variant="solid">Close</DrawerClose>
            </DrawerContent>
          </Drawer>
        )}
      </For>
    </div>
  )
}

export { Example }
从每条边缘打开一张面板。把它拖回那条边缘、在外部按压,或按 Escape 来关闭它。

吸附点

snapPoints 是抽屉可以停靠的位置。它在第一个位置打开,或者在 defaultSnapPoint 处打开;拖动后会停在另一个位置。快速甩动可以跳过中间的位置。

值大小
0.5沿抽屉轴线的视口一半。
320 或 "320px"像素;大于 1 的数字是像素值。
"20rem"根字号的倍数。
"50%"视口的百分比。
"content"面板自身的大小,默认值。

面板的 CSS 尺寸就是上限:1 不能把一张矮面板撑满屏幕。如果最大的吸附点应该几乎填满屏幕,就用 h-[calc(100dvh-3rem)] 这样的高度。内容或可用空间变化时,抽屉会重新测量;停靠点因此移动时会报告 content-resize。

手柄是一个带无障碍名称的按钮。按压它会移到下一个更大的吸附点,到达最大后回绕到最小的吸附点。沿抽屉轴线的方向键每次移动一个吸附点,不会回绕;Home 和 End 移到两端。canExpand 和 canCollapse 让示例显示还剩哪些移动。

如果面板只有一个吸附点,就用装饰性的横条代替不可用的按钮。

import {
  Drawer,
  DrawerBackdrop,
  DrawerContent,
  DrawerDescription,
  DrawerHandle,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { For } from "solid-js"

const places = [
  { name: "Blue Bottle Coffee", detail: "Coffee · 0.2 mi" },
  { name: "Tartine Bakery", detail: "Bakery · 0.4 mi" },
  { name: "Dolores Park", detail: "Park · 0.5 mi" },
  { name: "Mission Dolores", detail: "Landmark · 0.6 mi" },
  { name: "Ritual Coffee Roasters", detail: "Coffee · 0.7 mi" },
  { name: "Bi-Rite Creamery", detail: "Ice cream · 0.7 mi" },
  { name: "Alamo Square", detail: "Park · 1.1 mi" },
  { name: "The Castro Theatre", detail: "Cinema · 1.2 mi" },
  { name: "Ferry Building", detail: "Market · 2.3 mi" },
  { name: "Coit Tower", detail: "Landmark · 2.9 mi" },
  { name: "Golden Gate Park", detail: "Park · 3.0 mi" },
  { name: "Lands End", detail: "Trail · 5.4 mi" },
]

function Example() {
  return (
    <Drawer snapPoints={[0.25, 0.5, 1]} defaultSnapPoint={0.5} expandOnScroll>
      <DrawerTrigger>Find a Place</DrawerTrigger>
      <DrawerBackdrop />
      <DrawerContent>
        <DrawerHandle aria-label="Resize" />
        <div data-slot="stack">
          <DrawerTitle>Places nearby</DrawerTitle>
          <DrawerDescription>
            Drag the drawer, or press the handle, to see more.
          </DrawerDescription>
        </div>
        <div data-slot="scroll">
          <ul data-slot="list">
            <For each={places}>
              {(place) => (
                <li>
                  <div>{place.name}</div>
                  <div data-slot="hint">{place.detail}</div>
                </li>
              )}
            </For>
          </ul>
        </div>
      </DrawerContent>
    </Drawer>
  )
}

export { Example }
在中间吸附点打开面板。拖动它、按压手柄,或者 Tab 到手柄并用 Up、Down、Home 和 End 试试其他停靠位置。

受控

传入 open={open()} 和 onOpenChange,或者传入 snapPoint={snapPoint()} 和 onSnapPointChange。你可以分别控制打开状态和吸附点。用 details.cancel() 取消一次提议的变更;被取消的滑动会弹回。onOpenChangeComplete 在面板停稳后运行。

const [open, setOpen] = createSignal(false)
const [snapPoint, setSnapPoint] = createSignal<SnapPoint>(0.5)

<Drawer
  open={open()}
  onOpenChange={setOpen}
  snapPoints={[0.25, 0.5, 1]}
  snapPoint={snapPoint()}
  onSnapPointChange={setSnapPoint}
>

不可关闭

把 dismissible 设为 false 后,Escape、外部按压、返回手势和滑动都会让抽屉保持打开。onDismissAttempt 告诉你尝试了什么,这样你可以提供一条丢弃未保存工作的途径。Close 部件、触发器和控制器仍然可以主动关闭它。

<Drawer
  dismissible={false}
  onDismissAttempt={(details) => setAttempt(details.reason)}
>
  <DrawerTrigger>Write a Post</DrawerTrigger>
  <DrawerBackdrop />
  <DrawerContent>
    <Show when={attempt()}>
      <DrawerClose>Discard</DrawerClose>
    </Show>
    <DrawerClose value="post">Post</DrawerClose>
  </DrawerContent>
</Drawer>

当页面应该在一张小面板旁边保持可用时,设置 modalAbove。在这个位置或以下,页面不变暗、不进入不可交互(inert)状态,也没有滚动锁定和 aria-modal。超过这个位置时,modal 生效。切换发生在抽屉停稳时,并且不移动焦点;data-interactive 暴露页面可用的状态。

modal 的选项与 Dialog 相同:true 阻止页面交互,"trap-focus" 把 Tab 保持在内部,同时页面仍然可用,false 允许焦点离开。点击页面也会关闭 "trap-focus" 抽屉,而非模态抽屉只有在启用 closeOnOutsidePress 时才会在外部按压时关闭。

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerHandle,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { createSignal, For } from "solid-js"

const places = [
  { name: "Blue Bottle Coffee", detail: "Coffee · 0.2 mi" },
  { name: "Tartine Bakery", detail: "Bakery · 0.4 mi" },
  { name: "Dolores Park", detail: "Park · 0.5 mi" },
  { name: "Mission Dolores", detail: "Landmark · 0.6 mi" },
  { name: "Ritual Coffee Roasters", detail: "Coffee · 0.7 mi" },
]

function Example() {
  const [destination, setDestination] = createSignal(places[0].name)
  return (
    <div data-slot="stack">
      <ul data-slot="list" aria-label="Places">
        <For each={places}>
          {(place) => (
            <li>
              <button
                type="button"
                aria-pressed={destination() === place.name ? "true" : "false"}
                onClick={() => setDestination(place.name)}
              >
                {place.name}
                <span data-slot="hint">{place.detail}</span>
              </button>
            </li>
          )}
        </For>
      </ul>
      <Drawer snapPoints={[0.2, 0.6]} modalAbove={0.2}>
        <DrawerTrigger>Get Directions</DrawerTrigger>
        <DrawerBackdrop />
        <DrawerContent>
          {(state) => (
            <>
              <DrawerHandle aria-label="Resize" />
              <div data-slot="row">
                <div data-slot="stack">
                  <DrawerTitle>To {destination()}</DrawerTitle>
                  <DrawerDescription>
                    {state.interactive
                      ? "12 min walk. Pick another place behind the sheet."
                      : "12 min walk. Drag the sheet down to see the places."}
                  </DrawerDescription>
                </div>
                <DrawerClose>Done</DrawerClose>
              </div>
              <ol data-slot="stack">
                <li>Head north on Valencia St.</li>
                <li>Turn left onto 18th St.</li>
                <li>Arrive at {destination()}.</li>
              </ol>
            </>
          )}
        </DrawerContent>
      </Drawer>
    </div>
  )
}

export { Example }
在小吸附点打开 Get Directions,选择面板后面的另一个地点。展开它让面板变为模态,再收起它重新使用页面。

嵌套抽屉

在另一个抽屉里打开的抽屉会加入它的栈。Escape 和外部按压只影响最上层的抽屉;关闭父级也会关闭它的子级。--drawer-stack 跟随其上方面板的打开和拖动而变化,所以父级可以用 [scale:calc(1-var(--drawer-stack)*0.04)] 缩小并后退。

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { Field, FieldLabel } from "@ui-sdk/solid/field"
import { Input } from "@ui-sdk/solid/input"

function Example() {
  return (
    <Drawer>
      <DrawerTrigger>Account</DrawerTrigger>
      <DrawerBackdrop />
      <DrawerContent>
        <div data-slot="grip" aria-hidden="true" />
        <div data-slot="stack">
          <DrawerTitle>Account</DrawerTitle>
          <DrawerDescription>Manage how you sign in.</DrawerDescription>
        </div>
        <dl>
          <div data-slot="row">
            <dt>Email</dt>
            <dd>hollis@example.com</dd>
          </div>
          <div data-slot="row">
            <dt>Password</dt>
            <dd>Changed 3 months ago</dd>
          </div>
          <div data-slot="row">
            <dt>Two-factor</dt>
            <dd>On</dd>
          </div>
        </dl>
        <div data-slot="stack">
          <Drawer>
            <DrawerTrigger>Change Password</DrawerTrigger>
            <DrawerBackdrop />
            <DrawerContent>
              <div data-slot="grip" aria-hidden="true" />
              <div data-slot="stack">
                <DrawerTitle>Change password</DrawerTitle>
                <DrawerDescription>
                  Use at least 12 characters.
                </DrawerDescription>
              </div>
              <Field>
                <FieldLabel>New password</FieldLabel>
                <Input type="password" />
              </Field>
              <div data-slot="stack">
                <DrawerClose data-variant="solid">Update</DrawerClose>
              </div>
            </DrawerContent>
          </Drawer>
          <DrawerClose data-variant="solid">Done</DrawerClose>
        </div>
      </DrawerContent>
    </Drawer>
  )
}

export { Example }
打开 Account,然后打开 Change Password。父级会随着子级打开而后退;Escape 一次关闭一张面板。

表单

Close 部件的 action 可以返回一个 Promise。它运行期间面板保持打开,包括经过 Escape 或滑动。被拒绝时,动作的错误状态会保留下来,供重试。共用的待处理与错误约定见 Alert Dialog 的异步动作。

keepMounted 保留尚未完成的字段,finalFocus 把焦点还给更新后的个人资料。

<DrawerContent keepMounted finalFocus={() => summary}>
  <form ref={form}>{/* fields */}</form>
  <DrawerClose action={save}>
    {(state) =>
      state.pending ? "Saving…" : state.error ? "Try Again" : "Save Changes"
    }
  </DrawerClose>
</DrawerContent>

Outlet

Outlet 让另一个元素跟随面板的进度。它的 keyframes 从收起运行到完全展开;这个示例让 Compose 面板后面的收件箱缩放并变圆。抽屉之外的 Outlet 通过它的控制器连接。

import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerOutlet,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/solid/drawer"
import { Field, FieldLabel } from "@ui-sdk/solid/field"
import { Textarea } from "@ui-sdk/solid/textarea"
import { Input } from "@ui-sdk/solid/input"
import { For } from "solid-js"

const messages = [
  { from: "Inès", text: "The proofs are back from the printer." },
  { from: "Kofi", text: "Lunch on Thursday?" },
  { from: "Wren", text: "Pushed the fix for the release build." },
  { from: "Tomasz", text: "Can you review the launch checklist?" },
]

function Example() {
  return (
    <Drawer>
      <div>
        <DrawerOutlet
          keyframes={{ scale: [1, 0.94], borderRadius: ["0px", "24px"] }}
        >
          <div data-slot="row">
            <span>Inbox</span>
            <DrawerTrigger data-variant="solid">Compose</DrawerTrigger>
          </div>
          <ul data-slot="list">
            <For each={messages}>
              {(message) => (
                <li>
                  <div>{message.from}</div>
                  <div data-slot="hint">{message.text}</div>
                </li>
              )}
            </For>
          </ul>
        </DrawerOutlet>
      </div>
      <DrawerBackdrop />
      <DrawerContent>
        <div data-slot="grip" aria-hidden="true" />
        <div data-slot="stack">
          <DrawerTitle>New message</DrawerTitle>
          <DrawerDescription>Write a quick note to the team.</DrawerDescription>
        </div>
        <Field>
          <FieldLabel>To</FieldLabel>
          <Input defaultValue="Design team" />
        </Field>
        <Field>
          <FieldLabel>Message</FieldLabel>
          <Textarea placeholder="What's new?" />
        </Field>
        <div data-slot="stack">
          <DrawerClose data-variant="solid" value="send">
            Send
          </DrawerClose>
        </div>
      </DrawerContent>
    </Drawer>
  )
}

export { Example }
打开 Compose,然后慢慢拖动面板。后面的收件箱会随着面板的进度缩放并变圆。

从任意位置打开

把外部触发器和抽屉连接到同一个 createDrawerController<Payload, Result>()。每个触发器传一个 payload;内容从自己的状态里读取它。这让同一张面板可以服务每一行,包括为不可用操作准备的禁用触发器。

在控制器上调用 open({ payload }) 会返回一个 Promise,带着关闭的 reason 和 returnValue。getSnapPoint() 和 setSnapPoint() 也让代码可以读取或移动面板。控制器指南涵盖共用的结果与 payload 流程。

const share = createDrawerController<SharedFile, "copy" | "email">()

<DrawerTrigger controller={share} payload={file} disabled={file.uploading}>
  Share
</DrawerTrigger>

<Drawer controller={share}>
  <DrawerBackdrop />
  <DrawerContent<SharedFile>>
    {(state) => <DrawerTitle>Share {state.payload?.name}</DrawerTitle>}
  </DrawerContent>
</Drawer>

const { reason, returnValue } = await share.open({ payload: roadmap })

操作表

面板可以提供选项而不是表单。给每个 Close 部件一个 value;打开的 Promise 返回选中的动作。Escape、外部按压或滑动不返回值,这个示例把它当作 Cancel。

把风险最低的动作放在最前面,因为键盘或代码打开时会从那里开始。需要确认的选择,改用 Alert Dialog。

控制台
import {
  createDrawerController,
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
} from "@ui-sdk/solid/drawer"
import { useLog } from "./log"

type PhotoAction = "share" | "duplicate" | "delete" | "cancel"

function Example() {
  const photoActions = createDrawerController<undefined, PhotoAction>()
  const log = useLog()

  async function choose() {
    const { returnValue = "cancel" } = await photoActions.open()
    log(returnValue === "cancel" ? "Canceled" : `Chose ${returnValue}`)
  }

  return (
    <div data-slot="row">
      <button type="button" onClick={choose}>
        Photo Options
      </button>
      <Drawer controller={photoActions}>
        <DrawerBackdrop />
        <DrawerContent>
          <div data-slot="stack">
            <DrawerTitle>Beach.jpg</DrawerTitle>
            <DrawerDescription>Taken today at 9:41.</DrawerDescription>
          </div>
          <div data-slot="stack">
            <DrawerClose value="share">Share</DrawerClose>
            <DrawerClose value="duplicate">Duplicate</DrawerClose>
            <DrawerClose value="delete">Delete</DrawerClose>
            <DrawerClose value="cancel">Cancel</DrawerClose>
          </div>
        </DrawerContent>
      </Drawer>
    </div>
  )
}

export { Example }
打开 Photo Options 并选择一个动作。控制台会记录返回的值;关闭面板算作 Cancel。

响应式

这个做法用媒体查询在窄屏上选择 Drawer,在宽屏上选择 Dialog。它会在断点处替换组件树,所以打开的面板会关闭,本地字段编辑也会重置。如果打开状态和字段值必须在切换后保留,就把它们提升到那个分支之外。

const isDesktop = createMediaQuery("(min-width: 768px)")

return (
  <Show
    when={isDesktop()}
    fallback={
      <Drawer>
        <DrawerTrigger>Edit Profile</DrawerTrigger>
        <DrawerBackdrop />
        <DrawerContent>
          <ProfileForm />
        </DrawerContent>
      </Drawer>
    }
  >
    <Dialog>
      <DialogTrigger>Edit Profile</DialogTrigger>
      <DialogBackdrop />
      <DialogContent>
        <ProfileForm />
      </DialogContent>
    </Dialog>
  </Show>
)

驱动方式与物理参数

driver 决定面板如何移动。"scroll-snap" 为底部面板使用原生滚动和 CSS 吸附点;"pointer" 在每条边上使用指针拖动和弹簧运动。默认的 "auto" 在触摸屏上为底部面板选择原生滚动,而鼠标和触控笔、其他边缘、modalAbove 或 expandOnScroll 为 false 时选择指针拖动。data-driver 报告当前的选择。

用 physics 覆盖 sheetPhysics.ios 的一部分,来调整指针驱动:response 改变弹簧的时间,dampingRatio 改变停稳过程,momentumDampingRatio 影响甩动,rubberBand 改变越过最大吸附点时的阻力。

<Drawer driver="pointer" physics={{ response: 0.3, dampingRatio: 0.9 }} />

页面集成

themeColor 会随着遮罩把已有的 <meta name="theme-color"> 调暗,让浏览器的工具栏可以跟着变化;没有这个标签的页面不受影响。persistentElements 在抽屉处于模态时让选中的元素保持可用:一个元素或选择器的数组,或者一个返回元素的函数。必须留在遮罩之上的内容,也需要自己的顶层表面。

抽屉就地渲染,并使用顶层(top layer)。container 把遮罩和视口移到别处,比如移进影子根(shadow root),或者移出外围的表单。见共享的浮层指南。

<Drawer themeColor persistentElements={["#chat-launcher"]}>
  <DrawerContent container={shadowRoot} />
</Drawer>

自定义渲染

每个部件都接受 render,一个接收要展开的属性和部件状态的函数,它的 children 也可以是同一个状态的函数。

<DrawerTrigger
  shortcut="mod+j"
  render={(props, state) => <button {...props}>{state.open ? "Viewing" : "View Details"}</button>}
/>
<DrawerContent>
  {(state) => (
    <>
      <DrawerTitle render={(props) => <h3 {...props} />}>Quarterly report</DrawerTitle>
      <DrawerDescription>{state.expanded ? "Showing all of it." : "Drag up to see more."}</DrawerDescription>
      <DrawerClose render={(props) => <a {...props} href="/reports/q3" />}>Open the Full Page</DrawerClose>
    </>
  )}
</DrawerContent>

样式

每个部件都有一个 data-slot,比如 drawer-content,并通过数据属性下列出的属性展示状态。

把内容的 translate 和遮罩的不透明度留给抽屉。你可以设置缩放、圆角、颜色和内部滚动区域的样式。底部面板可以在边缘下方用一个 after 元素,在过度滚动时盖住空隙,示例就是这样做的。抽屉尊重减少动态效果设置,改为淡入淡出而不是滑动。

DrawerContent

变量内容
--drawer-progressHow far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
--drawer-dimHow dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
--drawer-expand0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
--drawer-stackHow many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.

Viewport

变量内容
--keyboard-insetHow many pixels of the page the on-screen keyboard covers, 0 without one.
--visual-viewport-widthThe width of the part of the page you can see.
--visual-viewport-heightThe height of the part of the page you can see, above the keyboard.
--visual-viewport-topHow far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up.

DrawerOutlet

变量内容
--drawer-progressHow far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
--drawer-dimHow dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
--drawer-expand0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.

数据属性

DrawerTrigger

[data-slot="drawer-trigger"]

属性含义
data-closedPresent while the drawer is closed, including while it animates out.
data-disabledPresent when the trigger is disabled.
data-openPresent while the drawer is open. On a trigger, while it's open from that trigger.

DrawerBackdrop

[data-slot="drawer-backdrop"]

属性含义
data-closedPresent while the drawer is closed, including while it animates out.
data-openPresent while the drawer is open. On a trigger, while it's open from that trigger.
data-interactivePresent while it rests at or below modalAbove, so the page behind is usable. The backdrop lets presses through.
data-starting-stylePresent for the first frame. The drawer slides itself, so leave the content's translate and the backdrop's opacity alone.
data-ending-stylePresent while the drawer animates out.
data-draggingPresent while a finger, mouse or pen drags it.

Viewport

[data-slot="drawer-viewport"]

属性含义
data-sidetoprightbottomleftThe edge it comes from, with start and end resolved for the writing direction.
data-closedPresent while the drawer is closed, including while it animates out.
data-openPresent while the drawer is open. On a trigger, while it's open from that trigger.
data-keyboardPresent on the viewport while the on-screen keyboard covers part of the page.

DrawerContent

[data-slot="drawer-content"]

属性含义
data-closedPresent while the drawer is closed, including while it animates out.
data-sidetoprightbottomleftThe edge it comes from, with start and end resolved for the writing direction.
data-openPresent while the drawer is open. On a trigger, while it's open from that trigger.
data-snap-pointcontent0.2The snap point it rests on or is moving to, as written, like 0.5 or content.
data-interactivePresent while it rests at or below modalAbove, so the page behind is usable. The backdrop lets presses through.
data-starting-stylePresent for the first frame. The drawer slides itself, so leave the content's translate and the backdrop's opacity alone.
data-ending-stylePresent while the drawer animates out.
data-driverpointerscroll-snapWhat moves it.
data-expandedPresent while it rests at its largest snap point.
data-draggingPresent while a finger, mouse or pen drags it.

DrawerHandle

[data-slot="drawer-handle"]

属性含义
data-snap-pointcontent0.2The snap point it rests on or is moving to, as written, like 0.5 or content.
data-expandedPresent while it rests at its largest snap point.

DrawerClose

[data-slot="drawer-close"]

属性含义
data-disabled
data-pendingPresent on a Close part while its action runs.

DrawerOutlet

[data-slot="drawer-outlet"]

属性含义
data-closedPresent while the drawer is closed, including while it animates out.
data-openPresent while the drawer is open. On a trigger, while it's open from that trigger.

API 参考

属性和回调与下面相同,都作为 Solid props。

Drawer

debug?boolean
Logs every state change with its reason to the console, in development builds.
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
open?boolean
Whether the dialog is open. Pass it to control the dialog.
defaultOpen?boolean
Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page.
onOpenChangeComplete?((open: boolean) => void)
Runs once the dialog has finished opening or closing, after any animation.
dismissible?boolean
Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass false while a form has unsaved changes, and ask in onDismissAttempt.
persistentElements?(string | Element)[] | (() => Element[])
Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it.
pendingAnnouncement?string
What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
onOpenChange?((open: boolean, details: DialogOpenChangeDetails<DrawerOpenChangeReason>) => void)
Runs when the drawer wants to open or close. details.reason says why, "swipe" included, details.cancel() stops it, and details.returnValue carries what closed it.
onPayloadChange?((payload: unknown, details: ChangeDetails<DrawerPayloadChangeReason>) => void)
Runs when the payload the content shows changes: a trigger with another payload opens the drawer, or takes a non-modal drawer over while it's open, which fires no onOpenChange, and so does a controller's open({ payload }) on the open drawer. details.cancel() keeps the previous payload.
onDismissAttempt?((details: DrawerDismissAttemptDetails) => void)
Runs when a dismissal was refused because dismissible is false, including a swipe. The drawer resists and springs back. Ask "Discard changes?" here.
modal?"trap-focus" | boolean
true: the rest of the page is inert and doesn't scroll, focus is trapped, and an outside press only closes the drawer. "trap-focus": traps focus and leaves the page usable. false: a drawer beside the page. See modalAbove to make it modal only above a snap point.
closeOnOutsidePress?boolean
Whether pressing outside the drawer, like on its backdrop, closes it.
controller?DrawerController<any, any>
Opens, closes and moves the drawer from anywhere, and connects triggers and outlets outside it. Create one with createDrawerController().
snapPoints?SnapPoint[]
Where the drawer can rest, from the edge it comes from: a fraction of the screen up to 1, pixels above 1, "…px", "…rem", "…%", or "content" for its own size. None can be larger than the drawer, which you size with CSS.
snapPoint?SnapPoint | null
The snap point it rests on. Pass it to control it.
defaultSnapPoint?SnapPoint
The snap point it opens at, when uncontrolled. It opens there again each time.
onSnapPointChange?((snapPoint: SnapPoint, details: ChangeDetails<DrawerSnapPointChangeReason>) => void)
Runs when the drawer moves to another snap point. details.reason says why: a swipe, the handle, the keyboard, a resize or the controller.
side?Side
The edge it comes from. "start" and "end" follow the writing direction.
modalAbove?SnapPoint
At or below this snap point the page stays usable and undimmed, like Maps: no inert page, no scroll lock, no aria-modal, and presses beside the drawer reach the page. Above it, modal applies. Changes once the drawer comes to rest.
driver?SheetDriverName
How it moves. "pointer" follows touch, mouse and pen with a spring fitted to iOS. "scroll-snap" uses the browser's own scrolling for bottom drawers. "auto" picks scroll snap for a bottom drawer on a touch screen, unless modalAbove is set or expandOnScroll is false, and the pointer driver otherwise.
expandOnScroll?boolean
Whether dragging toward a larger snap point on scrollable content moves the drawer first, until it's at its largest.
physics?Partial<SheetPhysics>
Overrides the motion: spring, projection, rubber band and dim. Starts from sheetPhysics.ios.
themeColor?boolean
Whether <meta name="theme-color"> dims with the backdrop, so Safari's toolbars darken too. Written where motion starts and ends, never per frame.
preventEdgeSwipe?boolean
Whether presses on the drawer near the screen's left and right edges are kept from starting iOS Safari's back and forward swipe. Taps right at those edges then don't click. Read when the content mounts.

DrawerTrigger

抽屉之外的触发器也接受 controller。

disabled?boolean
Stops the trigger from opening the dialog. A native button can't be focused or pressed, unless focusableWhenDisabled is set.
focusableWhenDisabled?boolean
Keeps a disabled trigger in the tab order with aria-disabled instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.
payload?unknown
Data for the content to render when this trigger opens the dialog, like the row it belongs to.
shortcut?string
A keyboard shortcut that presses the trigger, like "mod+k". mod is Command on Apple platforms and Control elsewhere. Sets aria-keyshortcuts, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.
controller?PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
Connects a trigger outside the dialog, like one per table row, to the dialog with this controller.

DrawerBackdrop

让模态抽屉后面的页面变暗,不透明度由抽屉管理。渲染一个 div。

DrawerContent

container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
initialFocus?DialogInitialFocus
Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears, unless this is set to something other than "auto".
finalFocus?PopupFocusTarget
Where focus goes when the dialog closes while focus is inside it.
keepMounted?boolean
Whether the dialog stays in the page, hidden, while closed. Its content keeps its state between opens.

DrawerHandle

调整面板大小:按压会移到下一个吸附点,方向键、Home 和 End 选择一个吸附点。渲染一个 button。

DrawerTitle

为抽屉命名。渲染一个 h2。

DrawerDescription

在渲染期间描述抽屉。渲染一个 p。

DrawerClose

value?string
Reported as returnValue in onOpenChange and by the controller's open(). createConfirm() resolves true for "confirm".
action?((event: Event | undefined, details: ActionDetails) => unknown)
Runs when the part is pressed, before the dialog closes. A returned Promise keeps the dialog open while it runs: the part gets data-pending, aria-busy and aria-disabled, screen readers hear the dialog's pendingAnnouncement after a second, and nothing but the controller closes the dialog. It closes with reason "action" once the Promise resolves. A rejection keeps it open and puts the reason in the part's error state until the next press, or until the dialog opens again. details.source says how the part was pressed, for changes made after an await.

DrawerShortcut

shortcut?string
The keys to show. Inside a trigger, its shortcut.

DrawerOutlet

抽屉之外的 Outlet 也接受 controller。

keyframes?SheetKeyframes
Keyframes it plays as the drawer expands, like { scale: [1, 0.94] }: the first while collapsed, the last at the largest snap point. They run on the compositor when they're transforms or opacity.
controller?DrawerController<any, any>
Connects an outlet outside the drawer, like the app's shell, to the drawer with this controller.

状态

每个部件的 render 函数、基于状态的类名和槽位收到什么。

DrawerTrigger:

openboolean
Whether the dialog is open from this trigger.
disabledboolean
Set by the trigger's disabled prop, which stops it opening the dialog.

DrawerBackdrop:

openboolean
Whether the dialog is open. False while it animates out.
nestedboolean
Whether the dialog was opened from inside another dialog.
nestedOpenboolean
Whether a dialog opened from inside this one is open.
interactiveboolean
Whether the page behind is usable, so the backdrop lets presses through.

DrawerContent:

openboolean
Whether the dialog is open. False while it animates out.
modalboolean | "trap-focus"
The modal setting. Always true for an alert dialog.
nestedboolean
Whether the dialog was opened from inside another dialog.
nestedOpenboolean
Whether a dialog opened from inside this one is open.
stacknumber
How many dialogs are open above this one, nested inside it.
payloadPayload | undefined
The payload of the last open, from the trigger that opened it or a controller, typed as the controller's Payload.
pendingboolean
Whether a Close part's action is running.
snapPointSnapPoint | null
The snap point it rests on or is moving to.
expandedboolean
Whether it's at its largest snap point.
draggingboolean
Whether a finger, mouse or pen is dragging it.
sidePhysicalSide
The edge it comes from, with start and end resolved.
interactiveboolean
Whether the page behind is usable, because it rests at or below modalAbove.

DrawerHandle:

snapPointSnapPoint | null
The snap point it rests on.
canExpandboolean
Whether there's a larger snap point to move to.
canCollapseboolean
Whether there's a smaller snap point to move to.

DrawerClose:

pendingboolean
Whether this part's action is running.
errorunknown
Why this part's last action failed, until it's pressed again or the dialog opens again.

DrawerOutlet:

openboolean
Whether the drawer is open. False as soon as it starts closing, while it still animates out.

原因

details.reason 说明抽屉为什么打开或关闭。

trigger-pressMouseEvent | KeyboardEvent | TouchEvent
Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its touchend.
close-pressMouseEvent | KeyboardEvent | SubmitEvent
A Close part was pressed, or a form with method="dialog" was submitted.
outside-pressMouseEvent
A press outside the layer.
escape-keyKeyboardEvent
Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
parent-closenone
The parent layer closed.
backEvent
Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
actionMouseEvent | KeyboardEvent
A Close part's action finished.
shortcutKeyboardEvent
A keyboard shortcut, like a trigger's shortcut.
swipeTouchEvent | PointerEvent
A swipe gesture: a finger, mouse or pen dragged it.
imperativenone
A controller or api call.

对于 payload 变更,它说明是什么打开了抽屉或接管了它。

trigger-pressMouseEvent | KeyboardEvent | TouchEvent
Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its touchend.
shortcutKeyboardEvent
A keyboard shortcut, like a trigger's shortcut.
imperativenone
A controller or api call.

它为什么移动到另一个吸附点:

backEvent
Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
swipeTouchEvent | PointerEvent
A swipe gesture: a finger, mouse or pen dragged it.
imperativenone
A controller or api call.
handle-pressMouseEvent | KeyboardEvent
A drawer's handle was pressed, which moved it to its next snap point.
handle-keyKeyboardEvent
Arrow keys, Home or End on a drawer's handle moved it between snap points.
content-resizenone
The content or the screen changed size, and the drawer's snap point or the carousel's page went away, so it moved to the nearest one.

dismissible 可以拒绝的关闭操作:

outside-pressMouseEvent
A press outside the layer.
escape-keyKeyboardEvent
Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
backEvent
Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
swipeTouchEvent | PointerEvent
A swipe gesture: a finger, mouse or pen dragged it.

控制器

用 createDrawerController<Payload, Result>() 创建一个,并把它作为 controller 传给抽屉,以及抽屉之外的任何触发器和 Outlet。

每个写方法都接受可选的 { reason, event },并传给回调。用控制器关闭总是有效,即使抽屉不可关闭,或者有动作正在运行。

isOpen()() => boolean
Whether it's open. False as soon as it starts closing, while it still animates out.
setOpen(open, options?)(open: boolean, options?: PopupChangeOptions<DrawerOpenChangeReason> | undefined) => boolean
Opens or closes it. Returns false when the change was canceled or it was already open or closed.
open(options?)(options?: (PopupChangeOptions<DialogPayloadChangeReason> & { payload?: Payload | undefined; anchor?: Anchor | undefined; signal?: AbortSignal | undefined; }) | undefined) => Promise<...>
Opens it, and resolves once it closes, with why, how and any return value. Resolves exactly once and never rejects: on the next close from any source, when signal aborts, or with reason "unmount" when the component leaves the page.
close(options?)(options?: (PopupChangeOptions<DrawerOpenChangeReason> & { returnValue?: Result | undefined; }) | undefined) => boolean
Closes it. returnValue is passed to the promise open() returned. Returns false when the close was canceled or it was already closed.
toggle(options?)(options?: PopupChangeOptions<DrawerOpenChangeReason> | undefined) => boolean
Opens it when it's closed, and closes it when it's open. Returns false when the change was canceled.
getPayload()() => Payload | undefined
The payload of the last open, from a controller or the trigger that opened it.
focus()() => void
Moves focus to the trigger that opened it last, or the first trigger.
getSnapPoint()() => SnapPoint | null
The snap point it rests on, or null before it first opens.
setSnapPoint(snapPoint, options?)(snapPoint: SnapPoint, options?: ChangeOptions<DrawerSnapPointChangeReason> | undefined) => boolean
Moves it to a snap point. While closed, it opens there next. Returns false when the change was canceled or it was already there.

事件

回调先收到新值,再收到详情。

属性所属收到
onOpenChangeDrawer(open, details): 新状态、原因以及任何 returnValue
onOpenChangeCompleteDrawer(open), 在停稳之后
onPayloadChangeDrawer(payload, details): 内容的新 payload,以及原因
onSnapPointChangeDrawer(snapPoint, details): 新的吸附点和原因
onDismissAttemptDrawer({ reason, event }), 当一次关闭被拒绝时

无障碍

触发器是一个打开对话框的按钮,抽屉在模态时遵循 WAI-ARIA 模态对话框模式:带有 aria-modal,焦点困在内部,页面不可交互,由标题提供名称,由描述说明。Escape 会关闭它。手柄是一个控制抽屉的按钮:按压会移到下一个吸附点,沿抽屉轴线的方向键逐步移动,Home 和 End 移到两端。下面每一行都是一个自动化测试。

键盘

按键作用
Enter, Space在触发器上打开抽屉;在手柄上移到下一个吸附点
Arrow keys along the axis在手柄上移动一个吸附点,不回绕
Home, End在手柄上移到最小或最大的吸附点
Tab, Shift+Tab在面板的控件之间移动,模态时保持在内部
Escape在可关闭时关闭最上层的抽屉

它共享 Dialog 的焦点行为:打开时焦点移入,关闭时返回。触摸打开会把焦点放在内容上,这样字段不会立刻唤出键盘,除非你设置了 initialFocus。屏幕键盘打开时,视口会缩小,聚焦的字段可以在面板内部滚动到可见区域。

经过测试的行为

Dialog
  • The trigger advertises a dialog.
  • The trigger opens a modal dialog named by its title and described by its description.
  • Opening moves focus into the drawer and closing returns it to the trigger.
  • Tab stays inside the drawer.
  • Escape closes it with the escape-key reason.
  • Pressing the backdrop closes it.
  • A Close part closes it.
  • Buttons inside it work without closing it.
  • The page behind is hidden from assistive technology while it's open.
  • Opening and closing never scroll or restyle the page.
  • A controller opens it from outside.
Sheet
  • It rises from the bottom and rests against it at its own size.
  • It opens at the first snap point, a fraction of the screen.
  • A slow drag settles on the nearest snap point and reports the swipe.
  • A drag down past the smallest snap point closes it with the swipe reason.
  • A short fast flick down closes it, though it moved less than half its height.
  • The same distance, slowly, settles back.
  • A fling up from the smallest snap point can pass the middle one.
  • A press while it rises catches it and holds it under the finger.
  • A short drag back up keeps it open.
  • A click on a button inside it isn't a drag.
  • With side="…" it rests against the … edge.
  • With side="left" a drag toward the left closes it.
Touch
  • A touch drag down closes it.
Handle
  • Pressing it moves to the next snap point and wraps.
  • Arrow keys step without wrapping, and Home and End go to the ends.
  • Moving it moves the drawer to the snap point's extent.
  • A snap point a controller sets while it animates closed is where it opens next.
  • A controller moves it with the imperative reason.
Not dismissible
  • Escape reports an attempt and keeps it open.
  • A press on the backdrop reports an attempt and keeps it open.
  • A swipe down resists, springs back and reports an attempt.
Modal above a snap point
  • At that snap point the page stays usable and the drawer isn't modal.
  • Above it the drawer becomes modal, and back down the page is usable again.
  • The switch doesn't move focus.
Nested
  • Escape closes only the drawer on top.

运行于 React、Vue 和 web components。

抽屉在这些屏幕阅读器和布局上经过测试:

  • No axe violations while closed.
  • No axe violations while open.
  • No axe violations while a nested drawer is open.
  • No axe violations while it rests where the page stays usable.
  • The drawer's accessibility tree is a dialog with its handle, title and actions.
  • The handle is a button that controls the drawer.

运行于 React、Vue 和 web components。

  • Side="start" comes from the right in a right-to-left layout.
  • Side="end" comes from the left in a right-to-left layout.
  • Side="…" stays on the … in a right-to-left layout.
  • A drag toward the start edge closes it in a right-to-left layout.
  • Side="top" stays at the top in a right-to-left layout.

运行于 React、Vue 和 web components。

还测试了:

  • Without a touch screen `auto` picks the pointer driver.
Dialog
  • An open modal drawer is marked aria-modal.
  • A keyboard open focuses its first control, and Tab cycles through the controls in order.
  • A controller's open() resolves with how it closed.
  • Focus inside a popup open in its content leaves that popup's scrolling alone.
Shortcuts
  • A trigger connected through a controller shows its shortcut in a Shortcut part, and binds it.
State attributes
  • The content names its side, its snap point and whether it's at the largest.
  • A drawer resting at its own size reports the content snap point and is expanded.
  • Data-dragging is set while a drag moves it.
  • A drawer opened from inside another marks both, and the one beneath reads its depth from --drawer-stack.
Physics
  • Past the largest snap point it stretches less than 24px and springs back.
Touch
  • Pulling down on scrolled content scrolls it to the top, then moves the drawer in the same gesture.
  • Pushing up on content below the largest snap point grows the drawer before the content scrolls.
Compositor
  • A settle runs as a spring sampled into linear(), on translate and the backdrop's opacity.
  • While a finger drives it, the drawer writes no attributes, only styles.
  • Its variables are registered and don't inherit, so moving it restyles only the drawer.
  • With reduced motion it fades in and out instead of sliding.
Page
  • An outlet outside the drawer follows it, and goes back when it closes.
  • The theme color dims while it's open and comes back when it closes.
  • Content that grows moves its content snap point, and the drawer follows.
  • Escape on a drawer that can't be dismissed nudges it toward closing.
Scroll-snap driver
  • On a touch screen it's the driver `auto` picks.
  • On a touch screen `auto` keeps the pointer driver with …=….
  • It opens at its first snap point with the browser's scrolling.
  • A swipe up snaps to the next snap point and reports the swipe.
  • A swipe up from the handle snaps to the next snap point.
  • It comes to rest when the scroll ends before the page hears the finger lift.
  • A swipe down closes it once it leaves the screen.
  • The handle moves it with a spring, like the pointer driver.

运行于 React、Vue 和 web components。