Skip to content

feat(CheckboxGroup): new component #3862

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

Open
wants to merge 37 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0ab5e50
docs: add page for UCheckboxGroup
TribeWeb Apr 11, 2025
0833ff6
feat: create checkboxGroup to handle arrays and use radioGroup variants
TribeWeb Apr 11, 2025
926b783
chore: add checkboxGroup to all component and types lists
TribeWeb Apr 11, 2025
0b531fa
chore: rerun tests
TribeWeb Apr 11, 2025
ac8ca04
docs: add missing description and category
TribeWeb Apr 12, 2025
a60a2bb
Update docs/content/3.components/checkbox-group.md
TribeWeb Apr 12, 2025
b180da5
Merge branch 'v3' into checkBoxGroup
benjamincanac Apr 13, 2025
3248184
chore: refactor after #3855
benjamincanac Apr 13, 2025
4980a65
docs(CheckboxGroup): add to form elements example
romhml Apr 13, 2025
e09e3be
fix: test/components/CheckboxGroup.spec.ts
TribeWeb Apr 13, 2025
e23a21f
fix: imports in test/components/CheckboxGroup.spec.ts
TribeWeb Apr 13, 2025
7a7180c
docs(CheckboxGroup): fix initial modelValue
romhml Apr 15, 2025
46b0ace
feat: Apply new variant styling
TribeWeb Apr 16, 2025
e529936
feat: refactor to reuse UCheckbox
TribeWeb Apr 16, 2025
e4d8719
feat: share and reuse styling between both components
TribeWeb Apr 16, 2025
cf7f46d
chore: update playground with variant chooser
TribeWeb Apr 16, 2025
e7a5aa4
chore: new snapshots
TribeWeb Apr 16, 2025
f5d8f7d
chore: new snapshots
TribeWeb Apr 16, 2025
27c3046
chore: fixed my initial mistakes in test file - still failing 4 tests
TribeWeb Apr 16, 2025
37abbc8
Merge branch 'checkBoxGroup' of https://github.com/TribeWeb/ui into c…
TribeWeb Apr 16, 2025
0fbb36f
Merge branch 'v3' into checkBoxGroup
TribeWeb Apr 16, 2025
c8eef60
chore: refactor to use provide/inject as per other group components
TribeWeb Apr 17, 2025
aa1e01f
docs: update to include table and card variants
TribeWeb Apr 17, 2025
69ab7e1
chore: refactor to restore `Primitive` root element on Checkbox and k…
TribeWeb Apr 17, 2025
74b06d2
Merge branch 'v3' into checkBoxGroup
TribeWeb Apr 17, 2025
87fecc7
chore: update snapshots
TribeWeb Apr 17, 2025
30d769f
chore: refactor using vueUse-createReusableTemplate to reduce repetition
TribeWeb Apr 19, 2025
8d7aabf
fix: reintroduce indeterminate state & disabled state
TribeWeb Apr 19, 2025
6323990
fix: default and model test values
TribeWeb Apr 19, 2025
3c4fa12
chore: update snapshots
TribeWeb Apr 19, 2025
275f3fb
Merge branch 'v3' into checkBoxGroup
TribeWeb Apr 19, 2025
d9217f5
fix: removed unecessary v-model repetition
TribeWeb Apr 20, 2025
b31c0d4
Merge branch 'v3' into checkBoxGroup
TribeWeb Apr 20, 2025
c84e410
fix: revert v-model
TribeWeb Apr 20, 2025
f732747
Merge branch 'v3' into checkBoxGroup
TribeWeb Apr 21, 2025
07d4e69
Merge branch 'v3' into pr/3862
benjamincanac Apr 21, 2025
b659b91
up
benjamincanac Apr 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/app/components/content/examples/form/FormExampleElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const schema = z.object({
radioGroup: z.string().refine(value => value === 'option-2', {
message: 'Select Option 2'
}),
checkboxGroup: z.any().refine(values => !!values?.find((option: any) => option === 'option-2'), {
message: 'Include Option 2'
}),
slider: z.number().max(20, { message: 'Must be less than 20' }),
pin: z.string().regex(/^\d$/).array().length(5)
})
Expand Down Expand Up @@ -101,11 +104,14 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
<UFormField label="Textarea" name="textarea">
<UTextarea v-model="state.textarea" class="w-full" />
</UFormField>

<UFormField name="radioGroup">
<URadioGroup v-model="state.radioGroup" legend="Radio group" :items="items" />
</UFormField>

<div class="flex gap-4">
<UFormField name="radioGroup">
<URadioGroup v-model="state.radioGroup" legend="Radio group" :items="items" />
</UFormField>
<UFormField name="checkboxGroup">
<UCheckboxGroup v-model="state.checkboxGroup" legend="Checkbox group" :items="items" />
</UFormField>
</div>
<UFormField name="pin" label="Pin Input" :error-pattern="/(pin)\..*/">
<UPinInput v-model="state.pin" />
</UFormField>
Expand Down
309 changes: 309 additions & 0 deletions docs/content/3.components/checkbox-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
---
title: CheckboxGroup
description: A set of checklist buttons to select multiple option from a list.
category: form
links:
- label: CheckboxGroup
icon: i-custom-reka-ui
to: https://reka-ui.com/docs/components/checkbox#group-root
- label: GitHub
icon: i-simple-icons-github
to: https://github.com/nuxt/ui/tree/v3/src/runtime/components/CheckboxGroup.vue
---


## Usage

Use the `v-model` directive to control the value of the CheckboxGroup or the `default-value` prop to set the initial value when you do not need to control its state.

### Items

Use the `items` prop as an array of strings or numbers:

::component-code
Copy link
Member

@romhml romhml Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something wrong when you change the value by interacting with the example in the documentation:
image

Copy link
Author

@TribeWeb TribeWeb Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @romhml. I have not been able to get pnpm run docs to work at any stage of working on this (JS heap out of memory). Is there another way I can review the page so I can see the behaviour you've seen?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was caused by an invalid modelValue in the docs, I fixed it here: 7a7180c

---
prettier: true
ignore:
- modelValue
- items
external:
- items
- modelValue
externalTypes:
- CheckboxGroupItem[]
- CheckboxGroupValue
props:
modelValue:
- 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

You can also pass an array of objects with the following properties:

- `label?: string`{lang="ts-type"}
- `description?: string`{lang="ts-type"}
- [`value?: string`{lang="ts-type"}](#value-key)
- `disabled?: boolean`{lang="ts-type"}

::component-code
---
ignore:
- modelValue
- items
external:
- items
- modelValue
externalTypes:
- CheckboxGroupItem[]
- CheckboxGroupValue
props:
modelValue:
- 'system'
items:
- label: 'System'
description: 'This is the first option.'
value: 'system'
- label: 'Light'
description: 'This is the second option.'
value: 'light'
- label: 'Dark'
description: 'This is the third option.'
value: 'dark'
---
::

::caution
When using objects, you need to reference the `value` property of the object in the `v-model` directive or the `default-value` prop.
::

### Value Key

You can change the property that is used to set the value by using the `value-key` prop. Defaults to `value`.

::component-code
---
ignore:
- modelValue
- items
- valueKey
external:
- items
- modelValue
externalTypes:
- CheckboxGroupItem[]
- CheckboxGroupValue
props:
modelValue:
- 'light'
valueKey: 'id'
items:
- label: 'System'
description: 'This is the first option.'
id: 'system'
- label: 'Light'
description: 'This is the second option.'
id: 'light'
- label: 'Dark'
description: 'This is the third option.'
id: 'dark'
---
::

### Legend

Use the `legend` prop to set the legend of the CheckboxGroup.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
externalTypes:
- CheckboxGroupItem[]
props:
legend: 'Theme'
defaultValue: 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

### Color

Use the `color` prop to change the color of the CheckboxGroup.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
externalTypes:
- CheckboxGroupItem[]
props:
color: neutral
defaultValue: 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

### Variant :badge{label="Not released" class="align-text-top"}

Use the `variant` prop to change the variant of the CheckboxGroup.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
props:
color: 'primary'
variant: 'table'
defaultValue: 'pro'
items:
- label: 'Pro'
value: 'pro'
description: 'Tailored for indie hackers, freelancers and solo founders.'
- label: 'Startup'
value: 'startup'
description: 'Best suited for small teams, startups and agencies.'
- label: 'Enterprise'
value: 'enterprise'
description: 'Ideal for larger teams and organizations.'
---
::

### Size

Use the `size` prop to change the size of the CheckboxGroup.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
externalTypes:
- CheckboxGroupItem[]
props:
size: 'xl'
variant: 'list'
defaultValue: 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

### Orientation

Use the `orientation` prop to change the orientation of the CheckboxGroup. Defaults to `vertical`.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
externalTypes:
- CheckboxGroupItem[]
props:
orientation: 'horizontal'
variant: 'list'
defaultValue: 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

### Indicator :badge{label="Not released" class="align-text-top"}

Use the `indicator` prop to change the position or hide the indicator. Defaults to `start`.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
externalTypes:
- CheckboxGroupItem[]
props:
indicator: 'end'
variant: 'card'
defaultValue: 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

### Disabled

Use the `disabled` prop to disable the CheckboxGroup.

::component-code
---
prettier: true
ignore:
- defaultValue
- items
external:
- items
externalTypes:
- CheckboxGroupItem[]
props:
disabled: true
defaultValue: 'System'
items:
- 'System'
- 'Light'
- 'Dark'
---
::

## API

### Props

:component-props

### Slots

:component-slots

### Emits

:component-emits

## Theme

:component-theme

34 changes: 34 additions & 0 deletions docs/content/3.components/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,40 @@ props:
---
::

### Variant :badge{label="Not released" class="align-text-top"}

Use the `variant` prop to change the variant of the Checkbox.

::component-code
---
ignore:
- label
- defaultValue
props:
color: 'primary'
variant: 'table'
defaultValue: true
label: Check me
---
::

### Indicator :badge{label="Not released" class="align-text-top"}

Use the `indicator` prop to change the position or hide the indicator. Defaults to `start`.

::component-code
---
ignore:
- label
- defaultValue
props:
indicator: 'end'
variant: 'card'
defaultValue: true
label: Check me
---
::

### Size

Use the `size` prop to change the size of the Checkbox.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
"pnpm": {
"onlyBuiltDependencies": [
"better-sqlite3",
"puppeteer",
"sharp"
],
"ignoredBuiltDependencies": [
Expand Down
1 change: 1 addition & 0 deletions playground-vue/src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const components = [
'calendar',
'carousel',
'checkbox',
'checkbox-group',
'chip',
'collapsible',
'color-picker',
Expand Down
Loading
Loading