-
Describe the questionThere is this pattern of accepting <script setup lang="ts">
import { computed } from 'vue'
import { useVModel } from '@vueuse/core'
import { Primitive } from '@/Primitive'
const props = withDefaults(defineProps<ToggleProps>(), {
pressed: undefined,
disabled: false,
as: 'button',
})
const emits = defineEmits<ToggleEmits>()
const pressed = useVModel(props, 'pressed', emits, {
defaultValue: props.defaultValue,
passive: (props.pressed === undefined) as false,
})
function togglePressed() {
pressed.value = !pressed.value
}
</script>
<template>
<Primitive
:type="as === 'button' ? 'button' : undefined"
:as-child="props.asChild"
:as="as"
:aria-pressed="pressed"
:data-state="dataState"
:data-disabled="disabled ? '' : undefined"
:disabled="disabled"
@click="togglePressed"
>
<slot />
</Primitive>
</template> I guess this was added to be fully compatible with Since <script setup lang="ts">
import { Primitive } from '@/Primitive'
const props = withDefaults(defineProps<ToggleProps>(), {
disabled: false,
as: 'button',
})
defineEmits<ToggleEmits>()
const pressed = defineModel<boolean>('pressed', { default: false })
useForwardExpose()
function togglePressed() {
pressed.value = !pressed.value
}
</script>
<template>
<Primitive
:type="as === 'button' ? 'button' : undefined"
:as-child="props.asChild"
:as="as"
:aria-pressed="pressed"
:data-state="dataState"
:data-disabled="disabled ? '' : undefined"
:disabled="disabled"
@click="togglePressed"
>
<slot />
</Primitive>
</template> this is indeed a breaking change but it would remove the extra |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Thanks for the question @Saeid-Za !
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the detailed response @zernonia !
This is interesting, I did not know such a limitation existed. I tried to implement a prototype replacing
This is not an issue of end-user. We're talking about adding vue 3.3+ to radix-vue codebase and since
I did not encounter such issue in my prototype. We never change the type of |
Beta Was this translation helpful? Give feedback.
-
UpdateThe issue opened in vue repo, was closed and was explained that this is the expected behavior. I marked your answer. Thanks again. |
Beta Was this translation helpful? Give feedback.
Thanks for the question @Saeid-Za !
Because in certain case we want a
uncontrolled
version of the component. Let's say I want to havedefault
AccordionItem to be opened, thus we setdefaultValue: 'accordion-2'
. We can't usemodelValue: 'accordion-2'
because it would cause the Accordion internal state not to be updated. We can't also usev-model="accordion-2"
(static value) as well.We don't use
defineModel
as we wanna support3.3
version. Also, usinguseVModel
allow us to forwardprops
andemits
easily. We dont need to export anotherdefineModel
's types 1-by-1.