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

Prevent accidental miss-clicks outside multi-select checkboxes #1700

Closed
wants to merge 1 commit into from

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Sep 6, 2024

We have experienced (and more people has reported) that it is easy to miss-click outside a checkbox on a MultiSelect option. This is problematic, because clicking on a checkbox appends/removes the item to the selection, but clicking outside of it is captured as a click on the main option's body, causing the whole selection to be replaced with just that option.

multi-select-current-2024-09-06_11.00.31.mp4

This PR changes that behavior, so that clicking on "the surroundings" of the checkbox behaves as clicking the checkbox itself.

"The surroundings" in this case means anywhere inside the right side of the option, matching the option's padding. That way the checkbox is always clicked if you click anywhere on the "right" of an option.

This shows how it behaves with these changes:

multi-select-fixed-2024-09-06_11.13.12.mp4

Note

This PR is easier to review ignoring whitespaces

Todo

  • Make checkbox slightly bigger. This was previously done via scale-125.

'-m-2.5 p-2.5 border border-transparent',
// The checkbox is sized based on the container's font size. Make
// it a bit larger.
'text-xl',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The checkbox was previously enlarged via scale-125, but that conflicts now with the margin and padding added here.

Increasing the font size was always the right approach.

@acelaya acelaya marked this pull request as ready for review September 6, 2024 09:17
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5976906) to head (93abdbe).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1700   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           66        66           
  Lines         1115      1121    +6     
  Branches       435       439    +4     
=========================================
+ Hits          1115      1121    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acelaya acelaya force-pushed the multi-select-checkbox-fix branch 2 times, most recently from 4edaf9c to 6818b76 Compare September 6, 2024 10:29
@acelaya acelaya marked this pull request as draft September 6, 2024 10:35
@acelaya
Copy link
Contributor Author

acelaya commented Sep 6, 2024

I just tested this in the dashboard and realized this solution does not work if the option has multiple lines, so I'm putting it back in draft while I think in something else.

@acelaya
Copy link
Contributor Author

acelaya commented Sep 6, 2024

I just tested this in the dashboard and realized this solution does not work if the option has multiple lines, so I'm putting it back in draft while I think in something else.

I addressed this by using position absolute and zero top and bottom. That way it will always adapt to any height.

EDIT: But that has other side effects I didn't consider:

Grabacion.de.pantalla.desde.2024-09-06.14-45-06.webm

@acelaya acelaya marked this pull request as ready for review September 6, 2024 12:43
@acelaya acelaya marked this pull request as draft September 6, 2024 12:44
Comment on lines +204 to +208
<div className="flex items-center">
{optionChildren(children, { selected, disabled })}
</div>
{!multiple && (
<CheckIcon
className={classnames('text-grey-6 scale-125', {
// Make the icon visible/invisible, instead of conditionally
// rendering it, to ensure consistent spacing among selected and
// non-selected options
'opacity-0': !selected,
})}
/>
)}
{multiple && (
<div
className={classnames('scale-125', {
'text-grey-6': selected,
'text-grey-3 hover:text-grey-6': !selected,
})}
>
<Checkbox
checked={selected}
checkedIcon={CheckboxCheckedFilledIcon}
elementRef={checkboxRef}
onChange={toggleValue}
onKeyDown={e => {
if (e.key === 'ArrowLeft') {
e.preventDefault();
optionRef.current?.focus();
}
}}
<div className="flex items-center">
Copy link
Contributor Author

@acelaya acelaya Sep 6, 2024

Choose a reason for hiding this comment

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

Since the wrapper is now items-stretch instead of items-center, every element that is now rendered inside of it needs to define its own flex container with items-center, so that everything is visually centered, while the checkbox wrapper (the label) is actually 100% tall, without having to use absolute containers, which have other side effects.

@acelaya
Copy link
Contributor Author

acelaya commented Sep 6, 2024

I just tested this in the dashboard and realized this solution does not work if the option has multiple lines, so I'm putting it back in draft while I think in something else.

I addressed this by using position absolute and zero top and bottom. That way it will always adapt to any height.

EDIT: But that has other side effects I didn't consider:

Grabacion.de.pantalla.desde.2024-09-06.14-45-06.webm

I moved back to a non-absolute-position approach, which has less side effects.

Now the option container is flex items-stretch, ensuring all items are as high as the taller one. Then every element defines a wrapper of its own with flex items-center so that visually the contents are still vertically aligned.

@acelaya acelaya marked this pull request as ready for review September 6, 2024 13:27
@acelaya acelaya marked this pull request as draft September 9, 2024 08:06
@acelaya
Copy link
Contributor Author

acelaya commented Sep 9, 2024

I'm putting this back in draft, as in retrospect, the work I did on this and different attempts I mentioned above, made me realize there might be an easier way to achieve the same.

Since now every "group" inside the option has its own flex container, we could remove the padding from the parent entirely, and then set individual paddings to every group where appropriate.

I'll give that a try and then decide if this is still relevant.

@acelaya
Copy link
Contributor Author

acelaya commented Sep 9, 2024

Closeing in favor of #1704

@acelaya acelaya closed this Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant