Migrating to Spectrum 2
An automated upgrade assistant is available by running the following command in the project you want to upgrade:
npx @react-spectrum/codemods s1-to-s2
To only upgrade specific components, provide a --components
argument with a comma-separated list of components to upgrade:
npx @react-spectrum/codemods s1-to-s2 --components=Button,TextField
The following arguments are also available:
--path
- Path to apply the upgrade changes to. Defaults to the current directory (.
)--dry
- Runs the upgrade assistant without making changes to components--ignore-pattern
- Ignore files that match the provided glob expression. Defaults to'**/node_modules/**'
For cases that the upgrade assistant doesn't handle automatically or where you'd rather upgrade some components manually, use the guide below.
Note that Pending indicates that future changes will occur before the final release, and the current solution should be considered temporary.
Components
All components
- Update imports to use the
@react-spectrum/s2
package instead of@adobe/react-spectrum
or individual packages like@react-spectrum/button
- Update style props to use the style macro instead. See the 'Style props' section below
Accordion
- Update
Item
to beDisclosure
.Disclosure
should now consist of two children:DisclosureTitle
andDisclosurePanel
. Note that you can now add interactive elements inside the header and adjacent to the title by using theDisclosureHeader
component with theDisclosureTitle
and interactive elements inside. - Update
Item
's title prop to be a child ofDisclosureTitle
- Update children of
Item
to be children ofDisclosurePanel
- Update
key
to beid
(and keepkey
if rendered insidearray.map
) - Remove
disabledKeys
and addisDisabled
to individualDisclosure
components - Add
allowsMultipleExpanded
to allow multipleDisclosure
components to be expanded at once (previously default behavior)
ActionBar
- Remove
ActionBarContainer
and moveActionBar
torenderActionBar
prop ofTableView
orCardView
- Update
Item
toActionButton
- Update root level
onAction
to be called viaonPress
on eachActionButton
- Apply
isDisabled
directly on eachActionButton
orToggleButton
instead of root leveldisabledKeys
- Update
key
to beid
(and keepkey
if rendered insidearray.map
) - Convert dynamic collections render function to
items.map
- Pending Comment out
buttonLabelBehavior
(it has not been implemented yet)
ActionButton
No updates needed.
ActionMenu
- Pending Comment out
closeOnSelect
(it has not been implemented yet) - Pending Comment out
trigger
(it has not been implemented yet) - Update
Item
to be aMenuItem
ActionGroup
- Use
ActionButtonGroup
if you are migrating from anActionGroup
that didn't allow for selection.ActionButtonGroup
takesActionButtons
as children. - Use
ToggleButtonGroup
if you are migrating from anActionGroup
that used single or multiple selection.ToggleButtonGroup
takesToggleButtons
as children. - Pending Comment out
overflowMode
(it has not been implemented yet) - Pending Comment out
buttonLabelBehavior
(it has not been implemented yet) - Pending Comment out
summaryIcon
(it has not been implemented yet) - Update root level
onAction
to called viaonPress
on eachActionButton
- Apply
isDisabled
directly on eachActionButton
orToggleButton
instead of root leveldisabledKeys
- Update
key
to beid
(and keepkey
if rendered insidearray.map
) - Convert dynamic collections render function to
items.map
AlertDialog
No updates needed.
Avatar
- Pending Comment out
isDisabled
(it has not been implemented yet) - Update
size
to be a pixel value if it currently matches'avatar-size-*'
Badge
- Change
variant="info"
tovariant="informative"
Breadcrumbs
- Pending Comment out
showRoot
(it has not been implemented yet) - Pending Comment out
isMultiline
(it has not been implemented yet) - Pending Comment out
autoFocusCurrent
(it has not been implemented yet) - Remove
size="S"
(Small is no longer a supported size in Spectrum 2) - Update
Item
to be aBreadcrumb
Button
- Change
variant="cta"
tovariant="accent"
- Change
variant="overBackground"
tovariant="primary" staticColor="white"
- Change
style
tofillStyle
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - If
href
is present, theButton
should be converted to aLinkButton
- Remove
elementType
(it is no longer supported in Spectrum 2)
ButtonGroup
No updates needed.
Calendar
No updates needed.
Checkbox
No updates needed.
CheckboxGroup
- Remove
showErrorIcon
(it has been removed due to accessibility issues)
ColorArea
- Remove
size
and instead provide a size via the style macro (i.e.styles={style({size: 20})}
)
ColorField
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Remove
placeholder
(it has been removed due to accessibility issues) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
ColorSlider
- Remove
showValueLabel
(it has been removed due to accessibility issues)
ColorSwatch
No updates needed.
ColorWheel
- Remove
size
and instead provide a size via the style macro (i.e.styles={style({size: 20})}
)
ComboBox
- Change
menuWidth
value from aDimensionValue
to a pixel value - Remove
isQuiet
(it is no longer supported in Spectrum 2) - Remove
placeholder
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2) - Update
Item
to be aComboBoxItem
DateField
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
DatePicker
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
DateRangePicker
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
Dialog
- Update children to move render props from being the second child of
DialogTrigger
to being a child ofDialog
- Remove
onDismiss
and useonOpenChange
on theDialogTrigger
, oronDismiss
on theDialogContainer
instead Dialog
is now meant specifically for rendering modal dialogs only and follows the same preset layout as before- If you are trying to create a dialog with a custom layout use
CustomDialog
- If you are trying to create a fullscreen dialog use
FullscreenDialog
- If you are trying to create a popover dialog use
Popover
- Supports
isKeyboardDismissDisabled
in place ofDialogTrigger
- Supports
isDismissible
in place ofDialogTrigger
. Note the fixed spelling from previousisDismissible
prop. - Supports
role: "dialog" | "alertdialog"
DialogContainer
- Remove
type
, this is dependent on the dialog level child that you use (e.g.Dialog
,FullscreenDialog
,Popover
) - Remove
isDismissable
, prop now exists on the dialog level component asisDismissible
- Remove
isKeyboardDismissDisabled
, prop now exists on the dialog level component
DialogTrigger
- Pending Comment out
type="tray"
(Tray
has not been implemented yet) - Pending Comment out
mobileType
(Tray
and other types have not been implemented yet forPopover
) - Remove
targetRef
(it is no longer supported in Spectrum 2) - Update
children
to remove render props usage, and note that theclose
function was moved fromDialogTrigger
toDialog
- Remove
containerPadding
, prop now exists on thePopover
component - Remove
crossOffset
, prop now exists on thePopover
component - Remove
hideArrow
, prop now exists on thePopover
component - Remove
isDismissable
, prop now exists on the dialog level component asisDismissible
- Remove
isKeyboardDismissDisabled
, prop now exists on the dialog level component - Remove
offset
, prop now exists on thePopover
component - Remove
placement
, prop now exists on thePopover
component - Remove
shouldFlip
, prop now exists on thePopover
component - Remove
type
, this is dependent on the dialog level child that you use (e.g.Dialog
,FullscreenDialog
,Popover
)
Divider
- Remove Divider component if within a Dialog (Updated design for Dialog in Spectrum 2)
Flex
- Update
Flex
to be adiv
and apply flex styles using the style macro (i.e.<div className={style({display: 'flex'})} />
)
Form
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Remove
isReadOnly
(it is no longer supported in Spectrum 2) - Remove
validationState
(it is no longer supported in Spectrum 2) - Remove
validationBehavior
(it is no longer supported in Spectrum 2)
Grid
- Update
Grid
to be adiv
and apply grid styles using the style macro (i.e.<div className={style({display: 'grid'})} />
)
IllustratedMessage
- Update illustrations to be from
@react-spectrum/s2/illustrations
. See Illustrations
InlineAlert
- Change
variant="info"
tovariant="informative"
Item
- If within
Menu
: UpdateItem
to be aMenuItem
- If within
ActionMenu
: UpdateItem
to be aMenuItem
- If within
TagGroup
: UpdateItem
to be aTag
- If within
Breadcrumbs
: UpdateItem
to be aBreadcrumb
- If within
Picker
: UpdateItem
to be aPickerItem
- If within
ComboBox
: UpdateItem
to be aComboBoxItem
- If within
ListBox
: UpdateItem
to be aListBoxItem
- If within
TabList
: UpdateItem
to be aTab
- If within
TabPanels
: UpdateItem
to be aTabPanel
and remove surroundingTabPanels
- Update
key
to beid
(and keepkey
if rendered insidearray.map
)
Link
- Change
variant="overBackground"
tostaticColor="white"
- If
a
was used insideLink
(legacy API), remove thea
and apply props (i.ehref
) directly toLink
ListBox
- Update
Item
to be aListBoxItem
Menu
- Update
Item
to be aMenuItem
MenuTrigger
- Pending Comment out
closeOnSelect
(it has not been implemented yet)
NumberField
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
Picker
- Change
menuWidth
value from aDimensionValue
to a pixel value - Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2) - Update
Item
to be aPickerItem
- Change
isLoading
toloadingState
and provide the appropriate loading state.
ProgressBar
- Change
variant="overBackground"
tostaticColor="white"
- Pending Comment out
labelPosition
(it has not been implemented yet) - Pending Comment out
showValueLabel
(it has not been implemented yet)
ProgressCircle
- Change
variant="overBackground"
tostaticColor="white"
Radio
No updates needed.
RadioGroup
- Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2) - Remove
showErrorIcon
(it has been removed due to accessibility issues)
RangeCalendar
No updates needed.
RangeSlider
- Remove
showValueLabel
(it has been removed due to accessibility issues) - Pending Comment out
getValueLabel
(it has not been implemented yet) - Pending Comment out
orientation
(it has not been implemented yet)
SearchField
- Remove
placeholder
(it has been removed due to accessibility issues) - Pending Comment out icon (it has not been implemented yet)
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
Section
- If within
Menu
: UpdateSection
to be aMenuSection
- If within
Picker
: UpdateSection
to be aPickerSection
Slider
- Remove
isFilled
(Slider is always filled in Spectrum 2) - Remove
trackGradient
(Not supported in S2 design) - Remove
showValueLabel
(it has been removed due to accessibility issues) - Pending Comment out
getValueLabel
(it has not been implemented yet) - Pending Comment out
orientation
(it has not been implemented yet)
StatusLight
- Remove
isDisabled
(it is no longer supported in Spectrum 2) - Change
variant="info"
tovariant="informative"
SubmenuTrigger
No updates needed.
Switch
No updates needed.
TableView
- For
Column
andRow
: Updatekey
to beid
(and keepkey
if rendered insidearray.map
) - For dynamic tables, pass a
columns
prop intoRow
- For
Row
: Update dynamic render function to pass incolumn
instead ofcolumnKey
- Move
loadingState
andonLoadMore
fromTableBody
toTableView
- Pending Comment out
UNSTABLE_allowsExpandableRows
(it has not been implemented yet) - Pending Comment out
UNSTABLE_onExpandedChange
(it has not been implemented yet) - Pending Comment out
UNSTABLE_expandedKeys
(it has not been implemented yet) - Pending Comment out
UNSTABLE_defaultExpandedKeys
(it has not been implemented yet)
Tabs
- Inside
TabList
: UpdateItem
to beTab
- Update
items
onTabs
to be onTabList
- Inside
TabPanels
: UpdateItem
to be aTabPanel
and remove the surroundingTabPanels
- Remove
isEmphasized
(it is no longer supported in Spectrum 2) - Remove
isQuiet
(it is no longer supported in Spectrum 2)
TagGroup
- Rename
actionLabel
togroupActionLabel
- Rename
onAction
toonGroupAction
- Change
validationState="invalid"
toisInvalid
- Update
Item
to beTag
TextArea
- Pending Comment out
icon
(it has not been implemented yet) - Remove
isQuiet
(it is no longer supported in Spectrum 2) - Remove
placeholder
(it has been removed due to accessibility issues) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
TextField
- Pending Comment out
icon
(it has not been implemented yet) - Remove
isQuiet
(it is no longer supported in Spectrum 2) - Remove
placeholder
(it has been removed due to accessibility issues) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
TimeField
- Remove
isQuiet
(it is no longer supported in Spectrum 2) - Change
validationState="invalid"
toisInvalid
- Remove
validationState="valid"
(it is no longer supported in Spectrum 2)
ToggleButton
No updates needed.
Tooltip
- Remove
variant
(it is no longer supported in Spectrum 2) - Remove
placement
and add to the parentTooltipTrigger
instead - Remove
showIcon
(it is no longer supported in Spectrum 2) - Remove
isOpen
and add to the parentTooltipTrigger
instead
TooltipTrigger
- Update placement prop to have one value (i.e. Update
placement="bottom left"
to beplacement="bottom"
)
TreeView
If migrating from TreeView version 3.0.0-beta.3 or before, please do the following. Otherwise, no updates needed.
- Update content within
TreeViewItem
to be wrapped inTreeViewContentItem
View
- Update
View
to be adiv
and apply styles using the style macro
Well
Update Well
to be a div
and apply styles using the style macro:
<div className={style({
display: 'block',
textAlign: 'start',
padding: 16,
minWidth: 160,
marginTop: 4,
borderWidth: 1,
borderRadius: 'sm',
borderStyle: 'solid',
borderColor: 'transparent-black-75',
font: 'body-sm'
})} />
Style props
React Spectrum v3 supported a limited set of style props for layout and positioning using Spectrum-defined values. Usage of these should be updated to instead use the style macro.
Border width
Affected style props: borderWidth
, borderStartWidth
, borderEndWidth
, borderTopWidth
, borderBottomWidth
, borderXWidth
, borderYWidth
.
Border widths should be updated to use pixel values. Use the following mappings:
Spectrum 1 | Spectrum 2 |
---|---|
'none' | 0 |
'thin' | 1 |
'thick' | 2 |
'thicker' | 4 |
'thickest' | '[8px]' |
Border radius
Affected style props: borderRadius
, borderTopStartRadius
, borderTopEndRadius
, borderBottomStartRadius
, borderBottomEndRadius
.
Border radius values should be updated to use pixel values. Use the following mappings:
Spectrum 1 | Spectrum 2 |
---|---|
'xsmall' | '[1px]' |
'small' | 'sm' |
'regular' | 'default' |
'medium' | 'lg' |
'large' | 'xl' |
Dimension values
Affected style props: width
, minWidth
, maxWidth
, height
, minHeight
, maxHeight
, margin
, marginStart
, marginEnd
, marginTop
, marginBottom
, marginX
, marginY
, top
, bottom
, left
, right
, start
, end
, flexBasis
, gap
, columnGap
, rowGap
, padding
, paddingX
, paddingY
, paddingStart
, paddingEnd
, paddingTop
, paddingBottom
.
Dimension values should be converted to pixel values. Use the following mappings:
Spectrum 1 | Spectrum 2 |
---|---|
'size-0' | 0 |
'size-10' | 1 |
'size-25' | 2 |
'size-40' | 3 |
'size-50' | 4 |
'size-65' | 5 |
'size-75' | 6 |
'size-85' | 7 |
'size-100' | 8 |
'size-115' | 9 |
'size-125' | 10 |
'size-130' | 11 |
'size-150' | 12 |
'size-160' | 13 |
'size-175' | 14 |
'size-200' | 16 |
'size-225' | 18 |
'size-250' | 20 |
'size-275' | 22 |
'size-300' | 24 |
'size-325' | 26 |
'size-350' | 28 |
'size-400' | 32 |
'size-450' | 36 |
'size-500' | 40 |
'size-550' | 44 |
'size-600' | 48 |
'size-675' | 54 |
'size-700' | 56 |
'size-800' | 64 |
'size-900' | 72 |
'size-1000' | 80 |
'size-1200' | 96 |
'size-1250' | 100 |
'size-1600' | 128 |
'size-1700' | 136 |
'size-2000' | 160 |
'size-2400' | 192 |
'size-3000' | 240 |
'size-3400' | 272 |
'size-3600' | 288 |
'size-4600' | 368 |
'size-5000' | 400 |
'size-6000' | 480 |
'static-size-0' | 0 |
'static-size-10' | 1 |
'static-size-25' | 2 |
'static-size-40' | 3 |
'static-size-50' | 4 |
'static-size-65' | 5 |
'static-size-100' | 8 |
'static-size-115' | 9 |
'static-size-125' | 10 |
'static-size-130' | 11 |
'static-size-150' | 12 |
'static-size-160' | 13 |
'static-size-175' | 14 |
'static-size-200' | 16 |
'static-size-225' | 18 |
'static-size-250' | 20 |
'static-size-300' | 24 |
'static-size-400' | 32 |
'static-size-450' | 36 |
'static-size-500' | 40 |
'static-size-550' | 44 |
'static-size-600' | 48 |
'static-size-700' | 56 |
'static-size-800' | 64 |
'static-size-900' | 72 |
'static-size-1000' | 80 |
'static-size-1200' | 96 |
'static-size-1700' | 136 |
'static-size-2400' | 192 |
'static-size-2600' | 208 |
'static-size-3400' | 272 |
'static-size-3600' | 288 |
'static-size-4600' | 368 |
'static-size-5000' | 400 |
'static-size-6000' | 480 |
'single-line-height' | 32 |
'single-line-width' | 192 |
Break points
Break points previously used in style props can be used in the style macro with updated keys. Use the following mappings:
Spectrum 1 | Spectrum 2 |
---|---|
base | default |
S | sm |
M | md |
L | lg |