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

Conversation

TribeWeb
Copy link

@TribeWeb TribeWeb commented Apr 11, 2025

πŸ”— Linked issue

Resolves #3050

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The UCheckbox component currently handles single instances of a checkbox only, returning a string. Being able to put several checkboxes together and returning an array is a common user requirement that has already been implemented in reka-ui but not yet in Nuxt UI. The new component builds on the reka example and adheres to the same patterns found in the existing URadioGroup component.

#3178 has added some beautiful and very useful styling for the URadioGroup component via the new table & card variants and so these same variants have been implemented in the new UCheckboxGroup component too.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@sandros94
Copy link
Member

sandros94 commented Apr 11, 2025

@benjamincanac you know I'm a super fan of this 😬 (#895)

EDIT: oh man, fall 2023, time flies...

@sandros94 sandros94 added v3 #1289 enhancement New feature or request labels Apr 11, 2025
Copy link

pkg-pr-new bot commented Apr 11, 2025

npm i https://pkg.pr.new/@nuxt/ui@3862

commit: 4980a65

{{ legend }}
</slot>
</legend>
<component :is="variant === 'list' ? 'div' : Label" v-for="item in normalizedItems" :key="item.value" :class="ui.item({ class: props.ui?.item })">
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not use the UCheckbox component here instead of re-implementing everything? πŸ€”

Copy link
Author

Choose a reason for hiding this comment

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

Good question! I started off with the intention of using the UCheckbox component. I felt that making the component as close to URadioGroup in structure was important to ensure consistency in behaviour in the new variants and how they applied to each component. As I proceeded, I became more confident I could achieve that aim by re-implementing instead. I'm willing to defer to your experience and refactor as suggested - this is my first pull request in any codebase so I'm more than happy to be guided.

Copy link
Member

Choose a reason for hiding this comment

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

We can left it like that I guess but I would share the theme between checkbox and checkbox-group though. The new variants should also be available on Checkbox.

You can check how textarea imports input theme for example.

@benjamincanac benjamincanac changed the title feat: New component - UCheckboxGroup feat(CheckboxGroup): new component Apr 12, 2025
@benjamincanac benjamincanac requested a review from romhml April 12, 2025 09:57
@benjamincanac benjamincanac requested a review from sandros94 April 13, 2025 09:16

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

@TribeWeb
Copy link
Author

TribeWeb commented Apr 17, 2025

Hi @romhml. I'm pretty happy with what I've just committed with a couple of caveats.

Good things:

  1. The theme is now shared between UCheckbox and UCheckboxGroup as suggested feat(CheckboxGroup): new componentΒ #3862 (comment)
  2. UCheckbox now has the table & card variants & I remembered to update the docs (although I still can't run them to check there's no mistakes)
  3. UCheckboxGroup uses the same strategy as useButtonGroup to share values that should be automatically passed without being exposed as props on UCheckbox.
  4. It all seems to work and hasn't changed the baseline UCheckbox API :)

Unresolved things:

  • 1. There is a huge <template v-if="..."> <template v-else> in UCheckbox but I don't know how to improve it without introducing a 3rd component. Any ideas?
    Resolved using vueUse - createReusableTemplate
  • 2. I don't know how to resolve the merge conflicts (below)
    I know how now...
  • 3. There are 4 tests in CheckboxGroup.spec.ts that are failing because the test needs tweaking and no matter what I try, I can't resolve them (I'm pretty sure the component is doing what it should). E.g. In a form, the label should have no for id value. I can see in the inspector that it doesn't have one (and have logged useFormField to see that bind: false is working as designed)

@romhml
Copy link
Member

romhml commented Apr 20, 2025

Thanks for all your work @TribeWeb! I'll try to check this out and fix the failing tests soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v3 #1289
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UCheckbox array support
4 participants