# 底部弹窗

## 使用方法

`BottomSheet` 从视口底部升起一块面板，用来承载筛选、分享、快速操作和表单这类移动端优先的内容。面板顶部有一条装饰性的拖拽条，下面是可以滚动的内容区；背景由遮罩压暗并阻挡交互。它基于原生 `<dialog>` 元素，因此在打开时会把焦点锁在面板内部、把页面其余部分设为不可交互，关闭后把焦点还给打开它的元素。

最基本的用法是自己管理开关状态，把标签和内容交给组件：

```vue
<script setup lang="ts">
import { BottomSheet } from '@astryx-vue/core/BottomSheet'
import { ref } from 'vue'

const isOpen = ref(false)
</script>

<template>
  <button type="button" @click="isOpen = true">
    筛选
  </button>
  <BottomSheet v-model:is-open="isOpen" label="筛选">
    <p>这里放筛选条件。</p>
  </BottomSheet>
</template>
```

`label` 是必填项，它会成为面板的无障碍名称，屏幕阅读器在进入面板时会读出它。面板本身没有内置标题，所以这个名称需要由你提供。是否打开由 `isOpen` 决定：不绑定 `v-model:is-open` 时组件自己管理状态，Escape、点击遮罩或向下拖动都会关闭它；绑定时组件完全跟随绑定的值，这些操作只会发出 `openChange(false)` 请求，是否关闭由父组件决定。

`height` 决定面板展开后的高度，可以使用三个命名档位。`hug` 让面板贴合内容，最多占到视口的 92%，适合内容固定且不长的场景；`capped` 是默认档，约占视口高度的 62%，是列表类内容的常用选择；`tall` 固定在接近满屏的高度，适合表单或内容会持续变长的场景。也可以直接传数字（像素）或任意 CSS 长度，例如 `420` 或 `"min(70vh, 30rem)"`。无论哪个档位，内容超过可见高度时都在面板内部滚动，不会把页面撑长。

`snapPoints` 让用户可以拖动面板停在中间高度，而不仅仅是全开或关闭。每个点位写的是面板的可见高度：数字是视口比例（`0.5` 就是半个屏幕），`"50%"` 是同样的意思，`"320px"` 是绝对高度。面板自身的高度始终是最高的那一档，所以 `snap-points="[0.5]"` 表示「要么半屏，要么全屏」。短到只有自身四分之一以下的档位被视为「露一角」：它不重排内容，而是把整块面板滑走一部分，同时把遮罩调淡。不传 `snapPoints` 时面板只支持打开和关闭，拖动仍可以关闭它。

向下拖动可以关闭面板，向上快速一甩会把面板展开到最高档。拖动时遮罩的深浅跟随面板的位置变化，松手后停到最近的档位。拖动条和（滚动到顶部后的）内容区都可以发起拖动。系统开启「减少动态效果」时，进入和退出的动画会缩短到几乎不可见，但面板的位置和状态变化照常发生。

`purpose` 控制隐式关闭的尺度，和 `Dialog` 一致。默认的 `info` 允许 Escape、点击遮罩和向下拖动；`form` 只允许 Escape，避免用户误触遮罩丢失已经输入的内容；`required` 屏蔽全部隐式关闭，并使用 `alertdialog` 语义，用于必须由用户明确响应的流程。想要面板和页面同时可交互时，把 `hasScrim` 设为 `false`：面板会用非模态方式打开，背景不再被压暗，页面可以继续滚动和点击，拖动关闭依旧可用。非模态面板不会把焦点从页面上抢走，因此 Escape 只在焦点位于面板内部时才会关闭它。

`padding` 设置内容区的内边距，取值来自全局间距刻度。不设置时使用主题为底部弹窗定义的内边距，主题没有定义时取 `--spacing-4`（16px），四个逻辑边相同；传入 `0` 可以让内容紧贴面板边缘。内容区会把实际用上的边距发布给里面的内容：唯一子元素如果是自带内边距的区块，会顶掉这层边距；表格和分隔线会伸到这条边上，不会再缩一圈。

### 结构

- **面板**: 从底边升起、装着内容的着色表面。
- **内容区**: 有内边距、可滚动，用来放使用方提供的面板内容。
- **把手**: 面板顶部的装饰性拖动手柄，也是拖动区域。
- **遮罩**: 带遮罩的呈现方式里，压暗并挡住页面的背景。

## 最佳实践

| 指引 | 实践 |
| --- | --- |
| 推荐 | 用在小屏上的临时任务：筛选、分享、快速操作、详情预览。让内容从底部升起，符合拇指的触达范围。 |
| 推荐 | 按内容选择高度档位：内容固定且短用 `hug`，列表用 `capped`，表单或持续变长的内容用 `tall`。 |
| 推荐 | 用 `purpose="form"` 保护已经输入的内容，同时保留 Escape；只有必须由用户明确结束的流程才用 `required`。 |
| 推荐 | 给 `label` 写清楚面板是什么，例如「筛选条件」「分享到」，它是屏幕阅读器进入面板时唯一的上下文。 |
| 避免 | 让面板内容过长。内容很多时考虑拆成多个步骤，或改用整页。 |
| 避免 | 在桌面端把它当默认的弹窗使用。需要居中的模态对话框时使用 `Dialog`。 |
| 避免 | 依赖拖动作为唯一的关闭方式。Escape、遮罩点击和显式的操作按钮同样重要。 |

## 示例

### 高度

对比 hug、capped、tall 三种起始高度，分别适合不同体量的内容。

```vue
<script setup lang="ts">
import type { BottomSheetHeight } from '@astryx-vue/core/BottomSheet'
import { BottomSheet } from '@astryx-vue/core/BottomSheet'
import { Button } from '@astryx-vue/core/Button'
import { Divider } from '@astryx-vue/core/Divider'
import { Heading } from '@astryx-vue/core/Heading'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { ref } from 'vue'

const descriptions: Record<BottomSheetHeight, string> = {
  hug: 'Hug fits short, bounded content.',
  capped: 'Capped starts at a comfortable mid-height for lists and filters.',
  tall: 'Tall reserves most of the viewport for long or changing content.',
}

const height = ref<BottomSheetHeight | null>(null)
</script>

<template>
  <HStack :gap="2" wrap="wrap">
    <Button label="Open hug" @click="height = 'hug'" />
    <Button label="Open capped" @click="height = 'capped'" />
    <Button label="Open tall" @click="height = 'tall'" />
  </HStack>
  <BottomSheet
    :height="height ?? 'hug'"
    :is-open="height != null"
    :label="`${height ?? 'Hug'} height`"
    @update:is-open="open => { if (!open) height = null }"
  >
    <VStack :gap="4">
      <Heading :level="3">
        {{ height ?? 'Hug' }} height
      </Heading>
      <Divider />
      <Text type="body">
        {{ descriptions[height ?? 'hug'] }}
      </Text>
      <Button label="Close" @click="height = null" />
    </VStack>
  </BottomSheet>
</template>
```

### 移动端键盘

接近全屏的可滚动表单，聚焦时控件仍留在移动端键盘上方。

```vue
<script setup lang="ts">
import { BottomSheet } from '@astryx-vue/core/BottomSheet'
import { Button } from '@astryx-vue/core/Button'
import { Divider } from '@astryx-vue/core/Divider'
import { Heading } from '@astryx-vue/core/Heading'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { TextArea } from '@astryx-vue/core/TextArea'
import { TextInput } from '@astryx-vue/core/TextInput'
import { reactive, ref } from 'vue'

const isOpen = ref(false)
const values = reactive({
  name: '',
  email: '',
  company: '',
  role: '',
  bio: '',
  notes: '',
})

function onSubmit(): void {
  isOpen.value = false
}
</script>

<template>
  <Button label="Edit profile" @click="isOpen = true" />
  <BottomSheet
    v-model:is-open="isOpen"
    height="tall"
    label="Edit profile"
  >
    <form @submit.prevent="onSubmit">
      <VStack :gap="4">
        <Heading :level="3">
          Edit profile
        </Heading>
        <Divider />
        <Text type="supporting" color="secondary">
          Focus fields throughout the form to see them remain visible above the mobile keyboard.
        </Text>
        <TextInput v-model="values.name" label="Name" />
        <TextInput v-model="values.email" label="Email" type="email" />
        <TextInput v-model="values.company" label="Company" />
        <TextInput v-model="values.role" label="Role" />
        <TextArea v-model="values.bio" label="Bio" :rows="5" />
        <TextArea v-model="values.notes" label="Notes" :rows="5" />
        <Button label="Save profile" type="submit" />
      </VStack>
    </form>
  </BottomSheet>
</template>
```

### 无遮罩

非模态面板不盖住页面，背后的内容仍然可以看见，也可以点。

```vue
<script setup lang="ts">
import { BottomSheet } from '@astryx-vue/core/BottomSheet'
import { Button } from '@astryx-vue/core/Button'
import { Divider } from '@astryx-vue/core/Divider'
import { Heading } from '@astryx-vue/core/Heading'
import { Section } from '@astryx-vue/core/Section'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { ref } from 'vue'

const isOpen = ref(false)
const backgroundClicks = ref(0)
</script>

<template>
  <Section :padding="4">
    <VStack :gap="3">
      <Heading :level="3">
        Nearby places
      </Heading>
      <Text type="body">
        Background interactions: {{ backgroundClicks }}
      </Text>
      <Button label="Interact with page" variant="secondary" @click="backgroundClicks += 1" />
      <Button label="Show place details" @click="isOpen = true" />
    </VStack>
    <BottomSheet
      v-model:is-open="isOpen"
      :has-scrim="false"
      height="hug"
      label="Place details"
    >
      <VStack :gap="4">
        <Heading :level="3">
          Central Park
        </Heading>
        <Divider />
        <Text type="body">
          The page remains visible and interactive behind this sheet.
        </Text>
        <Button label="Close details" @click="isOpen = false" />
      </VStack>
    </BottomSheet>
  </Section>
</template>
```

### 停靠点

拖动时可以停在半屏，也可以停在一条细缝上；细缝会把面板滑出，并减弱遮罩。

```vue
<script setup lang="ts">
import { BottomSheet } from '@astryx-vue/core/BottomSheet'
import { Button } from '@astryx-vue/core/Button'
import { Divider } from '@astryx-vue/core/Divider'
import { Heading } from '@astryx-vue/core/Heading'
import { Icon } from '@astryx-vue/core/Icon'
import { Item } from '@astryx-vue/core/List'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { ref } from 'vue'

const snapPoints = ['96px', '50%']
const isOpen = ref(false)

const steps = [
  { icon: 'pin', label: 'Head northeast on Mission St', detail: 'Toward 3rd St', distance: '350 ft' },
  { icon: 'right', label: 'Turn right onto 3rd St', detail: 'Pass Yerba Buena Gardens on your left', distance: '0.2 mi' },
  { icon: 'up', label: 'Continue onto Kearny St', detail: 'Stay in the right lane', distance: '0.4 mi' },
  { icon: 'left', label: 'Turn left onto Market St', detail: 'Cable car crossing ahead', distance: '0.6 mi' },
  { icon: 'right', label: 'Bear right onto Sutter St', detail: 'Toward the Financial District', distance: '0.3 mi' },
  { icon: 'up', label: 'Continue on Sansome St', detail: 'Four blocks, past Pine St', distance: '0.5 mi' },
  { icon: 'uturn', label: 'Make a U-turn at Washington St', detail: 'Construction detour until March', distance: '150 ft' },
  { icon: 'right', label: 'Turn right onto Battery St', detail: 'Follow signs for the Embarcadero', distance: '0.4 mi' },
  { icon: 'left', label: 'Turn left onto Sacramento St', detail: 'Toward the waterfront', distance: '0.2 mi' },
  { icon: 'right', label: 'Turn right onto The Embarcadero', detail: 'Bay Bridge on your right', distance: '0.5 mi' },
  { icon: 'up', label: 'Continue past Pier 14', detail: 'Ferry terminal signage begins here', distance: '0.3 mi' },
  { icon: 'flag', label: 'Arrive at the Ferry Building', detail: 'Parking garage entrance on Washington St', distance: '—' },
]
</script>

<template>
  <VStack align="start" :gap="3">
    <Text type="body">
      This sheet has two extra stops: half the viewport, and a 96px peek. Drag the handle down to collapse it, then back up — it rests at each stop instead of following your finger.
    </Text>
    <Button label="Show directions" @click="isOpen = true" />
  </VStack>
  <BottomSheet
    v-model:is-open="isOpen"
    height="tall"
    label="Directions to the Ferry Building"
    :snap-points="snapPoints"
  >
    <VStack :gap="4">
      <VStack :gap="1">
        <Heading :level="3">
          Ferry Building
        </Heading>
        <HStack :gap="2">
          <Text type="label">
            18 min
          </Text>
          <Text type="supporting">
            3.7 mi · arrive 9:41 AM
          </Text>
        </HStack>
      </VStack>
      <Divider />
      <VStack :gap="0">
        <Item
          v-for="step in steps"
          :key="step.label"
          :description="step.detail"
          :label="step.label"
        >
          <template #startContent>
            <Icon size="sm">
              <svg v-if="step.icon === 'pin'" fill="none" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" width="16">
                <path d="M12 21s7-6.2 7-11a7 7 0 1 0-14 0c0 4.8 7 11 7 11Z" stroke-linecap="round" stroke-linejoin="round" />
                <circle cx="12" cy="10" r="2.25" />
              </svg>
              <svg v-else-if="step.icon === 'right'" fill="none" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" width="16">
                <path d="M4 12h16M14 6l6 6-6 6" stroke-linecap="round" stroke-linejoin="round" />
              </svg>
              <svg v-else-if="step.icon === 'left'" fill="none" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" width="16">
                <path d="M20 12H4M10 6l-6 6 6 6" stroke-linecap="round" stroke-linejoin="round" />
              </svg>
              <svg v-else-if="step.icon === 'up'" fill="none" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" width="16">
                <path d="M12 20V4M6 10l6-6 6 6" stroke-linecap="round" stroke-linejoin="round" />
              </svg>
              <svg v-else-if="step.icon === 'uturn'" fill="none" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" width="16">
                <path d="M9 14 4 9l5-5" stroke-linecap="round" stroke-linejoin="round" />
                <path d="M4 9h9a6 6 0 0 1 0 12H8" stroke-linecap="round" stroke-linejoin="round" />
              </svg>
              <svg v-else fill="none" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" width="16">
                <path d="M5 21V4h9l-1.5 4.5L14 13H5" stroke-linecap="round" stroke-linejoin="round" />
              </svg>
            </Icon>
          </template>
          <template #endContent>
            <Text type="supporting">
              {{ step.distance }}
            </Text>
          </template>
        </Item>
      </VStack>
      <Divider />
      <Button label="Start" variant="primary" @click="isOpen = false" />
    </VStack>
  </BottomSheet>
</template>
```

### 自适应对话框

默认仍是对话框。粗指针且宽度在 lg 及以下时，同一份资料表单改为底部面板。

```vue
<script setup lang="ts">
import type { BottomSheetHeight, BottomSheetPurpose } from '@astryx-vue/core/BottomSheet'
import type { DialogPurpose } from '@astryx-vue/core/Dialog'
import { useMediaQuery } from '@astryx-vue/core'
import { BottomSheet } from '@astryx-vue/core/BottomSheet'
import { Button } from '@astryx-vue/core/Button'
import { Dialog, DialogHeader } from '@astryx-vue/core/Dialog'
import { Heading } from '@astryx-vue/core/Heading'
import { Layout, LayoutContent, LayoutFooter } from '@astryx-vue/core/Layout'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { TextArea } from '@astryx-vue/core/TextArea'
import { TextInput } from '@astryx-vue/core/TextInput'
import { ref } from 'vue'

const TOUCH_ORIENTED_LG_QUERY = '(max-width: 1024px) and (pointer: coarse) and (hover: none)'

type AdaptivePresentation = 'dialog' | 'fullscreen' | 'bottom-sheet'

const isOpen = ref(false)
const name = ref('Ruby Cheung')
const email = ref('ruby@example.com')
const notes = ref('')
const isTouchOriented = useMediaQuery(TOUCH_ORIENTED_LG_QUERY)

const purpose: DialogPurpose = 'form'
const touchPresentation: AdaptivePresentation = 'bottom-sheet'
const bottomSheetHeight: BottomSheetHeight = 'tall'

function resolvedPresentation(): AdaptivePresentation {
  return isTouchOriented.value ? touchPresentation : 'dialog'
}
</script>

<template>
  <Button label="Edit profile" @click="isOpen = true" />
  <BottomSheet
    v-if="resolvedPresentation() === 'bottom-sheet'"
    v-model:is-open="isOpen"
    :height="bottomSheetHeight"
    label="Edit profile"
    :purpose="purpose as BottomSheetPurpose"
  >
    <VStack :gap="4">
      <Heading :level="3">
        Edit profile
      </Heading>
      <Text type="supporting" color="secondary">
        Dialog remains the default presentation. This example explicitly opts into a Bottom Sheet only at lg and below when the device has a coarse pointer and no hover. Pass the presentation prop to make tests or unusual environments deterministic.
      </Text>
      <Text type="supporting" color="secondary">
        In Bottom Sheet presentation, purpose="form" blocks scrim clicks and swipe dismissal while preserving Escape. Use this opt-in only when that contract is acceptable; keep AlertDialog/destructive confirmations on Dialog unless a product deliberately chooses otherwise.
      </Text>
      <TextInput v-model="name" label="Name" />
      <TextInput v-model="email" label="Email" type="email" />
      <TextArea v-model="notes" label="Notes" :rows="6" />
      <HStack :gap="2" h-align="end" wrap="wrap">
        <Button label="Cancel" variant="secondary" @click="isOpen = false" />
        <Button label="Save profile" variant="primary" @click="isOpen = false" />
      </HStack>
    </VStack>
  </BottomSheet>
  <Dialog
    v-else
    :is-open="isOpen"
    max-height="75dvh"
    :purpose="purpose"
    :variant="resolvedPresentation() === 'fullscreen' ? 'fullscreen' : 'standard'"
    :width="480"
    @open-change="isOpen = $event"
  >
    <Layout>
      <template #header>
        <DialogHeader title="Edit profile" @open-change="isOpen = $event" />
      </template>
      <LayoutContent>
        <VStack :gap="4">
          <Text type="supporting" color="secondary">
            Dialog remains the default presentation. This example explicitly opts into a Bottom Sheet only at lg and below when the device has a coarse pointer and no hover. Pass the presentation prop to make tests or unusual environments deterministic.
          </Text>
          <Text type="supporting" color="secondary">
            In Bottom Sheet presentation, purpose="form" blocks scrim clicks and swipe dismissal while preserving Escape. Use this opt-in only when that contract is acceptable; keep AlertDialog/destructive confirmations on Dialog unless a product deliberately chooses otherwise.
          </Text>
          <TextInput v-model="name" label="Name" />
          <TextInput v-model="email" label="Email" type="email" />
          <TextArea v-model="notes" label="Notes" :rows="6" />
        </VStack>
      </LayoutContent>
      <template #footer>
        <LayoutFooter>
          <HStack :gap="2" h-align="end" wrap="wrap">
            <Button label="Cancel" variant="secondary" @click="isOpen = false" />
            <Button label="Save profile" variant="primary" @click="isOpen = false" />
          </HStack>
        </LayoutFooter>
      </template>
    </Layout>
  </Dialog>
</template>
```

### 自适应菜单

紧凑的触屏上用底部面板，其余情况用锚在按钮上的菜单。

```vue
<script setup lang="ts">
import { useMediaQuery } from '@astryx-vue/core'
import { DropdownMenu } from '@astryx-vue/core/DropdownMenu'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { computed, ref } from 'vue'

const COMPACT_TOUCH_QUERY = '(max-width: 639px) and (pointer: coarse) and (hover: none)'
const isCompactTouch = useMediaQuery(COMPACT_TOUCH_QUERY)
const lastAction = ref<string | null>(null)

const items = computed(() => [
  'Edit project',
  'Duplicate project',
  'Share project',
  'Archive project',
].map(label => ({
  label,
  onClick: () => {
    lastAction.value = label
  },
})))
</script>

<template>
  <VStack :gap="3">
    <DropdownMenu
      :button="{ label: 'Project actions' }"
      :items="items"
      :presentation="isCompactTouch ? 'bottom-sheet' : 'popover'"
    />
    <Text v-if="lastAction" type="supporting" color="secondary">
      Last action: {{ lastAction }}
    </Text>
  </VStack>
</template>
```

### 多选面板

多选列表在底部面板里保持打开，勾选时不会收起。

```vue
<script setup lang="ts">
import { MultiSelector } from '@astryx-vue/core/MultiSelector'
import { ref } from 'vue'

const value = ref<string[]>([])
const options = ['Design', 'Engineering', 'Marketing', 'Operations']
</script>

<template>
  <div class="bottom-sheet-field">
    <MultiSelector
      v-model="value"
      label="Teams"
      :options="options"
      placeholder="Choose teams"
      presentation="bottom-sheet"
      select-all
    />
  </div>
</template>

<style scoped>
.bottom-sheet-field {
  width: 320px;
  max-width: 100%;
}
</style>
```

### 单选面板

单选列表在底部面板里打开。

```vue
<script setup lang="ts">
import { Selector } from '@astryx-vue/core/Selector'
import { ref } from 'vue'

const value = ref<string | null>(null)
const options = [
  { value: 'design', label: 'Design' },
  { value: 'engineering', label: 'Engineering' },
  { value: 'marketing', label: 'Marketing' },
  { value: 'operations', label: 'Operations' },
]
</script>

<template>
  <div class="bottom-sheet-field">
    <Selector
      v-model="value"
      label="Team"
      :options="options"
      placeholder="Choose a team"
      presentation="bottom-sheet"
    />
  </div>
</template>

<style scoped>
.bottom-sheet-field {
  width: 320px;
  max-width: 100%;
}
</style>
```

### 多步切换

结账分成两张底栏，共用一个对话框。换页时遮罩不闪。

```vue
<script setup lang="ts">
import { BottomSheet, BottomSheetSwitcher } from '@astryx-vue/core/BottomSheet'
import { Button } from '@astryx-vue/core/Button'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { ref } from 'vue'

const activeSheet = ref<string | null>(null)
</script>

<template>
  <Button label="Start checkout" @click="activeSheet = 'details'" />
  <BottomSheetSwitcher v-model:active-sheet="activeSheet" label="Checkout">
    <BottomSheet sheet-id="details" label="Details">
      <VStack :gap="3">
        <Text type="body">
          Confirm the order, then continue to payment.
        </Text>
        <Button label="Continue" @click="activeSheet = 'pay'" />
      </VStack>
    </BottomSheet>
    <BottomSheet sheet-id="pay" label="Payment">
      <VStack :gap="3">
        <Text type="body">
          Payment details stay in the same sheet.
        </Text>
        <Button label="Back" variant="secondary" @click="activeSheet = 'details'" />
        <Button label="Done" @click="activeSheet = null" />
      </VStack>
    </BottomSheet>
  </BottomSheetSwitcher>
</template>
```

## 无障碍

面板基于原生 `<dialog>` 元素构建。带遮罩时使用 `showModal()` 打开，浏览器会把它放到顶层、把背景设为不可交互，并把 Tab 焦点限制在面板内；不带遮罩时使用 `show()` 打开，页面保持可用。`label` 通过 `aria-label` 成为面板的名称，`purpose="required"` 时角色变为 `alertdialog`。

打开时，焦点会落到面板内第一个带 `data-autofocus` 的元素上；没有这样的元素时，焦点落在面板本身。关闭后，焦点回到打开面板时的那个元素（如果它还在页面里），或者回到 `finalFocusRef` 指定的元素。抬起与关闭的动画结束后才执行焦点归还，避免焦点落在正在滑走的面板上。

Escape 只在 `purpose` 不是 `required` 时关闭面板（带遮罩的模态面板会把焦点限制在内部；无遮罩的面板不抢焦点，因此焦点需要位于面板内）；输入法正在组合文字时按下的 Escape 属于取消输入，不会关闭面板。内容区滚动到顶部后可以向下拖动关闭面板，滚动到内容底部时可以向上拖动展开面板；`purpose` 不是 `info` 时拖动只会停靠在最近的档位，不会关闭。

当内容区实际溢出时，它会成为一个可聚焦的滚动区域，带 `role="group"` 和面板的 `label` 作为名称，键盘用户可以聚焦它并用方向键滚动内容。

## 主题

```css
.my-sheet {
  --astryx-bottom-sheet-background: #ffffff;
  --astryx-bottom-sheet-foreground: #171717;
  --astryx-bottom-sheet-border: #d4d4d4;
  --astryx-bottom-sheet-handle-background: #d4d4d4;
  --astryx-bottom-sheet-scrim: #00000080;
  --astryx-bottom-sheet-shadow: 0 -12px 24px rgb(0 0 0 / 15%);
}
```

Neutral 主题自动适配明暗模式。`class` 与 `style` 会落在面板这个 `<div>` 上，而不是包裹它的 `<dialog>`，因此上面的变量写在面板上生效。

## Props

| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `label` | `string` | - | 面板的无障碍名称，必填。它通过 `aria-label` 与面板关联；面板没有内置标题可以自动取名。 |
| `v-model:isOpen` | `boolean` | `false` | 受控的打开状态。绑定后组件完全跟随这个值，Escape、遮罩点击和拖动只发出更新请求；不绑定时组件自己管理状态。 |
| `height` | `BottomSheetHeight \| number \| string` | `'capped'` | 面板的高度。命名档位 hug（贴合内容，最多 92%）、capped（约 62%）、tall（约 92%）；数字按像素解释，字符串按 CSS 长度原样使用。内容超出可见高度时在面板内部滚动。 |
| `snapPoints` | `readonly BottomSheetSnapPoint[]` | - | 拖动时可以停靠的额外高度。数字是视口比例，`'50%'` 是百分比，`'320px'` 是绝对高度；面板自身高度始终是最高的档位。不传时面板只能打开和关闭。 |
| `padding` | `BottomSheetPadding` | - | 内容区的内边距，取值来自间距刻度。不设置时使用主题为底部弹窗定义的内边距，主题没有定义时取 `--spacing-4`（16px），四个逻辑边相同；传入 `0` 可以让内容紧贴面板边缘。内容区是容器，唯一子元素是自带内边距的区块时该区块会顶掉这层内边距。 |
| `purpose` | `BottomSheetPurpose` | `'info'` | 隐式关闭的尺度，与 `Dialog` 一致。info 允许 Escape、遮罩点击和拖动关闭；form 只允许 Escape；required 屏蔽全部隐式关闭并使用 `alertdialog` 语义。 |
| `hasScrim` | `boolean` | `true` | 是否渲染遮罩并以模态方式打开。为 `true` 时使用 `showModal()`：顶层显示、焦点限制、锁定页面滚动、背景不可交互。为 `false` 时使用 `show()`，页面保持可交互和可滚动。 |
| `finalFocusRef` | `HTMLElement \| null` | `null` | 关闭后接收焦点的元素，用来替换打开时的那个元素。适用于触发器会被重新创建、或打开时的焦点元素不可靠的场景。 |
| `isInline` | `boolean` | `false` | 把面板渲染在普通文档流里，不使用 `<dialog>`、遮罩、焦点限制和动画。用于在已经是 inert 的容器中预览面板本身，例如组件文档。 |

## 插槽

| 名称 | 说明 |
| --- | --- |
| `default` | 面板的内容，渲染在拖动条下方的滚动区域里。 |

## 事件与模板引用

| 名称 | 签名 | 说明 |
| --- | --- | --- |
| `openChange` | `(isOpen: boolean) => void` | 面板请求切换状态时触发：Escape、遮罩点击、拖动关闭，或 `v-model:isOpen` 的写入。 |
| `update:isOpen` | `(isOpen: boolean) => void` | 由 `v-model:isOpen` 自动监听，一般不需要手动处理。 |
| `motionStart` | `(motion: 'entering' \| 'exiting') => void` | 进入或退出动画开始时触发。 |
| `motionComplete` | `(motion: 'entering' \| 'exiting') => void` | 进入或退出动画结束时触发。退出动画完成后才会关闭 `<dialog>` 并把焦点还回去。 |
| `snap` | `(visibleHeight: number) => void` | 拖动停靠到某个档位时触发，参数是面板此刻的可见高度（像素）。 |
| `element` | `HTMLDivElement \| null` | 面板元素，通过模板引用暴露；`class` 与 `style` 会落在这个元素上。 |
| `focus()` / `blur()` | `() => void` | 把焦点移入或移出面板。 |

## BottomSheetSwitcher

多步流程共用一个对话框。当前页用 `v-model:active-sheet` 指向子级 `BottomSheet` 的 `sheetId`。换页时遮罩留着，上一张会短暂留在下面并对齐高度。关掉时把 `activeSheet` 设为 `null`。

| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `activeSheet` | `string \| null` | `null` | 当前那一张的 `sheetId`。用 `v-model:active-sheet` 绑定。 |
| `label` | `string` | 当前底栏的 `label` | 整段流程的无障碍名。 |
| `purpose` | `BottomSheetPurpose` | 当前底栏的 `purpose` | 整段流程怎么被关掉。 |
| `hasScrim` | `boolean` | `true` | 是否给整段流程一块遮罩。换页时遮罩留着。 |

- `cancel(event: Event)`：切换器处理原生 dialog 的取消请求（例如 Escape）之前触发。调用 `event.preventDefault()` 可以留住这段流程。

子级 `BottomSheet` 加上 `sheetId` 后不再自己打开对话框，由切换器决定哪一张可见。

## 原生属性

根元素是面板的 `<div>`（类名 <code>astryx-bottom-sheet</code>），它被包裹在一个固定的 <code>&lt;dialog&gt;</code> 里。

以下内容传入面板元素：

- HTML 属性。
- `aria-*` 属性（<code>aria-label</code> 与 <code>aria-labelledby</code> 例外，它们用于命名外层的对话框）。
- `data-*` 属性。
- `class`。
- `style`。
