Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
k11q committed Jul 19, 2023
1 parent 7c6434b commit c1ad5de
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 10 deletions.
10 changes: 5 additions & 5 deletions packages/radix-vue/src/Switch/SwitchRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const SWITCH_INJECTION_KEY =
export interface SwitchProvideValue {
open?: Readonly<Ref<boolean>>;
toggleOpen: (value: string) => void;
toggleOpen: () => void;
disabled: boolean;
}
</script>
Expand Down Expand Up @@ -53,7 +53,7 @@ provide<SwitchProvideValue>(SWITCH_INJECTION_KEY, {
});
function handleKeydown(e: KeyboardEvent) {
if (e.key === "Enter" || e.keyCode === 32) {
if (e.key === "Enter") {
toggleOpen();
}
}
Expand All @@ -62,20 +62,21 @@ function handleKeydown(e: KeyboardEvent) {
<template>
<PrimitiveDiv
:value="open"
role="checkbox"
role="switch"
:aria-checked="open"
:data-state="open ? 'checked' : 'unchecked'"
:data-disabled="props.disabled ? '' : undefined"
:as-child="props.asChild"
style="position: relative"
>
<slot />
<input
type="checkbox"
:id="props.id"
v-bind="open"
@change="toggleOpen"
:checked="open"
:name="props.name"
@click="toggleOpen"
@keydown="handleKeydown"
aria-hidden="true"
:disabled="props.disabled"
Expand All @@ -84,6 +85,5 @@ function handleKeydown(e: KeyboardEvent) {
:data-disabled="props.disabled ? '' : undefined"
style="opacity: 0; position: absolute; inset: 0"
/>
<slot />
</PrimitiveDiv>
</template>
5 changes: 2 additions & 3 deletions packages/radix-vue/src/Switch/SwitchThumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import {
} from "./SwitchRoot.vue";
const injectedValue = inject<SwitchProvideValue>(SWITCH_INJECTION_KEY);
const props = defineProps<SwitchThumbProps>();
defineProps<SwitchThumbProps>();
</script>

<template>
<PrimitiveSpan
:data-state="injectedValue?.open?.value ? 'checked' : 'unchecked'"
:data-disabled="injectedValue?.disabled ? '' : undefined"
:as-child="props.asChild"
@click="injectedValue?.toggleOpen"
:as-child="asChild"
>
<slot />
</PrimitiveSpan>
Expand Down
2 changes: 1 addition & 1 deletion playground/vue3/src/components/Demo/SwitchDemo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { SwitchRoot, SwitchThumb } from 'radix-vue'
import { SwitchRoot, SwitchThumb } from '../../../../../packages/radix-vue/src'
import { ref } from 'vue'
const switchState = ref(true)
Expand Down
80 changes: 79 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1ad5de

Please sign in to comment.