To add the Button
, LinkButton
, or LoadingButton
component to your app:
1 2import { Button } from "@forge/react";
1 2import { LinkButton } from "@forge/react";
1 2import { LoadingButton } from "@forge/react";
A button triggers an event or action. They let users know what will happen next.
Name | Type | Required | Description |
---|---|---|---|
autoFocus | boolean | No | Set the button to autofocus on mount. |
isDisabled | boolean | No | Disable the button to prevent user interaction. |
isSelected | boolean | No | Indicates that the button is selected. |
onBlur | (e: BlurEvent) => void | No | Handler to be called on blur. |
onClick | (e: MouseEvent ) => void | No | Handler to be called on click. The second argument can be used to track analytics data. |
onFocus | (e: FocusEvent) => void | No | Handler to be called on focus. |
spacing | 'compact' | 'default' | No | Controls the amount of padding in the button. |
shouldFitContainer | boolean | No | Option to fit button width to its parent width. |
type | 'submit' | 'reset' | 'button' | No | Pass type down to a button. |
The Button
accepts all common props as well as the additional props below.
Name | Type | Required | Description |
---|---|---|---|
appearance | 'default' | 'danger' | 'primary' | 'subtle' | 'warning' | No | The button style variation. |
iconAfter | IconGlyph | No | Places an icon within the button, after the button's text. |
iconBefore | IconGlyph | No | Places an icon within the button, before the button's text. |
The LinkButton
accepts all common props (except for type
) as well as the additional props below.
Name | Type | Required | Description |
---|---|---|---|
href | string | Yes | The prop |
target | '_self' | '_blank' | '_parent' | '_top' | No | Specifies where the link content opens when clicked. |
appearance | 'default' | 'danger' | 'primary' | 'subtle' | 'warning' | No | The button style variation. |
The LoadingButton
accepts all common props as well as the additional props below.
Name | Type | Required | Description |
---|---|---|---|
isLoading | boolean | No | Conditionally shows a spinner over the top of a button. |
appearance | 'default' | 'danger' | 'link'| 'primary' | 'subtle' | 'subtle-link' | 'warning' | No | The button style variation. |
Use default buttons for most actions that aren't the main call to action for a page or area. Default buttons are less prominent than primary buttons.
1 2const ButtonDefaultExample = () => { return <Button>Default button</Button>; };
Use a primary button to call attention to a form submission or to highlight the most important call to action on a page. Primary buttons should only appear once per area, though not every screen needs a primary button.
1 2const ButtonPrimaryExample = () => { return <Button appearance="primary">Primary button</Button>; };
Use a subtle button with a primary button for secondary actions, such as “Cancel.”
1 2const ButtonSubtleExample = () => { return <Button appearance="subtle">Subtle button</Button>; };
Warning buttons confirm actions that may cause a significant change or a loss of data.
Typically, warnings alert people of a problem that might happen if they proceed. These appearances are often found in confirmation modals.
1 2const ButtonWarningExample = () => { return <Button appearance="warning">Warning button</Button>; };
A danger button appears as a final confirmation for a destructive and irreversible action, such as deleting.
1 2const ButtonDangerExample = () => { return <Button appearance="danger">Danger button</Button>; };
The default form of a link button.
1 2const LinkButtonExample = () => { return <LinkButton href="https://atlassian.com/">Link button</LinkButton>; };
Standard buttons use the disabled
HTML attribute, however this doesn't exist for anchor <a>
tags, so link buttons are disabled by adding aria-disabled="true"
, adding role="link"
and removing the href
attribute.
1 2const LinkButtonDisabledExample = () => { return ( <LinkButton href="https://atlassian.com/" appearance="primary" isDisabled> Disabled link button </LinkButton> ); };
Set isDisabled
to disable a button that shouldn't be actionable. The button will appear faded and won't respond to user interaction.
Disabled buttons can cause accessibility issues (disabled elements are not in the tab order) so wherever possible, avoid using isDisabled
. Instead, use validation or other techniques to show users how to proceed.
1 2const ButtonDisabledExample = () => { return ( <Button appearance="primary" isDisabled> Disabled button </Button> ); };
Set isSelected
to indicate the button is selected.
1 2const ButtonSelectedExample = () => { return <Button isSelected>Selected button</Button>; };
Use the loading button and set isLoading
to indicate the button is loading. The button text is hidden and a spinner is shown in its place, while maintaining the width that it would have if the text were visible.
1 2const ButtonLoadingExample = () => { return ( <LoadingButton appearance="primary" isLoading> Loading button </LoadingButton> ); };
Button spacing depends on the surrounding UI. Default spacing is used for most use cases, compact
for tables.
1 2import { ButtonGroup, Button } from "@forge/react"; const ButtonPaddingExample = () => { return ( <ButtonGroup> <Button appearance="primary">Default</Button> <Button appearance="primary" spacing="compact"> Compact </Button> </ButtonGroup> ); };
Buttons can expand to full width to fill the parent container. This is sometimes done in login forms.
1 2const ButtonFullWidthExample = () => { return ( <Button shouldFitContainer appearance="primary"> Full width button </Button> ); };
Buttons may include an icon before or after the text label. Valid icons can be found in the Atlassian Design System Icon Library.
Extract the glyph
segment of the icon's import to get the valid icon name to pass into iconBefore
or iconAfter
(eg. @atlaskit/icon/glyph/star-filled
-> star-filled
is a valid icon name).
1 2const ButtonIconBefore = () => { return ( <Button appearance="primary" iconBefore="star-filled" > Icon before </Button> ); };
1 2const ButtonIconAfter = () => { return ( <Button appearance="primary" iconAfter="star-filled" > Icon after </Button> ); };
When using the Button
, LinkButton
, and LoadingButton
components, we recommend keeping the following accessibility considerations in mind:
Avoid disabling buttons, especially in forms. Instead, keep the button pressable, and use validation and errors to explain what needs to be done to proceed.
Disabled buttons don’t explain why the button isn’t usable. They also aren’t reachable in the tab order and don’t receive hover, focus, or click events, making them entirely inaccessible to some people.
Tooltips can't be reached on all devices or by some assitive technologies, and they should never appear on elements that aren't interactable.
Things to consider before using a tooltip:
Rate this page: