A simple guide to upgrade your existing Chakra UI projects to v1.0.
Chakra UI v1.0 is focused on improving the ideas and concepts from 0.x to make even easier to create, theme and extend components.
While there's quite a number of new features we've added, we focused on making Chakra UI a stable base to build your own design systems on top of. In the end, we want make you feel more confident using Chakra UI in production.
Theming API: Chakra UI now provides a new theming API which makes it easy to style components and their modifiers (sizes, variants, and color scheme) from your theme.
Color mode improvement: We've fixed the bugs related to Color mode and made it possible to persist color mode, set initial color mode, and lock specific components to a certain color mode.
Better TypeScript support: This means all components have very good
TypeScript support and most low-level components like Box
, Flex
will support
the as
prop and types will be extracted properly.
Theme-aware sx prop: Just like theme-ui
, we've added support for the sx
prop to help you add theme-aware styles directly on any Chakra component. This
is useful if you're not a fan of style props, and prefer passing all styles in
one object.
Deprecated PseudoBox: We've removed PseudoBox
and merged all it's props
with Box
so you can use pseudo style props, like _hover
, _active
in any
Chakra components.
Here's a list of steps to take in order to migrate your project safely. Don't worry if your styles aren't exactly the same — this is to be expected.
Chakra no longer requires @emotion/core
, @emotion/styled
and
emotion-theming
peer dependencies. If you're not using these libraries in your
code, you can safely remove them and update Chakra UI to v1.
Please note that when using Chakra UI in a TypeScript project, a minimum TypeScript version of
3.8.0
is required.
Chakra moved all icons to a separate package @chakra-ui/icons
. We recommend
using react-icons
in your projects considering it has a robust set of icons.
However, you can still install this package.
Swap out ThemeProvider
with ChakraProvider
to make setup cleaner.
ChakraProvider
adds the following providers for you automatically:
theme.styles.global
to your application.Optionally via prop:
CSSReset
, pass resetCSS={false}
.z-index
in your application. Pass the portalZIndex
prop.Fire up your "Find and Replace" tool in VSCode or IntelliJ. Find variantColor
and replace with colorScheme
.
Reason: We renamed this prop to make it easier to understand that this prop represents a visual color scheme, not a css color attribute.
size
prop#Change size
prop to width
or w
and height
, or h
. If you'd like to use
only one prop to manage this, you can rename it to boxSize
.
We strongly recommend using the width
and height
props
Reason: We think the
size
prop should only be used for component size modifiers. Thesize
prop has caused a lot of confusion in the past because, in some components (e.g. Button), it means the visual size and in others (e.g Box), it means width and height.
PseudoBox
is now deprecated and its props can now be directly applied to
Box
. Replace all PseudoBox
components with Box
.
You may safely skip this if you didn't customize your breakpoints.
To provide easier extensibility and typesafety, breakpoints should now be
created through createBreakpoints
by passing an object:
Please note that unless you plan overriding all components, sm
to xl
are
required.
You may of course add for example xxl
or other breakpoints in between -
createBreakpoints
will sort in ascending order. It is adviseable to not mix
css units.
Reason: Previously, breakpoints on a theme had to be an array with your breakpoints in ascending order which made it hard to reference which value was correlating to
md
etc. On top, you had to manually manipulate the array by defining properties on it, which was often overlooked and not typesafe.
You may safely skip this if you do not allow to change the color mode.
To keep color mode settings in sync across page visits, you will need to add the
ColorModeScript
.
For exhaustive examples, please visit Features > Color Mode # Add ColorModeScript.
We've updated the API of some components to fix bugs and improve usability, types and accessibility.
AccordionHeader
to AccordionButton
. This is to
remove the notion that it's a header when it's actually a button
.WAI-ARIA guidelines require that accordion buttons be wrapped in the appropriate heading tag
h2-h6
based on the page heading flow.
We think the name AccordionHeader
might mislead users to think we handle this
out of the box when we don't. Here's how to handle this:
AccordionItem
in isolation, it must be used within
Accordion
.AspectRatioBox
to AspectRatio
Removed support for the addSeparator
prop
leftIcon
or rightIcon
to the equivalent icon
React element.Replacement logic: If
leftIcon
is<EmailIcon/>
from Chakra.
This reduces the effort needed to use custom icons, eliminates TypeScript errors, and reduces unused icons bloating your app.
Renamed variantColor
to colorScheme
Removed negative side margins on leftIcon
and rightIcon
elements. We
believe the user should handle these side margins.
#1024
variantColor
to colorScheme
Deprecated the isFullWidth
prop. Checkbox
now takes up the width of the
parent by default.
To allow for better checkbox group layout, the CheckboxGroup
component no
longer supports every style prop.
You can now only pass size
, variant
, and colorScheme
in addition to
CheckboxGroup
-specific props (value
, defaultValue
, and onChange
).
We believe a checkbox group's layout should be managed by your design requirements. The checkboxes can be grouped using
Stack
, placed in a grid usingSimpleGrid
or made to wrap automatically usingWrap
.
Color mode now persists correctly when you refresh the page. All you need to
do is add ColorModeScript
script as the first child of body
.
Here's how to add it for Next.js:
Here's how to add it for Gatsby:
You can also install the
gatsby-plugin-chakra-ui
package which automatically configures ColorModeScript
along with
ChakraProvider
.
The onRequestEdit
prop has been renamed to onEdit
. This applies to both the
prop passed to Editable
as well as the prop in its render props.
Basic interface icons provided by Chakra have moved to the icons
package.
Replace all <Icon name="..." />
elements imported from core
with
equivalent named icon React elements imported from icons
.
Replacement logic: If
<Icon name="search" />
is used, then replace it with<SearchIcon />
from Chakra icons package.
Existing icons will appear as a question mark until refactored.
theme
create your own icons using the createIcon
utility:As a convenience you can also import createIcon
from the icons
package along
with other icons:
icon
to the equivalent icon React element.Replacement logic: If
icon
is<EmailIcon/>
from Chakra.
This reduces the effort needed to use custom icons, eliminates TypeScript errors, and reduces unused icons bloating your app.
variantColor
to colorScheme
Renamed colorStart
and colorEnd
props to startColor
and endColor
respectively.
Resolved SSR issue with Next.js. If you still run into issues, we recommend
using the Img
component which is a regular img
tag with support for Chakra
props.
InputAddon
, you no longer need to pass border radius properties
to the Input
. InputGroup
will intelligently detect the addon and apply the
necessary border to the input.Due to accessibility reasons, we've deprecated the isDisabled
prop for Link
.
isReversed
props in
favor of the direction
propdirection
and spacing
propsMenuList
component,
should now be passed to Menu
. Reason: To support nested menusplacement
prop has moved from MenuList
to Menu
Removed addAriaLabels
and formatIds
props in favor of passing a top-level
id
prop to the modal, and we'll handle the rest.
Removed preserveScrollBarGap
prop. We preserve scroll bar gap by default to
prevent any layout shift.
Wrap ModalContent
with the ModalOverlay
component.
Only pass size
values defined in the components theme. Hard-coded values
will be ignored. Update the styles in theme.components.Modal
to reflect your
custom values
You can now disable focus trap by passing trapFocus={false}
The SlideIn
and Scale
transition components have been replaced with the
Fade
, ScaleFade
, Slide
, and SlideFade
components.
color
prop to colorScheme
.trackColor
prop now takes a specific theme color or a valid css
color.thickness
prop to point to an actual thickness value in px
(e.g. thickness={4}
)variantColor
prop to colorScheme
.Deprecated the isFullWidth
prop. The Radio
takes up the width of the
parent by default.
Deprecated the RadioButton
component. Use the useRadio
hook to create
custom radio buttons. Learn more about
creating custom radio buttons.
The useRadio
hook is exported with state and focus management logic for use
in creating tailor-made radio component for your application
Deprecated the isFullWidth
prop. The RadioGroup
takes up the width of the
parent by default.
Deprecated the RadioButtonGroup
component. Use the useRadioGroup
hook to
control a group of custom radio buttons. Learn more about
creating custom radio buttons.
To allow for better Radio group layout, the RadioGroup
component no longer
supports every style prop. You can only pass size
, variant
, and
colorScheme
in addition to RadioGroup
props (value
, defaultValue
, and
onChange
).
SliderFilledTrack
with SliderTrack
.Rename the color
prop to colorScheme
Change variantColor
prop to colorScheme
variantColor
to colorScheme
isDisabled
prop on the TagCloseButton
componentmd
instead of lg
react-spring
dependency in favor of react-transition-group
toast.isActive
methodtoast.close
or toast.closeAll
methodstoast.update
method.onCloseComplete
prop, a callback function to run side
effects after the toast component has closed.config
prop, in favor of reading global styles from
theme.styles.global
focus-visible
in event you need to remove focus
styles for non-keyboard interactions.useDisclosure
now accepts object
instead of boolean
as initial valuesThat's it! Welcome to Chakra UI v1.
If you still experience issues after migrating, feel free to create an issue or join our Discord chat here: https://discord.gg/dQHfcWF