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

fix(SelectableCard): make label clickable by removing pointer events to none #4870

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

matthprost
Copy link
Collaborator

@matthprost matthprost commented Mar 10, 2025

Summary

Type

  • Bug

Summarise concisely:

What is expected?

Current SelectableCard is hard to test especially when you try to click on the label. This was due to the pointer-events: none; set on checkbox and radio in order to avoid having double state change.

I fixed this issue by no triggering the event 2 times when the click is specifically on the label / input. This way we only generate one change and we don't need to add pointer-events: none;. I also needed to change to add an extra layer of style inside SelectableCard for Checkbox and Radio as we remove pointer events. We don't want the hover effects etc.

I have also reformatted internal testing to test both checkbox and radio on the same series of tests as both should work the same.

Before this was not working, it now works.

    test(`should trigger onChange when click on the label`, async () => {
        const onChange = vi.fn()

        renderWithTheme(
          <SelectableCard
            onChange={onChange}
            type={type}
            value="choice"
            label="test"
            name="test"
          >
            blabla
          </SelectableCard>,
        )

        const label = screen.getByLabelText('test')
        await userEvent.click(label)

        await waitFor(() => {
          expect(onChange).toHaveBeenCalled()
        })
      })

@matthprost matthprost added the bug Something isn't working label Mar 10, 2025
@matthprost matthprost requested a review from a team March 10, 2025 13:42
@matthprost matthprost self-assigned this Mar 10, 2025
@matthprost matthprost requested a review from johnrazeur as a code owner March 10, 2025 13:42
@matthprost matthprost removed the request for review from a team March 10, 2025 13:42
@matthprost matthprost requested a review from a team as a code owner March 10, 2025 13:42
@matthprost matthprost requested a review from johnrazeur March 10, 2025 13:42
@matthprost matthprost requested a review from lisalupi as a code owner March 10, 2025 13:42
Copy link

changeset-bot bot commented Mar 10, 2025

🦋 Changeset detected

Latest commit: a0d530a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@ultraviolet/ui Patch
@ultraviolet/form Patch
@ultraviolet/plus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.37%. Comparing base (9f43f59) to head (a0d530a).
Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4870      +/-   ##
==========================================
+ Coverage   89.30%   89.37%   +0.07%     
==========================================
  Files         234      234              
  Lines        8153     8180      +27     
  Branches     3697     3752      +55     
==========================================
+ Hits         7281     7311      +30     
+ Misses        872      869       -3     
Files with missing lines Coverage Δ
packages/ui/src/components/Checkbox/index.tsx 99.12% <100.00%> (ø)
packages/ui/src/components/Radio/index.tsx 98.00% <100.00%> (ø)
...ackages/ui/src/components/SelectableCard/index.tsx 96.12% <100.00%> (+3.96%) ⬆️
...ts/SelectableCardOptionGroup/components/Option.tsx 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 356fde9...a0d530a. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@matthprost matthprost merged commit c8f5887 into main Mar 10, 2025
55 checks passed
@matthprost matthprost deleted the fix/selectable-card branch March 10, 2025 14:24
@scaleway-bot scaleway-bot mentioned this pull request Mar 10, 2025
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

Successfully merging this pull request may close these issues.

4 participants