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/s2package instead of@adobe/react-spectrumor individual packages like@react-spectrum/button - Update style props to use the style macro instead. See the 'Style props' section below
Accordion
- Update
Itemto beDisclosure.Disclosureshould now consist of two children:DisclosureTitleandDisclosurePanel. Note that you can now add interactive elements inside the header and adjacent to the title by using theDisclosureHeadercomponent with theDisclosureTitleand interactive elements inside. - Update
Item's title prop to be a child ofDisclosureTitle - Update children of
Itemto be children ofDisclosurePanel - Update
keyto beid(and keepkeyif rendered insidearray.map) - Remove
disabledKeysand addisDisabledto individualDisclosurecomponents - Add
allowsMultipleExpandedto allow multipleDisclosurecomponents to be expanded at once (previously default behavior)
ActionBar
- Remove
ActionBarContainerand moveActionBartorenderActionBarprop ofTableVieworCardView - Update
ItemtoActionButton - Update root level
onActionto be called viaonPresson eachActionButton - Apply
isDisableddirectly on eachActionButtonorToggleButtoninstead of root leveldisabledKeys - Update
keyto beid(and keepkeyif 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
Itemto be aMenuItem
ActionGroup
- Use
ActionButtonGroupif you are migrating from anActionGroupthat didn't allow for selection.ActionButtonGrouptakesActionButtonsas children. - Use
ToggleButtonGroupif you are migrating from anActionGroupthat used single or multiple selection.ToggleButtonGrouptakesToggleButtonsas 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
onActionto called viaonPresson eachActionButton - Apply
isDisableddirectly on eachActionButtonorToggleButtoninstead of root leveldisabledKeys - Update
keyto beid(and keepkeyif 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
sizeto 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
Itemto be aBreadcrumb
Button
- Change
variant="cta"tovariant="accent" - Change
variant="overBackground"tovariant="primary" staticColor="white" - Change
styletofillStyle - Remove
isQuiet(it is no longer supported in Spectrum 2) - If
hrefis present, theButtonshould 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
sizeand 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) - 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
sizeand instead provide a size via the style macro (i.e.styles={style({size: 20})})
ComboBox
- Change
menuWidthvalue from aDimensionValueto 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
Itemto 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
DialogTriggerto being a child ofDialog - Remove
onDismissand useonOpenChangeon theDialogTrigger, oronDismisson theDialogContainerinstead Dialogis 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
isKeyboardDismissDisabledin place ofDialogTrigger - Supports
isDismissiblein place ofDialogTrigger. Note the fixed spelling from previousisDismissibleprop. - 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"(Trayhas not been implemented yet) - Pending Comment out
mobileType(Trayand other types have not been implemented yet forPopover) - Remove
targetRef(it is no longer supported in Spectrum 2) - Update
childrento remove render props usage, and note that theclosefunction was moved fromDialogTriggertoDialog - Remove
containerPadding, prop now exists on thePopovercomponent - Remove
crossOffset, prop now exists on thePopovercomponent - Remove
hideArrow, prop now exists on thePopovercomponent - 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 thePopovercomponent - Remove
placement, prop now exists on thePopovercomponent - Remove
shouldFlip, prop now exists on thePopovercomponent - 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
Flexto be adivand 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
Gridto be adivand 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: UpdateItemto be aMenuItem - If within
ActionMenu: UpdateItemto be aMenuItem - If within
TagGroup: UpdateItemto be aTag - If within
Breadcrumbs: UpdateItemto be aBreadcrumb - If within
Picker: UpdateItemto be aPickerItem - If within
ComboBox: UpdateItemto be aComboBoxItem - If within
ListBox: UpdateItemto be aListBoxItem - If within
TabList: UpdateItemto be aTab - If within
TabPanels: UpdateItemto be aTabPaneland remove surroundingTabPanels - Update
keyto beid(and keepkeyif rendered insidearray.map)
Link
- Change
variant="overBackground"tostaticColor="white" - If
awas used insideLink(legacy API), remove theaand apply props (i.ehref) directly toLink
ListBox
- Update
Itemto be aListBoxItem
Menu
- Update
Itemto 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
menuWidthvalue from aDimensionValueto 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
Itemto be aPickerItem - Change
isLoadingtoloadingStateand provide the appropriate loading state. - Update
defaultSelectedKeyandselectedKeyto bedefaultValueandvaluerespectively. See the Picker documentation for more details.
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
- 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: UpdateSectionto be aMenuSection - If within
Picker: UpdateSectionto 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
ColumnandRow: Updatekeyto beid(and keepkeyif rendered insidearray.map) - For dynamic tables, pass a
columnsprop intoRow - For
Row: Update dynamic render function to pass incolumninstead ofcolumnKey - Move
loadingStateandonLoadMorefromTableBodytoTableView - 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: UpdateItemto beTab - Update
itemsonTabsto be onTabList - Inside
TabPanels: UpdateItemto be aTabPaneland 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
actionLabeltogroupActionLabel - Rename
onActiontoonGroupAction - Change
validationState="invalid"toisInvalid - Update
Itemto beTag
TextArea
- 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)
TextField
- 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)
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
placementand add to the parentTooltipTriggerinstead - Remove
showIcon(it is no longer supported in Spectrum 2) - Remove
isOpenand add to the parentTooltipTriggerinstead
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
TreeViewItemto be wrapped inTreeViewContentItem
View
- Update
Viewto be adivand 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 |