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
[Checkbox] Control still has the blue outline on focus, even wih focus-visible package applied #2234
Comments
It is also the case if you use |
Hi! |
Facing the same issue |
I was recently able to make this work as expected:
I'm using the |
I added these in my global theme and it works as expected.
|
Safari (the new IE) is supposed to support The world's most valuable company is always late to the party I needed to overwrite checkbox boxshadow so I ended up modifying @kdfriedman 's solution to /* using tailwind */
.chakra-radiobox__control[data-focus],
.chakra-checkbox__control[data-focus] {
@apply ring-2 ring-red-300 !important;
} |
Another workaround can be: <Checkbox
size="sm"
colorScheme="primary"
defaultIsChecked
css={`
> span:first-of-type {
box-shadow: unset;
}
`}
>
Random text
</Checkbox> |
The focus visible package just adds the polyfill for the focus visible css selector which indicates keyboard focus. In order to remove the box shadow you gotta do this <Checkbox _focusVisible={{ shadow: 'outline'}} _focus={{ shadow: 'none'}} /> to apply this globally add the following to your global styles '.js-focus-visible :focus:not(.focus-visible)': {
shadow: 'none',
}, |
Perhaps what's not clear is whether if this is intended or just a bug, or under which circumstances this is a bug. |
Thanks @Brettm12345. If you disable Chakra's CSS Reset, you do need to add this style manually. |
Im having the same issue with switch, radio button and checkbox. However it does work on button. I have tried the suggestions above but nothing has worked. Has anyone else faced this? When trying some of these work arounds I was playing around in dev tools and it looks like it works when forcing element state but does not work without doing that. |
In chakra component such as Checkbox and Radio, input element is hidden and styled by custom elements. They have the data-focus attribute, so the following code probably work. const GlobalStyles = css`
/*
https://github.com/WICG/focus-visible#2-update-your-css
This will hide the focus indicator if the element receives focus via the mouse,
but it will still show up on keyboard focus.
*/
.js-focus-visible :focus:not(.focus-visible),
.js-focus-visible :focus:not(.focus-visible) + [data-focus] {
outline: none;
box-shadow: none;
}
` |
For those who would rather not keep the fix in their code, I've included it as a theme extension into a library of mine of Chakra helpers. Not particularly advocating using random people's libraries in your projects, but just saying it's there ;) |
Thanks, this worked! :) |
For anyone still having this issue. Kindly use the workaround suggested above. |
Another option if you want to set this globally in your theme: const theme = extendTheme({
components: {
Checkbox: {
baseStyle: {
control: {
_focus: {
boxShadow: 'none',
},
},
},
}
}
}); |
In the release logs of Chakra v2, I see a mention to a
Is it useful to solve this issue? Is there any documentation or example about it? |
dude, thank you so much |
Describe the bug
The checkbox square has a blue outline color when focused with mouse click, despite the focus-visible package being used.
To reproduce
npm i focus-visible
import "focus-visible/dist/focus-visible"
to_app.js
<Checkbox/>
elementExpected behavior
The blue outline should only be visible when using keyboard navigation, just like with Button etc.
System information
"@chakra-ui/core": "^1.0.0-rc.5",
"next": "9.5.3",
The text was updated successfully, but these errors were encountered: