Skip to content
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

checked prop does nothing in Checkbox #188

Open
ruchamahabal opened this issue Sep 19, 2024 · 1 comment
Open

checked prop does nothing in Checkbox #188

ruchamahabal opened this issue Sep 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ruchamahabal
Copy link
Member

checked prop does nothing in Checkbox. It only depends on modelValue

<template>
<div
class="inline-flex items-center space-x-2 rounded transition"
:class="{
'px-2.5 py-1.5': padding && size === 'sm',
'px-3 py-2': padding && size === 'md',
'focus-within:bg-gray-100 focus-within:ring-2 focus-within:ring-gray-400 hover:bg-gray-200 active:bg-gray-300':
padding && !disabled,
}"
>
<input
class="rounded-sm"
:class="inputClasses"
type="checkbox"
:disabled="disabled"
:id="htmlId"
:checked="Boolean(modelValue)"
@change="
(e) =>
$emit('update:modelValue', (e.target as HTMLInputElement).checked)
"
v-bind="attrs"
/>
<label class="block" :class="labelClasses" v-if="label" :for="htmlId">
{{ label }}
</label>
</div>
</template>
<script lang="ts" setup>
import { computed, useAttrs } from 'vue'
import { useId } from '../utils/useId'
interface CheckboxProps {
size?: 'sm' | 'md'
label?: string
checked?: boolean
disabled?: boolean
padding?: boolean
modelValue?: boolean | 1 | 0
id?: string
}
const props = withDefaults(defineProps<CheckboxProps>(), {
size: 'sm',
padding: false,
})

Should we remove it? Will lead to warnings for Extraneous non-props attributes were passed
Should we wire it? Will change behavior if someone has set the prop value

@ruchamahabal ruchamahabal added the bug Something isn't working label Sep 19, 2024
@netchampfaris
Copy link
Contributor

We should probably sync it with modelValue such that both work:

<Checkbox v-model="checked" />

<Checkbox v-model:checked="checked" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants