Button API
Import
Section titled “Import”Cimpress UI exports several different button-related components. Use the version that’s appropriate for your use case.
Button: has a visible label, performs an actionLinkButton: has a visible label, performs navigationIconButton: has no visible label (icon-only), performs an actionIconLinkButton: has no visible label (icon-only), performs navigation
import { Button, IconButton, IconLinkButton, LinkButton } from '@cimpress-ui/react';Accessibility notes
Section titled “Accessibility notes”Button and IconButton can be activated by pressing Enter or Space, similar to a native HTML button.
LinkButton and IconLinkButton can be activated by pressing Enter, similar to a native HTML link.
IconButton and IconLinkButton should have an aria-label prop defined to identify the function of the button to assistive technologies. Button and IconButton in a loading state should have a loadingLabel prop defined to identify the loading state to assistive technologies. See our accessibility guide for more details.
Buttons with a variant="tertiary" prop have a transparent background. This variant should only be used on backgrounds that provide adequate contrast.
Client-side routing
Section titled “Client-side routing”LinkButton and IconLinkButton use the client-side router configured with RouterProvider.
If you need features from your router’s own link component, such as prefetching, use the render prop to render that component instead.
The render prop is ignored when the button is disabled with a reason, because a <button> element is rendered instead of a link.
See the client-side routing guide for details.
import NextLink from 'next/link';
<LinkButton href="/about" render={(props) => ('href' in props ? <NextLink {...props} prefetch /> : <span {...props} />)}> About</LinkButton>;API reference
Section titled “API reference”Button
Section titled “Button”Displays a labelled button that allows users to perform an action.
- Ref<HTMLButtonElement>
The
reftype for this component.
ButtonProps
- StringLikeChildren
children *
Section titled “children * ” The text displayed on the button.
- boolean | ({ reason: string })
isDisabled
Section titled “isDisabled” - Defaults to false .
Whether the button is disabled.
Optionally, you can provide an object with the
reasonproperty explaining why the button is disabled. This information will be shown to end-users as a tooltip or a popover. - 'primary' | 'secondary' | 'tertiary'
variant
Section titled “variant” - Defaults to 'secondary' .
Determines the visual appearance of the button.
- 'base' | 'critical'
- Defaults to 'base' .
Determines the color tone of the button.
- 'small' | 'medium' | 'large'
- Defaults to 'medium' .
The size of the button.
- boolean
fullWidth
Section titled “fullWidth” - Defaults to false .
Whether the button should take up the whole available width.
- ReactNode
iconStart
Section titled “iconStart” An icon displayed before the button text.
- ReactNode
iconEnd
Section titled “iconEnd” An icon displayed after the button text.
- boolean
isLoading
Section titled “isLoading” - Defaults to false .
Whether the button is in a loading state. This disables the button and replaces its contents with a spinner.
- string
loadingLabel
Section titled “loadingLabel” A string that identifies the loading state to assistive technologies. It will be announced by screen readers together with the button label. You must provide this prop if
isLoadingistrue.- string
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “data-cim-style-root” Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “UNSAFE_className” Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “UNSAFE_style” Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-label
Section titled “aria-label” Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “aria-labelledby” Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “aria-describedby” Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “aria-details” Identifies the element (or elements) that provide a detailed, extended description for the object.
- (e: HoverEvent) => void
onHoverStart
Section titled “onHoverStart” Handler that is called when a hover interaction starts.
- (e: HoverEvent) => void
onHoverEnd
Section titled “onHoverEnd” Handler that is called when a hover interaction ends.
- (e: PressEvent) => void
onPress
Section titled “onPress” Handler that is called when the press is released over the target.
- 'button' | 'reset' | 'submit'
- Defaults to 'button' .
The behavior of the button when used in an HTML form.
- string
The
<form>element to associate the button with. The value of this attribute must be the id of a<form>in the same document. See MDN.- string
Submitted as a pair with the button's value as part of the form data.
- string
The value associated with the button's name when it's submitted with the form data.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “margin” The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “marginX” The amount of margin applied to the left and right edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginY
Section titled “marginY” The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginTop
Section titled “marginTop” The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginRight
Section titled “marginRight” The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin.- Responsive<Spacing | "auto">
marginBottom
Section titled “marginBottom” The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginLeft
Section titled “marginLeft” The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
LinkButton
Section titled “LinkButton”Displays a labelled button that allows users to navigate to another page or resource.
- Ref<HTMLAnchorElement>
The
reftype for this component.
LinkButtonProps
- StringLikeChildren
children *
Section titled “children * ” The text displayed on the button.
- string
href *
Section titled “href * ” A URL to link to.
- boolean | ({ reason: string })
isDisabled
Section titled “isDisabled” - Defaults to false .
Whether the button is disabled.
Optionally, you can provide an object with the
reasonproperty explaining why the button is disabled. This information will be shown to the end-users as a tooltip or a popover. - (props: (DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>) | (DetailedHTMLProps<LinkWithRequiredHref, HTMLAnchorElement>), renderProps: LinkRenderProps) => ReactElement
render
Section titled “render” Renders a custom element, e.g. your router's link component. Render an
<a>if'href' in props, otherwise a<span>. Ignored when the button is disabled with a reason, as a<button>is rendered instead.- 'primary' | 'secondary' | 'tertiary'
variant
Section titled “variant” - Defaults to 'secondary' .
Determines the visual appearance of the button.
- 'base' | 'critical'
- Defaults to 'base' .
Determines the color tone of the button.
- 'small' | 'medium' | 'large'
- Defaults to 'medium' .
The size of the button.
- boolean
fullWidth
Section titled “fullWidth” - Defaults to false .
Whether the button should take up the whole available width.
- ReactNode
iconStart
Section titled “iconStart” An icon displayed before the button text.
- ReactNode
iconEnd
Section titled “iconEnd” An icon displayed after the button text.
- boolean
data-cim-style-root
Section titled “data-cim-style-root” Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “UNSAFE_className” Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “UNSAFE_style” Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-label
Section titled “aria-label” Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “aria-labelledby” Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “aria-describedby” Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “aria-details” Identifies the element (or elements) that provide a detailed, extended description for the object.
- undefined
routerOptions
Section titled “routerOptions” Options for the configured client side router.
- string
hrefLang
Section titled “hrefLang” Hints at the human language of the linked URL. SeeMDN.
- HTMLAttributeAnchorTarget
target
Section titled “target” The target window for the link. See MDN.
- string
The relationship between the linked resource and the current page. See MDN.
- string | boolean
download
Section titled “download” Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
- string
A space-separated list of URLs to ping when the link is followed. See MDN.
- HTMLAttributeReferrerPolicy
referrerPolicy
Section titled “referrerPolicy” How much of the referrer to send when following the link. See MDN.
- (e: HoverEvent) => void
onHoverStart
Section titled “onHoverStart” Handler that is called when a hover interaction starts.
- (e: HoverEvent) => void
onHoverEnd
Section titled “onHoverEnd” Handler that is called when a hover interaction ends.
- (e: PressEvent) => void
onPress
Section titled “onPress” Handler that is called when the press is released over the target.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “margin” The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “marginX” The amount of margin applied to the left and right edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginY
Section titled “marginY” The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginTop
Section titled “marginTop” The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginRight
Section titled “marginRight” The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin.- Responsive<Spacing | "auto">
marginBottom
Section titled “marginBottom” The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginLeft
Section titled “marginLeft” The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
IconButton
Section titled “IconButton”Displays an icon-only button that allows users to perform an action.
- Ref<HTMLButtonElement>
The
reftype for this component.
IconButtonProps
- ReactNode
icon *
Section titled “icon * ” The icon displayed on the button.
- string
aria-label *
Section titled “aria-label * ” The label describing the function of this button for assistive technologies.
- boolean | ({ reason: string })
isDisabled
Section titled “isDisabled” - Defaults to false .
Whether the button is disabled.
Optionally, you can provide an object with the
reasonproperty explaining why the button is disabled. This information will be shown to the end-users as a tooltip or a popover. - 'primary' | 'secondary' | 'tertiary'
variant
Section titled “variant” - Defaults to 'secondary' .
Determines the visual appearance of the button.
- 'base' | 'critical'
- Defaults to 'base' .
Determines the color tone of the button.
- 'small' | 'medium' | 'large'
- Defaults to 'medium' .
The size of the button.
- boolean
fullWidth
Section titled “fullWidth” - Defaults to false .
Whether the button should take up the whole available width.
- boolean
isLoading
Section titled “isLoading” - Defaults to false .
Whether the button is in a loading state. This disables the button and replaces its contents with a spinner.
- string
loadingLabel
Section titled “loadingLabel” A string that identifies the loading state to assistive technologies. It will be announced by screen readers together with the button label. You must provide this prop if
isLoadingistrue.- string
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “data-cim-style-root” Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “UNSAFE_className” Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “UNSAFE_style” Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-labelledby
Section titled “aria-labelledby” Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “aria-describedby” Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “aria-details” Identifies the element (or elements) that provide a detailed, extended description for the object.
- (e: HoverEvent) => void
onHoverStart
Section titled “onHoverStart” Handler that is called when a hover interaction starts.
- (e: HoverEvent) => void
onHoverEnd
Section titled “onHoverEnd” Handler that is called when a hover interaction ends.
- (e: PressEvent) => void
onPress
Section titled “onPress” Handler that is called when the press is released over the target.
- 'button' | 'reset' | 'submit'
- Defaults to 'button' .
The behavior of the button when used in an HTML form.
- string
The
<form>element to associate the button with. The value of this attribute must be the id of a<form>in the same document. See MDN.- string
Submitted as a pair with the button's value as part of the form data.
- string
The value associated with the button's name when it's submitted with the form data.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “margin” The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “marginX” The amount of margin applied to the left and right edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginY
Section titled “marginY” The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginTop
Section titled “marginTop” The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginRight
Section titled “marginRight” The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin.- Responsive<Spacing | "auto">
marginBottom
Section titled “marginBottom” The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginLeft
Section titled “marginLeft” The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
IconLinkButton
Section titled “IconLinkButton”Displays an icon-only button that allows users to navigate to another page or resource.
- Ref<HTMLAnchorElement>
The
reftype for this component.
IconLinkButtonProps
- ReactNode
icon *
Section titled “icon * ” The icon displayed on the button.
- string
aria-label *
Section titled “aria-label * ” The label describing the function of this button for assistive technologies.
- string
href *
Section titled “href * ” A URL to link to.
- boolean | ({ reason: string })
isDisabled
Section titled “isDisabled” - Defaults to false .
Whether the button is disabled.
Optionally, you can provide an object with the
reasonproperty explaining why the button is disabled. This information will be shown to the end-users as a tooltip or a popover. - (props: (DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>) | (DetailedHTMLProps<LinkWithRequiredHref, HTMLAnchorElement>), renderProps: LinkRenderProps) => ReactElement
render
Section titled “render” Renders a custom element, e.g. your router's link component. Render an
<a>if'href' in props, otherwise a<span>. Ignored when the button is disabled with a reason, as a<button>is rendered instead.- 'primary' | 'secondary' | 'tertiary'
variant
Section titled “variant” - Defaults to 'secondary' .
Determines the visual appearance of the button.
- 'base' | 'critical'
- Defaults to 'base' .
Determines the color tone of the button.
- 'small' | 'medium' | 'large'
- Defaults to 'medium' .
The size of the button.
- boolean
fullWidth
Section titled “fullWidth” - Defaults to false .
Whether the button should take up the whole available width.
- boolean
data-cim-style-root
Section titled “data-cim-style-root” Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “UNSAFE_className” Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “UNSAFE_style” Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-labelledby
Section titled “aria-labelledby” Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “aria-describedby” Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “aria-details” Identifies the element (or elements) that provide a detailed, extended description for the object.
- undefined
routerOptions
Section titled “routerOptions” Options for the configured client side router.
- string
hrefLang
Section titled “hrefLang” Hints at the human language of the linked URL. SeeMDN.
- HTMLAttributeAnchorTarget
target
Section titled “target” The target window for the link. See MDN.
- string
The relationship between the linked resource and the current page. See MDN.
- string | boolean
download
Section titled “download” Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
- string
A space-separated list of URLs to ping when the link is followed. See MDN.
- HTMLAttributeReferrerPolicy
referrerPolicy
Section titled “referrerPolicy” How much of the referrer to send when following the link. See MDN.
- (e: HoverEvent) => void
onHoverStart
Section titled “onHoverStart” Handler that is called when a hover interaction starts.
- (e: HoverEvent) => void
onHoverEnd
Section titled “onHoverEnd” Handler that is called when a hover interaction ends.
- (e: PressEvent) => void
onPress
Section titled “onPress” Handler that is called when the press is released over the target.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “margin” The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “marginX” The amount of margin applied to the left and right edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginY
Section titled “marginY” The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin.- Responsive<Spacing | "auto">
marginTop
Section titled “marginTop” The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginRight
Section titled “marginRight” The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin.- Responsive<Spacing | "auto">
marginBottom
Section titled “marginBottom” The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin.- Responsive<Spacing | "auto">
marginLeft
Section titled “marginLeft” The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.