fix: address DatePicker review findings

This commit is contained in:
maoyingjie
2026-10-26 22:14:35 +08:00
parent 3341c86e4d
commit 9ef833319d
9 changed files with 382 additions and 21 deletions
@@ -1,6 +1,10 @@
<script setup lang="ts">
import { computed, ref, useAttrs, watch } from "vue";
import { PopoverAnchor, useForwardExpose } from "reka-ui";
import {
injectPopoverRootContext,
PopoverAnchor,
useForwardExpose,
} from "reka-ui";
import { datePickerVariants } from "@heroui-vue/styles";
import OverlayAction from "../overlay/OverlayAction";
import { usePopover } from "../popover/context";
@@ -12,16 +16,20 @@ const props = withDefaults(
);
const popover = usePopover();
const picker = useDatePicker();
const root = injectPopoverRootContext();
const attrs = useAttrs();
const { forwardRef, currentElement } = useForwardExpose();
const focusVisible = ref(false);
const triggerId = computed(
() => (attrs.id as string | undefined) ?? popover.triggerId,
);
const disabled = computed(
() => props.isDisabled || picker.disabled.value || picker.readOnly.value,
);
const defaultLabelledBy = computed(() => {
if (attrs["aria-label"] || attrs["aria-labelledby"]) return undefined;
const ids = [popover.triggerId, picker.labelledBy()].filter(Boolean);
return ids.length ? ids.join(" ") : undefined;
const label = picker.labelledBy();
return label ? [triggerId.value, label].join(" ") : undefined;
});
const defaultLabel = computed(() => {
if (attrs["aria-label"] || attrs["aria-labelledby"]) return undefined;
@@ -34,15 +42,21 @@ watch(
currentElement,
(element) => {
picker.trigger.value = element;
root.triggerElement.value = element;
root.triggerId = triggerId.value;
},
{ immediate: true },
);
watch(triggerId, (id) => {
root.triggerId = id;
});
</script>
<template>
<PopoverAnchor as-child>
<OverlayAction
:ref="forwardRef"
v-bind="$attrs"
:id="triggerId"
:as="as"
:as-child="asChild"
:is-disabled="disabled"