-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Uncontrolled collapsible not working #310
Comments
export interface CollapsibleRootProps extends PrimitiveProps {
/** The open state of the collapsible when it is initially rendered. <br> Use when you do not need to control its open state. */
defaultOpen?: boolean;
/** The controlled open state of the collapsible. Can be binded with `v-model`. */
open?: boolean;
/** When `true`, prevents the user from interacting with the collapsible. */
disabled?: boolean;
} Boolean casting curse@ParasSolanki This is because Vue will transform With this issue, we kinda make the Component Controlled even though we don't want too I HOPE the Vue team fixes it soon You have two options to fix it 1. useForwardPropsEmits and useForwardProps
<script setup lang="ts">
import { CollapsibleRoot, useForwardPropsEmits } from 'radix-vue'
import type { CollapsibleRootEmits, CollapsibleRootProps } from 'radix-vue'
const props = defineProps<CollapsibleRootProps>()
const emits = defineEmits<CollapsibleRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<CollapsibleRoot v-slot="{ open }" v-bind="forwarded">
<slot :open="open" />
</CollapsibleRoot>
</template> 2. withDeafults
<script setup lang="ts">
import { CollapsibleRoot, useEmitAsProps } from 'radix-vue'
import type { CollapsibleRootEmits, CollapsibleRootProps } from 'radix-vue'
const props = withDefaults(defineProps<CollapsibleRootProps>(), {
defaultOpen: undefined,
disabled: undefined,
open: undefined,
})
const emits = defineEmits<CollapsibleRootEmits>()
</script>
<template>
<CollapsibleRoot v-slot="{ open }" v-bind="{ ...props, ...useEmitAsProps(emits) }">
<slot :open="open" />
</CollapsibleRoot>
</template> |
Oh interesting! |
Environment
Link to minimal reproduction
https://stackblitz.com/edit/w2uuxx-s8mgnp?file=src%2FApp.vue,package.json
Steps to reproduce
pnpm create vue@latest
.pnpm dlx shadcn-vue@latest init
.pnpm run dev
.ref
(Controlled) and Second (Uncontrolled).Describe the bug
I was checking the docs on mobile the other day and found out that on mobile "On this Page" TOC was not working. So, i decided to check what is the issue?
on-this-page-shadcn-vue.webm
In the docs we are using TableOfContent.vue component and it will show TOC for the page and there we have this On This Page Collapsible which will toggle the TOC section.
The code had no issue because we can use Collapsible both Controlled and Uncontrolled way. Here, In the docs we are using as Uncontrolled and it should work. Then i checked in our Collapsible Component Docs and there it was working but not for the "On this page" TOC.
Controlled collapsible is working but Uncontrolled collapsible not working. Also i am not sure whether this is bug from radix-vue side from our collapsible component side.
uncontrolled-collapsible-not-working.webm
Expected behavior
Collapsible should work if its controlled or uncontrolled.
Conext & Screenshots (if applicable)
No response
The text was updated successfully, but these errors were encountered: