fix(dropdown): preserve grouped root attrs and events without breaking seams
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ButtonGroup,
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const cancel = ref(true);
|
||||
const hidden = ref(false);
|
||||
const counts = reactive({ click: 0, pointerdown: 0, keydown: 0 });
|
||||
const cases = [
|
||||
{ orientation: "horizontal" as const, dir: "ltr" as const },
|
||||
{ orientation: "horizontal" as const, dir: "rtl" as const },
|
||||
{ orientation: "vertical" as const, dir: "ltr" as const },
|
||||
];
|
||||
const positions = ["first", "middle", "last"];
|
||||
function capture(event: Event) {
|
||||
counts[event.type as keyof typeof counts]++;
|
||||
if (cancel.value) event.preventDefault();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="p-6 space-y-6">
|
||||
<h1>ButtonGroup / Dropdown 根属性与接缝</h1>
|
||||
<label>
|
||||
<input v-model="cancel" type="checkbox" />
|
||||
取消打开
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="hidden" type="checkbox" />
|
||||
隐藏根容器
|
||||
</label>
|
||||
<output aria-label="捕获事件次数">{{ JSON.stringify(counts) }}</output>
|
||||
<section v-for="item in cases" :key="item.orientation + item.dir">
|
||||
<h2>{{ item.orientation }} / {{ item.dir }}</h2>
|
||||
<ButtonGroup
|
||||
:orientation="item.orientation"
|
||||
:dir="item.dir"
|
||||
:data-case="item.orientation + '-' + item.dir"
|
||||
>
|
||||
<DropdownRoot
|
||||
v-for="position in positions"
|
||||
:id="item.orientation + '-' + item.dir + '-' + position"
|
||||
:key="position"
|
||||
class="consumer-root"
|
||||
:data-position="position"
|
||||
:style="{
|
||||
display: hidden ? 'none' : 'flex',
|
||||
'--consumer-marker': 'kept',
|
||||
}"
|
||||
:aria-label="position + '菜单容器'"
|
||||
@click.capture="capture"
|
||||
@pointerdown.capture="capture"
|
||||
@keydown.capture="capture"
|
||||
>
|
||||
<DropdownTrigger>
|
||||
<Button variant="outline">{{ position }}</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownPopover>
|
||||
<DropdownMenu>
|
||||
<DropdownItem id="action">执行操作</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</DropdownPopover>
|
||||
</DropdownRoot>
|
||||
</ButtonGroup>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
Reference in New Issue
Block a user