Skip to content

Commit

Permalink
fix(vue): presence of componets with Positioner (#2799)
Browse files Browse the repository at this point in the history
* fix(vue): dialog presence

* fix(vue): tooltip presence

* fix(vue): color-picker presence

* fix(vue): date-picker presence

* fix(vue): combobox presence

* fix(vue): hover-card presence

* fix(vue): menu presence

* fix(vue): popover presence

* fix(vue): select presence

* fix(vue): time-picker presence

* fix(vue): presence fix mistakes

* fix(vue): dialog and tooltip tests waiting
  • Loading branch information
YaredFall authored Aug 27, 2024
1 parent 3ed7ad6 commit 71be482
Show file tree
Hide file tree
Showing 22 changed files with 211 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { mergeProps } from '@zag-js/vue'
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory'
import type { PresenceProps } from '../presence'
import { type PresenceProps, usePresenceContext } from '../presence'
export interface ColorPickerContentBaseProps extends PresenceProps, PolymorphicProps {}
export interface ColorPickerContentProps
Expand All @@ -18,10 +19,12 @@ import { useColorPickerContext } from './use-color-picker-context'
defineProps<ColorPickerContentProps>()
const colorPicker = useColorPickerContext()
const presence = usePresenceContext()
const mergedProps = computed(() => mergeProps(colorPicker.value.getContentProps(), presence.value.presenceProps))
</script>

<template>
<ark.div v-bind="colorPicker.getContentProps()">
<ark.div v-if="!presence.unmounted" v-bind="mergedProps" :as-child="asChild">
<slot />
</ark.div>
</template>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory'
import { type HTMLAttributes, computed } from 'vue'
import { type PolymorphicProps, ark } from '../factory'
export interface ColorPickerPositionerBaseProps extends PolymorphicProps {}
export interface ColorPickerPositionerProps
Expand All @@ -13,21 +13,24 @@ export interface ColorPickerPositionerProps

<script setup lang="ts">
import { useRenderStrategyProps } from '../../utils'
import { Presence } from '../presence'
import { PresenceProvider, usePresence } from '../presence'
import { useColorPickerContext } from './use-color-picker-context'
defineProps<ColorPickerPositionerProps>()
const colorPicker = useColorPickerContext()
const renderStrategy = useRenderStrategyProps()
const presence = usePresence(
computed(() => ({
...renderStrategy.value,
present: colorPicker.value.open,
})),
)
PresenceProvider(presence)
</script>

<template>
<Presence
v-bind="colorPicker.getPositionerProps()"
:present="colorPicker.open"
:lazy-mount="renderStrategy.lazyMount"
:unmount-on-exit="renderStrategy.unmountOnExit"
>
<ark.div v-if="!presence.unmounted" v-bind="colorPicker.getPositionerProps()" :as-child="asChild">
<slot />
</Presence>
</ark.div>
</template>
9 changes: 7 additions & 2 deletions packages/vue/src/components/combobox/combobox-content.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { mergeProps } from '@zag-js/vue'
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory'
import { usePresenceContext } from '../presence'
export interface ComboboxContentBaseProps extends PolymorphicProps {}
export interface ComboboxContentProps
Expand All @@ -17,10 +19,13 @@ import { useComboboxContext } from './use-combobox-context'
defineProps<ComboboxContentProps>()
const combobox = useComboboxContext()
const presence = usePresenceContext()
const mergedProps = computed(() => mergeProps(combobox.value.getContentProps(), presence.value.presenceProps))
</script>

<template>
<ark.div v-bind="combobox.getContentProps()" :as-child="asChild">
<ark.div v-if="!presence.unmounted" v-bind="mergedProps" :as-child="asChild">
<slot />
</ark.div>
</template>

23 changes: 13 additions & 10 deletions packages/vue/src/components/combobox/combobox-positioner.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory'
import { type HTMLAttributes, computed } from 'vue'
import { type PolymorphicProps, ark } from '../factory'
export interface ComboboxPositionerBaseProps extends PolymorphicProps {}
export interface ComboboxPositionerProps
Expand All @@ -13,21 +13,24 @@ export interface ComboboxPositionerProps

<script setup lang="ts">
import { useRenderStrategyProps } from '../../utils'
import { Presence } from '../presence'
import { PresenceProvider, usePresence } from '../presence'
import { useComboboxContext } from './use-combobox-context'
defineProps<ComboboxPositionerProps>()
const combobox = useComboboxContext()
const renderStrategy = useRenderStrategyProps()
const presence = usePresence(
computed(() => ({
...renderStrategy.value,
present: combobox.value.open,
})),
)
PresenceProvider(presence)
</script>

<template>
<Presence
v-bind="combobox.getPositionerProps()"
:present="combobox.open"
:lazy-mount="renderStrategy.lazyMount"
:unmount-on-exit="renderStrategy.unmountOnExit"
>
<ark.div v-if="!presence.unmounted" v-bind="combobox.getPositionerProps()" :as-child="asChild">
<slot />
</Presence>
</ark.div>
</template>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { mergeProps } from '@zag-js/vue'
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory'
import { usePresenceContext } from '../presence'
export interface DatePickerContentBaseProps extends PolymorphicProps {}
export interface DatePickerContentProps
Expand All @@ -17,10 +19,12 @@ import { useDatePickerContext } from './use-date-picker-context'
defineProps<DatePickerContentProps>()
const datePicker = useDatePickerContext()
const presence = usePresenceContext()
const mergedProps = computed(() => mergeProps(datePicker.value.getContentProps(), presence.value.presenceProps))
</script>

<template>
<ark.div v-bind="datePicker.getContentProps()" :as-child="asChild">
<ark.div v-if="!presence.unmounted" v-bind="mergedProps" :as-child="asChild">
<slot />
</ark.div>
</template>
25 changes: 14 additions & 11 deletions packages/vue/src/components/date-picker/date-picker-positioner.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory'
import { type HTMLAttributes, computed } from 'vue'
import { type PolymorphicProps, ark } from '../factory'
export interface DatePickerPositionerBaseProps extends PolymorphicProps {}
export interface DatePickerPositionerProps
Expand All @@ -13,21 +13,24 @@ export interface DatePickerPositionerProps

<script setup lang="ts">
import { useRenderStrategyProps } from '../../utils'
import { Presence } from '../presence'
import { PresenceProvider, usePresence } from '../presence'
import { useDatePickerContext } from './use-date-picker-context'
defineProps<DatePickerPositionerProps>()
const datePicker = useDatePickerContext()
const renderStrategy = useRenderStrategyProps()
const presence = usePresence(
computed(() => ({
...renderStrategy.value,
present: datePicker.value.open,
})),
)
PresenceProvider(presence)
</script>

<template>
<Presence
v-bind="datePicker.getPositionerProps()"
:present="datePicker.open"
:lazy-mount="renderStrategy.lazyMount"
:unmount-on-exit="renderStrategy.unmountOnExit"
>
<ark.div v-if="!presence.unmounted" v-bind="datePicker.getPositionerProps()" :as-child="asChild">
<slot />
</Presence>
</template>
</ark.div>
</template>
9 changes: 7 additions & 2 deletions packages/vue/src/components/dialog/dialog-content.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { mergeProps } from '@zag-js/vue'
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory'
import { usePresenceContext } from '../presence'
export interface DialogContentBaseProps extends PolymorphicProps {}
export interface DialogContentProps
Expand All @@ -16,11 +18,14 @@ import { ark } from '../factory'
import { useDialogContext } from './use-dialog-context'
defineProps<DialogContentProps>()
const dialog = useDialogContext()
const presence = usePresenceContext()
const mergedProps = computed(() => mergeProps(dialog.value.getContentProps(), presence.value.presenceProps))
</script>

<template>
<ark.div v-bind="dialog.getContentProps()" :as-child="asChild">
<ark.div v-if="!presence.unmounted" v-bind="mergedProps" :as-child="asChild">
<slot />
</ark.div>
</template>
25 changes: 15 additions & 10 deletions packages/vue/src/components/dialog/dialog-positioner.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { type HTMLAttributes, computed } from 'vue'
import { useRenderStrategyProps } from '../../utils'
import type { PolymorphicProps } from '../factory'
export interface DialogPositionerBaseProps extends PolymorphicProps {}
Expand All @@ -12,22 +13,26 @@ export interface DialogPositionerProps
</script>

<script setup lang="ts">
import { useRenderStrategyProps } from '../../utils'
import { Presence } from '../presence'
import { ark } from '../factory'
import { PresenceProvider, usePresence } from '../presence'
import { useDialogContext } from './use-dialog-context'
defineProps<DialogPositionerProps>()
const dialog = useDialogContext()
const renderStrategy = useRenderStrategyProps()
const presence = usePresence(
computed(() => ({
...renderStrategy.value,
present: dialog.value.open,
})),
)
PresenceProvider(presence)
</script>

<template>
<Presence
v-bind="dialog.getPositionerProps()"
:present="dialog.open"
:lazy-mount="renderStrategy.lazyMount"
:unmount-on-exit="renderStrategy.unmountOnExit"
>
<ark.div v-if="!presence.unmounted" v-bind="dialog.getPositionerProps()" :as-child="asChild">
<slot />
</Presence>
</ark.div>
</template>
5 changes: 3 additions & 2 deletions packages/vue/src/components/dialog/tests/dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ describe('Dialog', () => {
render(ComponentUnderTest)

await user.click(screen.getByText('Open Dialog'))
expect(await screen.findByText('Dialog Title')).toBeVisible()

await waitFor(async () => expect(await screen.findByText('Dialog Title')).toBeVisible())

await user.click(screen.getByText('Close'))
expect(await screen.findByText('Dialog Title')).not.toBeVisible()
await waitFor(async () => expect(await screen.findByText('Dialog Title')).not.toBeVisible())
})

it('should invoke onOpenChange if dialog is closed', async () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/vue/src/components/hover-card/hover-card-content.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { mergeProps } from '@zag-js/vue'
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory'
import { usePresenceContext } from '../presence'
export interface HoverCardContentBaseProps extends PolymorphicProps {}
export interface HoverCardContentProps
Expand All @@ -17,10 +19,12 @@ import { useHoverCardContext } from './use-hover-card-context'
defineProps<HoverCardContentProps>()
const hoverCard = useHoverCardContext()
const presence = usePresenceContext()
const mergedProps = computed(() => mergeProps(hoverCard.value.getContentProps(), presence.value.presenceProps))
</script>

<template>
<ark.div v-bind="hoverCard.getContentProps()" :as-child="asChild">
<ark.div v-if="!presence.unmounted" v-bind="mergedProps" :as-child="asChild">
<slot />
</ark.div>
</template>
</template>
24 changes: 14 additions & 10 deletions packages/vue/src/components/hover-card/hover-card-positioner.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory'
import { type HTMLAttributes, computed } from 'vue'
import { type PolymorphicProps, ark } from '../factory'
export interface HoverCardPositionerBaseProps extends PolymorphicProps {}
export interface HoverCardPositionerProps
Expand All @@ -13,21 +13,25 @@ export interface HoverCardPositionerProps

<script setup lang="ts">
import { useRenderStrategyProps } from '../../utils'
import { Presence } from '../presence'
import { PresenceProvider, usePresence } from '../presence'
import { useHoverCardContext } from './use-hover-card-context'
defineProps<HoverCardPositionerProps>()
const hoverCard = useHoverCardContext()
const renderStrategy = useRenderStrategyProps()
const presence = usePresence(
computed(() => ({
...renderStrategy.value,
present: hoverCard.value.open,
})),
)
PresenceProvider(presence)
</script>

<template>
<Presence
v-bind="hoverCard.getPositionerProps()"
:present="hoverCard.open"
:lazy-mount="renderStrategy.lazyMount"
:unmount-on-exit="renderStrategy.unmountOnExit"
>
<ark.div v-if="!presence.unmounted" v-bind="hoverCard.getPositionerProps()" :as-child="asChild">
<slot />
</Presence>
</ark.div>
</template>

10 changes: 7 additions & 3 deletions packages/vue/src/components/menu/menu-content.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import { mergeProps } from '@zag-js/vue'
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory'
import { usePresenceContext } from '../presence'
export interface MenuContentBaseProps extends PolymorphicProps {}
export interface MenuContentProps
Expand All @@ -17,10 +19,12 @@ import { useMenuContext } from './use-menu-context'
defineProps<MenuContentProps>()
const menu = useMenuContext()
const presence = usePresenceContext()
const mergedProps = computed(() => mergeProps(menu.value.getContentProps(), presence.value.presenceProps))
</script>

<template>
<ark.div v-bind="menu.getContentProps()" :as-child="asChild">
<ark.div v-if="!presence.unmounted" v-bind="mergedProps" :as-child="asChild">
<slot />
</ark.div>
</template>
</template>
Loading

0 comments on commit 71be482

Please sign in to comment.