primitives icon indicating copy to clipboard operation
primitives copied to clipboard

Add native checkbox element

Open Haberkamp opened this issue 2 years ago • 3 comments

Feature request

Overview

I'm creating this issue because it currently is not possible to change the state of the checkbox component when javascript is disabled. For example this allows these user to opt-out of something like a registration. Because this does not work I suggest that the button element should be swapped out with a native html checkbox element.

The html checkbox element also provides an indeterminate attribute to cover this case as well.

Examples in other libraries

The react library Mantine does this where they use an input element and add the type="checkbox" attribute to it.

Who does this impact? Who is this for?

This would be a break for users that either directly access the button element with Javascript via the DOM-API as well as for users that select the button element via css like:

.checkbox button {
  /* some styles */
}

Haberkamp avatar Apr 15 '22 12:04 Haberkamp

Hey @Haberkamp,

The fact it isn't a checkbox under the hood is an implementation detail that shouldn't matter. We do add a hidden native checkbox in cases where the checkbox is used in a form for example, but that's only to handle change events bubbling in forms.

I'm not clear what your issues are.

benoitgrelard avatar Apr 25 '22 10:04 benoitgrelard

it currently is not possible to change the state of the checkbox component when javascript is disabled

@benoitgrelard it sounds like another progressive enhancement request.

jjenzz avatar Apr 25 '22 13:04 jjenzz

@benoitgrelard it sounds like another progressive enhancement request.

Yes that exactly what I meant.

Haberkamp avatar Apr 29 '22 07:04 Haberkamp

Because of this reason when using react-hook-form and uncontrolled input - register returns On/Off instead of boolean

TomasSestak avatar Sep 23 '22 15:09 TomasSestak

The fact it isn't a checkbox under the hood is an implementation detail that shouldn't matter.

Why did you decide to implement a checkbox that isn't a checkbox under the hood, though? Just curious to hear the reasoning behind this decision. :)

henrik-stahl avatar Nov 16 '23 19:11 henrik-stahl

Because of this reason when using react-hook-form and uncontrolled input - register returns On/Off instead of boolean

Just because of this, I created my own CheckBox component. I can't think of a reasoning why On/Off are being used while a simple boolean could have suficed. I mean even indeterminate should be a false state and be controlled internally like any other component library solved

pixeliner avatar Jan 02 '24 19:01 pixeliner