-
Notifications
You must be signed in to change notification settings - Fork 373
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]: Input attrs
are not reactive
#224
Comments
Will check it. Thanks for the report |
If you want i could create a PR to fix this issue. |
to prevent duplicate classes I thought this way would work, actually, it works but on the first render and without reactivity afterward const { class: className, ...restOfAttributes } = useAttrs()
|
Yeah since propsDestructure is still experimental we have to use Also i have notice that we are using useAttrs() in FormItem, PaginationEllipsis with destructuring so we have to make changes there as well? |
I've found this error with Form.
from Input as it removes the reactivity and bindings from the component (as described in docs here) |
It would be helpful if you can provide minimal reproduction (stackblitz/codesandbox). So we can check whats the issue. |
You can see the issue even in the docs under Form. I can create a separate repo that recreates the issue but I don't think it's necessary here. You can even check it just with browser's inspection. |
Yeah it is because we are destructuring For the solution we have to define class inside props and bind other attributes without destructuring. Here is the Solution you could use for now. This is latest commit with the same implementation soon it will be fix in live. input-attrs-issue.webm |
This works well, great work. |
Yeah because by default You can take a look at this Vue SFC Playground to understand better. I hope this explains. Sorry for my bad english. |
Environment
Link to minimal reproduction
https://stackblitz.com/edit/8qmftg?file=src%2FApp.vue
Steps to reproduce
pnpm create vue@latest
.pnpm dlx shadcn-vue@latest init
.pnpm dlx shadcn-vue@latest add input
.pnpm run dev
.App.vue
component with Input component fromshadcn-vue
and create password input so when we click on it it changes the type attribute of input tag.Describe the bug
Yesterday, I was playing around with the
shadcn-vue
package for a little side project that I was building. I needed a password input for the signin/signup form. I added the input component fromshadcn-vue
and imported it into my form. I also needed a toggle button in the password input so that when the user clicks on it, it switches from type="password" to type="text" and vice versa. So, I implemented a basic form with a password input, and when I click on it, it toggles thetype
.But this was not working when i clicked on toggle button it was not toggling the type attribute on input. I was not able to figure out why its not working because the icon was changing but why
type
attribute is not changing?.Then i checked the code of Input component and i found that we are using vue
useAttrs()
composable and grabbing all attributes destructuring theclass
andrest
from it and adding to ourinput
tag.When we destructure the attrs we looses the reactivity and that's why the attribute was not changing.
Expected behavior
The Expected behavior is attrs should be reactive. When it changes it also updates the input attributes.
Solution
We can solve this by using
computed
property. Here is the code for it.Conext & Screenshots (if applicable)
Demo showing that after changing to
computed
property it is working.shadcn-vue-input-demo.webm
The text was updated successfully, but these errors were encountered: