Skip to main content

Migrate Button from Polaris React

Replace Polaris React Button with s-button. Decide first whether the call site performs an action, submits a form, navigates, downloads a file, or opens another component.


Anchor to Migrate a primary actionMigrate a primary action

This example preserves the button's hierarchy, label, and click behavior. Replace the imported Polaris React icon component with the documented Polaris web-component icon name.

Migrating a primary action with an icon

export function AddProductButton({onAddProduct}) {
return (
<s-button variant="primary" icon="plus" onClick={onAddProduct}>
Add product
</s-button>
);
}
import {Button} from '@shopify/polaris';
import {PlusIcon} from '@shopify/polaris-icons';

export function AddProductButton({onAddProduct}) {
return (
<Button variant="primary" icon={PlusIcon} onClick={onAddProduct}>
Add product
</Button>
);
}

Preview


Anchor to Replace Button propertiesReplace Button properties

Polaris ReactPolaris web componentsMigration notes
onClickonClickGuard duplicate async requests in app logic.
submittype="submit"Keep the button inside its native form.
urlhrefUse s-link for inline navigation; use button styling only when the hierarchy calls for it.
external and targettarget, commonly _blankPreserve a real href; don't emulate navigation in onClick.
downloaddownload with hrefTest the actual response and filename.
loadingloadingKeep it true for the complete request and prevent repeat submission in app state.
disableddisabledExplain unavailable prerequisites visibly; disabled controls aren't focusable.
variant="primary"variant="primary"Keep one clear primary action for the current scope.
Plain or low-emphasis variantsvariant="tertiary"Re-evaluate hierarchy instead of copying appearance names.
tone="critical" or destructivetone="critical"Use for destructive actions that are difficult to reverse.
iconA documented icon name string in iconRemove Polaris React icon imports.
iconOnly or no visible texticon plus accessibilityLabelName the action, not the icon.
disclosureA trigger with commandFor pointing to s-menu or s-popoverLet the destination overlay own open and close state.
pressedUse the control that matches the state, such as s-switch or a choice fieldDon't use an action button as a persistent setting.
fullWidthinlineSize="fill"Let the button fill the available inline size only when the containing layout calls for it.
size, textAlign, and monochromeContaining layout and destination hierarchyRemove appearance-only compatibility props.

Anchor to Handle actions safelyHandle actions safely

Set loading before awaiting an operation, keep the label specific, and show success or failure feedback. Don't clear form values or navigate until persistence succeeds. For destructive changes, confirm scope in a modal and keep the critical action there.

Use commandFor when the button opens an s-menu, s-popover, s-modal, or another command target. Keep the target as a sibling with a stable id; don't retain React state that only opened the Polaris overlay.


  • Exercise enabled, disabled, loading, success, failure, and retry states.
  • Submit with pointer, keyboard, and Enter from the form.
  • Test internal links, external links, modified clicks, and downloads.
  • Verify icon-only labels and focus order.
  • Confirm destructive actions show the correct scope and can't run twice.

Anchor to Remove Polaris ReactRemove Polaris React

Remove Button, Polaris icon imports, disclosure state, and prop adapters after each call site is migrated. Remove @shopify/polaris only after no other route in scope imports it.



Was this page helpful?