errorBorderColor & focusBorderColor couldn't be set using semantic tokens
See original GitHub issueDescription
By using the semantic tokens feature introduced in v1.8+, I’m unable to set the focusBorderColor, or errorBorderColor properties to components like Input etc. I’m using Next.JS v12
Link to Reproduction
https://codesandbox.io/s/compassionate-cray-e534ez?file=/src/index.js
Steps to reproduce
_app.js
: (Theme setup)
import { extendTheme, ChakraProvider } from '@chakra-ui/react'
const theme = extendTheme({
semanticTokens: {
colors: {
primary: {
default: "red.200",
_light: "red.500",
},
},
},
})
export default function MyApp({ Component, pageProps }) {
return (
<ChakraProvider resetCSS theme={theme}>
<Component {...pageProps} />
</ChakraProvider>
)
}
login.js
: (Doesn’t work)
...
<Input
type="text"
focusBorderColor="primary"
/>
...
- Tentative Solution :
...
<Input
type="text"
focusBorderColor="red.200"
_light={{
_focus: {
borderColor: "red.500",
},
}}
/>
...
Chakra UI Version
1.8.3
Browser
Google Chrome v98.0.4
Operating System
- macOS
- Windows
- Linux
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
How to change border color of textarea on :focus
Probably a more appropriate way of changing outline color is using the outline-color CSS rule.
Read more >VS Code API | Visual Studio Code Extension API
VS Code API is a set of JavaScript APIs that you can invoke in your Visual Studio Code extension. This page lists all...
Read more >Changelog | PSPDFKit for Web
Fixes an error “The timestamp token couldn't be parsed” that may appear ... Adds the ability to select any color using the native...
Read more >Design Tokens beyond colors, typography, and spacing.
In recent months, I couldn't help but notice how many people (and companies) when referring to “design tokens” what they actually mean is...
Read more >The JavaScript Anthology 101 Essential Tips, Tricks & Hacks ...
For each menu, we'll create a core navigation structure using clean, semantic code. Then, we'll improve on each script with usability and accessibility...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
tldr;
It is currently not possible to use semantic tokens in
focusBorderColor
anderrorBorderColor
. A workaround is to extend the theme, which is quite a lot code: See CodeSandboxLong explanation
The theme styles for the Input component uses
getColor
to retrieve the color value from the theme:https://github.com/chakra-ui/chakra-ui/blob/27eec8de744d05eef5bcbd2de651f3a37370ff2c/packages/theme/src/components/input.ts#L98-L106
The semantic tokens rely heavily on CSS variables, which can change with a CSS media query or selector like our dark mode selector. Here is an example of the implementation detail:
Because of the ambiguity of semantic tokens it is not possible to retrieve an actual color value for it.
Proposed Solution or API
The theme needs a new mechanism to retrieve theme tokens which should replace the usage of
getColor()
in the theme object.This way we would be able to reference every token and semantic token in the theme, e.g.:
This is the way I’m doing now. Nice. Thanks!