feat: migrate Select with field, collection and SSR contracts
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
import { mergeProps, useAttrs } from "vue";
|
||||
import PopoverContent from "../popover/PopoverContent.vue";
|
||||
import { useSelect } from "./context";
|
||||
import type { OverlayPlacement } from "../overlay/placement";
|
||||
defineOptions({ name: "SelectPopover", inheritAttrs: false });
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
placement?: OverlayPlacement;
|
||||
offset?: number;
|
||||
to?: string | HTMLElement;
|
||||
shouldFlip?: boolean;
|
||||
containerPadding?: number;
|
||||
}>(),
|
||||
{ placement: "bottom", offset: 8, shouldFlip: true, containerPadding: 12 },
|
||||
);
|
||||
const ctx = useSelect(),
|
||||
attrs = useAttrs();
|
||||
function openFocus(event: Event) {
|
||||
if (!event.defaultPrevented) {
|
||||
event.preventDefault();
|
||||
void ctx.focusCollection();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<PopoverContent
|
||||
:placement="placement"
|
||||
:offset="offset"
|
||||
:to="to"
|
||||
:should-flip="shouldFlip"
|
||||
:container-padding="containerPadding"
|
||||
v-bind="mergeProps(attrs, { onOpenAutoFocus: openFocus })"
|
||||
:id="`${ctx.listId}-popover`"
|
||||
role="presentation"
|
||||
:class="[ctx.slots.value.popover(), attrs.class]"
|
||||
data-slot="select-popover"
|
||||
:aria-labelledby="
|
||||
ctx.field.labelledBy() ??
|
||||
ctx.trigger.value?.id ??
|
||||
ctx.field.field.controlId.value
|
||||
"
|
||||
:style="{
|
||||
'--trigger-width': 'var(--reka-popover-trigger-width)',
|
||||
'--trigger-anchor-point': 'var(--reka-popper-transform-origin)',
|
||||
}"
|
||||
>
|
||||
<slot />
|
||||
</PopoverContent>
|
||||
</template>
|
||||
Reference in New Issue
Block a user