Skip to content

Commit

Permalink
fix(Modal): button side-effects when used within a button group
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Jan 18, 2025
1 parent f0297e0 commit cd9f97c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/runtime/components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extendDevtoolsMeta({ example: 'ModalExample' })
</script>

<script setup lang="ts">
import { computed, toRef } from 'vue'
import { computed, toRef, provide } from 'vue'
import { DialogRoot, DialogTrigger, DialogPortal, DialogOverlay, DialogContent, DialogTitle, DialogDescription, DialogClose, useForwardPropsEmits } from 'reka-ui'
import { reactivePick } from '@vueuse/core'
import { useAppConfig } from '#imports'
Expand Down Expand Up @@ -112,6 +112,9 @@ const ui = computed(() => modal({
transition: props.transition,
fullscreen: props.fullscreen
}))
// Blocks ButtonGroup injections to avoid side-effects if the modal is within a button group.
provide(buttonGroupInjectionKey, undefined)
</script>

<template>
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/composables/useButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import type { GetObjectField } from '../types/utils'
export const buttonGroupInjectionKey: InjectionKey<ComputedRef<{
size: ButtonGroupProps['size']
orientation: ButtonGroupProps['orientation']
}>> = Symbol('nuxt-ui.button-group')
}> | undefined> = Symbol('nuxt-ui.button-group')

type Props<T> = {
size?: GetObjectField<T, 'size'>
}

export function useButtonGroup<T>(props: Props<T>) {
const buttonGroup = inject(buttonGroupInjectionKey, undefined)

return {
orientation: computed(() => buttonGroup?.value.orientation),
size: computed(() => props?.size ?? buttonGroup?.value.size)
Expand Down

0 comments on commit cd9f97c

Please sign in to comment.