Skip to content

Conversation

@TribeWeb
Copy link
Contributor

@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
@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 11, 2025

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

commit: 6fa0ada

{{ 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
Contributor 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
@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!

@benjamincanac
Copy link
Member

So I've made quite a few changes, would you mind having a look?

@benjamincanac benjamincanac requested a review from romhml April 22, 2025 12:42
@benjamincanac benjamincanac removed the enhancement New feature or request label Apr 22, 2025
@benjamincanac benjamincanac merged commit 9c3d53a into nuxt:v3 Apr 22, 2025
5 checks passed
@benjamincanac
Copy link
Member

Thanks @TribeWeb! 😊

@druskacik
Copy link

Is there a way to style the labels of the checkboxes? This does not work in version https://pkg.pr.new/@nuxt/ui@3862:

<UCheckboxGroup v-model="selectedCountriesValue" :items="selectedCountriesItems" @change="emitFilters">
    <template #label="{ item }">
      <span class="italic">
        {{ item.label }}
      </span>
    </template>
  </UCheckboxGroup>

@TribeWeb
Copy link
Contributor Author

TribeWeb commented Apr 23, 2025

Is there a way to style the labels of the checkboxes? This does not work in version https://pkg.pr.new/@nuxt/ui@3862:

<UCheckboxGroup v-model="selectedCountriesValue" :items="selectedCountriesItems" @change="emitFilters">
    <template #label="{ item }">
      <span class="italic">
        {{ item.label }}
      </span>
    </template>
  </UCheckboxGroup>

Good spot @druskacik!

@benjamincanac - I have a potential fix:
To add the template/slots into CheckboxGroup.vue as below.
Should I make another pull request?

<UCheckbox
    v-for="item in normalizedItems"
    :key="item.value"
    v-bind="{ ...item, ...checkboxProps }"
    :color="color"
    :size="size"
    :name="name"
    :disabled="item.disabled || disabled"
>
    <template #label>
        <slot name="label" :item="item">
            {{ item.label }}
        </slot>
    </template>
    <template #description>
        <slot name="description" :item="item">
            {{ item.description }}
        </slot>
    </template>
</UCheckbox>

Copy link
Member

@TribeWeb We've indeed forgot to proxy the slots as well as the ui prop!

Copy link
Member

@TribeWeb @druskacik Should be fixed with bc06185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 #1289

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UCheckbox array support

5 participants