-
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]: Class name duplicated #35
Comments
However if we extend Props based on HTMLAttributes like shadcn, we will have two class prop when we hit Ctrl + Space
see this SFC playground Edit: external types error and vue props destructuring error with |
Base on so1ve answer in Vue issue (How to import interface for defineProps) imported external interface should not be extended so Vue can resolve the type We should have an interface like this - export interface ButtonHTMLAttributes extends HTMLAttributes {
+ export interface OnlyButtonHTMLAttributes {
autofocus?: Booleanish
disabled?: Booleanish
form?: string
formaction?: string
formenctype?: string
formmethod?: string
formnovalidate?: Booleanish
formtarget?: string
name?: string
type?: 'submit' | 'reset' | 'button'
value?: string | string[] | number
} https://github.com/wooorm/html-element-attributes/blob/main/index.js |
Because the default value of the |
That Vue SFC playground sometimes acts inconsistently after editing 😭 for example, it's merge classes even if you use $attrs.class and v-bind="$attrs" I think we should use New SFC playgrounduseAttrs (not reactive when destructered and make them reactive with computed or other Vue apis is not good choice cause attrs are readonly proxy)Component<script setup lang="ts">
import { useAttrs } from 'vue'
import { cn } from '@/lib/utils'
defineOptions({
inheritAttrs: false,
})
const { class: className, ...rest } = useAttrs() // not reactive only works on first render
</script>
<template>
<input type="text" :class="cn('flex h-9 w-full text-green-600', className ?? '')" v-bind="rest">
</template> Usage<script setup lang="ts">
import Input from './Input.vue'
</script>
<template>
<Input class="text-red-600"/> <!-- class output: "flex h-9 w-full text-red-600" -->
</template> |
|
Hi, have we finalize the solution yet? |
This comment was marked as off-topic.
This comment was marked as off-topic.
Note that setting |
If you inspecting some element, you would notice a duplicated class name mainly due to using
2.
approach mentioned below.For components in
registry
, you would see 2 different approach for passing the class name intocn
function.class
props.The reason I'm hesitating is because I don't like to declare
class
props in every component, using$attrs.class
seems much more intuitive. wdyt??The text was updated successfully, but these errors were encountered: