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

useCheckbox Hook does not provide keyboard accessibility #8358

Open
benmcginnis opened this issue Mar 13, 2024 · 5 comments
Open

useCheckbox Hook does not provide keyboard accessibility #8358

benmcginnis opened this issue Mar 13, 2024 · 5 comments

Comments

@benmcginnis
Copy link

It looks like the example custom checkbox does not work on the chakra docs for the useCheckbox hook: https://chakra-ui.com/docs/hooks/use-checkbox as you can see in this loom video: https://www.loom.com/share/6883977835f545ab9b9209168363f86b?sid=a035d499-8fd5-4967-be24-d9e98caa321e

Originally posted by @benmcginnis in #3491 (comment)

@benmcginnis
Copy link
Author

It also doesn't appear to support a focus state out of the box

@veloware
Copy link

I noticed the same recently with useRadio hook, I had to manually add tabIndex={0} and also handle the onClick and onMouseDown handlers

@erpatterson11
Copy link

I was able to restore keyboard accessibility by removing the hidden attribute on the input element (worked for useRadio() too). Not sure why this is in the docs.

You can set the focus state by adding _focusWithin={{ boxShadow: "outline" }} on the label.

@KubaZachacz
Copy link

KubaZachacz commented Mar 23, 2024

Yup, keyboard control is not working on Chakra docs for useRadioGroup and checkbox.
As said above you need to remove that hidden attribute from input, but you can also apply _focusVisible prop to that element which gets getRadioProps().

<chakra.label
      {...htmlProps}
      cursor="pointer"
      w="full"
      overflow="hidden"
      {...getLabelProps()}
    >
      <input {...getInputProps({})} />
      <Box
        {...getRadioProps()}
        w={'full'}
        _focusVisible={{
          boxShadow: 'outline',
        }}
      >
      ...
     </Box>
</chakra.label>

@Aa37573112
Copy link

Aa37573112 commented Mar 23, 2024 via email

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

No branches or pull requests

5 participants