fix: toggle not setting pressed property on init (#223)
* fix: toggle not setting pressed property on init * refactor: move class outside of toggleVariants
This commit is contained in:
parent
9d66d15801
commit
5e22ffc037
|
|
@ -2,7 +2,7 @@
|
||||||
import type { ToggleEmits, ToggleProps } from 'radix-vue'
|
import type { ToggleEmits, ToggleProps } from 'radix-vue'
|
||||||
import { Toggle, useForwardPropsEmits } from 'radix-vue'
|
import { Toggle, useForwardPropsEmits } from 'radix-vue'
|
||||||
import type { VariantProps } from 'class-variance-authority'
|
import type { VariantProps } from 'class-variance-authority'
|
||||||
import { computed } from 'vue'
|
import { computed, useAttrs } from 'vue'
|
||||||
import { toggleVariants } from '.'
|
import { toggleVariants } from '.'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
|
|
@ -13,6 +13,11 @@ interface Props extends ToggleProps {
|
||||||
size?: ToggleVariantProps['size']
|
size?: ToggleVariantProps['size']
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
inheritAttrs: false,
|
||||||
|
})
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
variant: 'default',
|
variant: 'default',
|
||||||
size: 'default',
|
size: 'default',
|
||||||
|
|
@ -26,13 +31,17 @@ const toggleProps = computed(() => {
|
||||||
return otherProps
|
return otherProps
|
||||||
})
|
})
|
||||||
|
|
||||||
const forwarded = useForwardPropsEmits(toggleProps, emits)
|
const { class: className, ...rest } = useAttrs()
|
||||||
|
const forwarded = useForwardPropsEmits(toggleProps.value, emits)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Toggle
|
<Toggle
|
||||||
v-bind="forwarded"
|
v-bind="{
|
||||||
:class="cn(toggleVariants({ variant, size, class: $attrs.class ?? '' }))"
|
...forwarded,
|
||||||
|
...rest,
|
||||||
|
}"
|
||||||
|
:class="cn(toggleVariants({ variant, size }), className ?? '')"
|
||||||
:disabled="props.disabled"
|
:disabled="props.disabled"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import type { ToggleEmits, ToggleProps } from 'radix-vue'
|
import type { ToggleEmits, ToggleProps } from 'radix-vue'
|
||||||
import { Toggle, useForwardPropsEmits } from 'radix-vue'
|
import { Toggle, useForwardPropsEmits } from 'radix-vue'
|
||||||
import type { VariantProps } from 'class-variance-authority'
|
import type { VariantProps } from 'class-variance-authority'
|
||||||
import { computed } from 'vue'
|
import { computed, useAttrs } from 'vue'
|
||||||
import { toggleVariants } from '.'
|
import { toggleVariants } from '.'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
|
|
@ -13,6 +13,11 @@ interface Props extends ToggleProps {
|
||||||
size?: ToggleVariantProps['size']
|
size?: ToggleVariantProps['size']
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
inheritAttrs: false,
|
||||||
|
})
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
variant: 'default',
|
variant: 'default',
|
||||||
size: 'default',
|
size: 'default',
|
||||||
|
|
@ -22,17 +27,21 @@ const emits = defineEmits<ToggleEmits>()
|
||||||
|
|
||||||
const toggleProps = computed(() => {
|
const toggleProps = computed(() => {
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||||
const { variant, size, ...otherProps } = props
|
const { variant, size, disabled, ...otherProps } = props
|
||||||
return otherProps
|
return otherProps
|
||||||
})
|
})
|
||||||
|
|
||||||
const forwarded = useForwardPropsEmits(toggleProps, emits)
|
const { class: className, ...rest } = useAttrs()
|
||||||
|
const forwarded = useForwardPropsEmits(toggleProps.value, emits)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Toggle
|
<Toggle
|
||||||
v-bind="forwarded"
|
v-bind="{
|
||||||
:class="cn(toggleVariants({ variant, size, class: $attrs.class ?? '' }))"
|
...forwarded,
|
||||||
|
...rest,
|
||||||
|
}"
|
||||||
|
:class="cn(toggleVariants({ variant, size }), className ?? '')"
|
||||||
:disabled="props.disabled"
|
:disabled="props.disabled"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user