fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Checkbox: Hitting <Enter> doesn't toggle it

Open HalcyonPride opened this issue 7 years ago • 7 comments

Environment Information

  • Package version(s): Whatever's the latest
  • Browser and OS versions: Tested in Chrome and Edge

Please provide a reproduction of the bug in a codepen:

https://developer.microsoft.com/en-us/fabric#/components/checkbox

Actual behavior:

Hitting Enter does nothing.

Expected behavior:

Hitting Enter should toggle the Checkbox.

Priorities and help requested:

Are you willing to submit a PR to fix? No

Requested priority: High

Products/sites affected: Any product that uses Fabric.

HalcyonPride avatar Apr 04 '19 18:04 HalcyonPride

I could've sworn this used to work... It might be a regression.

HalcyonPride avatar Apr 04 '19 18:04 HalcyonPride

I could've sworn this used to work... It might be a regression.

Possibly, tho its worth mentioning that native input type="checkbox" only toggles on SPACE not ENTER, https://jsfiddle.net/kevintcoughlin/ry8tc2ks/.

KevinTCoughlin avatar Apr 04 '19 18:04 KevinTCoughlin

The checkbox did indeed used to be toggle-able via the enter key, in version 6.121 - PR #7521 changed CheckBox to use <input type="checkbox"> instead of button, which as @KevinTCoughlin mentioned only toggles on spacebar and not enter.

@cliffkoh should the refactored CheckBox (which uses input) also be toggled on enter?

kkjeer avatar Apr 04 '19 18:04 kkjeer

Hitting enter to toggle checkbox is non-standard and in particular, the behavior in the prior checkbox was a source of bugs like https://github.com/OfficeDev/office-ui-fabric-react/issues/6811.

If it is important to support the enter key, here are some codepens with examples of how you can re-introduce it: https://codepen.io/dzearing/pen/PVEpye?editors=0010

cliffkoh avatar Apr 04 '19 19:04 cliffkoh

p.s. the fact that the checkbox used to be able to be toggled with enter key was an unintentional side-effect of the checkbox previously being implemented via a button. A button was initially chosen for the implementation by others on the team purely because it was deemed to be more stylable (but even at that point, it was a somewhat contentious choice).

It turned out to be a poor choice however as it resulted in a bunch of intractable bugs with the accessibility and behavior because it behaves in a non-standard way compared to <input type="checkbox">

cliffkoh avatar Apr 04 '19 19:04 cliffkoh

Big ups to all the responses in this thread! 🙌 Now that I know about the <input> thing, I concur with the 'By Design' resolution and will close this issue. Thank you all!

HalcyonPride avatar Apr 06 '19 00:04 HalcyonPride

Hi @kkjeer, could you please help me remove the "Needs: Attention" tag as well? 😅

HalcyonPride avatar Jun 12 '19 22:06 HalcyonPride