Skip to content

Commit

Permalink
fix: toggle not setting pressed property on init (#223)
Browse files Browse the repository at this point in the history
* fix: toggle not setting pressed property on init

* refactor: move class outside of toggleVariants
  • Loading branch information
sadeghbarati authored Dec 29, 2023
1 parent 9d66d15 commit 5e22ffc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
17 changes: 13 additions & 4 deletions apps/www/src/lib/registry/default/ui/toggle/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { ToggleEmits, ToggleProps } from 'radix-vue'
import { Toggle, useForwardPropsEmits } from 'radix-vue'
import type { VariantProps } from 'class-variance-authority'
import { computed } from 'vue'
import { computed, useAttrs } from 'vue'
import { toggleVariants } from '.'
import { cn } from '@/lib/utils'
Expand All @@ -13,6 +13,11 @@ interface Props extends ToggleProps {
size?: ToggleVariantProps['size']
disabled?: boolean
}
defineOptions({
inheritAttrs: false,
})
const props = withDefaults(defineProps<Props>(), {
variant: 'default',
size: 'default',
Expand All @@ -26,13 +31,17 @@ const toggleProps = computed(() => {
return otherProps
})
const forwarded = useForwardPropsEmits(toggleProps, emits)
const { class: className, ...rest } = useAttrs()
const forwarded = useForwardPropsEmits(toggleProps.value, emits)
</script>

<template>
<Toggle
v-bind="forwarded"
:class="cn(toggleVariants({ variant, size, class: $attrs.class ?? '' }))"
v-bind="{
...forwarded,
...rest,
}"
:class="cn(toggleVariants({ variant, size }), className ?? '')"
:disabled="props.disabled"
>
<slot />
Expand Down
19 changes: 14 additions & 5 deletions apps/www/src/lib/registry/new-york/ui/toggle/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { ToggleEmits, ToggleProps } from 'radix-vue'
import { Toggle, useForwardPropsEmits } from 'radix-vue'
import type { VariantProps } from 'class-variance-authority'
import { computed } from 'vue'
import { computed, useAttrs } from 'vue'
import { toggleVariants } from '.'
import { cn } from '@/lib/utils'
Expand All @@ -13,6 +13,11 @@ interface Props extends ToggleProps {
size?: ToggleVariantProps['size']
disabled?: boolean
}
defineOptions({
inheritAttrs: false,
})
const props = withDefaults(defineProps<Props>(), {
variant: 'default',
size: 'default',
Expand All @@ -22,17 +27,21 @@ const emits = defineEmits<ToggleEmits>()
const toggleProps = computed(() => {
// eslint-disable-next-line unused-imports/no-unused-vars
const { variant, size, ...otherProps } = props
const { variant, size, disabled, ...otherProps } = props
return otherProps
})
const forwarded = useForwardPropsEmits(toggleProps, emits)
const { class: className, ...rest } = useAttrs()
const forwarded = useForwardPropsEmits(toggleProps.value, emits)
</script>

<template>
<Toggle
v-bind="forwarded"
:class="cn(toggleVariants({ variant, size, class: $attrs.class ?? '' }))"
v-bind="{
...forwarded,
...rest,
}"
:class="cn(toggleVariants({ variant, size }), className ?? '')"
:disabled="props.disabled"
>
<slot />
Expand Down

0 comments on commit 5e22ffc

Please sign in to comment.