Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds guidelines about inactive buttons #627

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion content/components/button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Buttons allow users to initiate an action or command when clicked or tapped. The
</Box>
</Box>

### Color
### Variants

<Box
mb={3}
Expand Down Expand Up @@ -234,6 +234,62 @@ Buttons allow users to initiate an action or command when clicked or tapped. The
</Box>
</Box>

### Inactive

<Box
mb={3}
display="flex"
alignItems="flex-start"
justifyContent="space-between"
flexDirection={['column', 'column', 'column', 'column', 'row']}
sx={{gap: 3}}
>

<img
width="456"
alt="An button that looks like a disabled primary button, but it has a focus state"
src="https://github.com/primer/design/assets/2313998/727ad1c2-3c14-4033-be2e-f6d7c856aa43"
/>

<div>

An inactive button has the same styles as a disabled button, but it still reponds to user input.

An inactive button an accessible alternative to a disabled button. They're intended to be used for buttons that are non-functional, but cannot be removed from the page.

Unlike a disabled button, an inactive button can respond to user input. For example, if a button shows a tooltip when hovered or focused, or a dialog when clicked.

If you need to use an inactive button, it's best to have something else on the page that informs users about the issue that broke the button's normal functionality. For example, showing a [global banner](/ui-patterns/degraded-experiences#global-system-notification) for service outages.

</div>

</Box>

<Box
display="flex"
alignItems="flex-start"
justifyContent="space-between"
flexDirection={['column', 'column', 'column', 'column', 'row']}
sx={{gap: 3}}
>

<CustomVideoPlayer
width="456"
loop
src="https://github.com/primer/design/assets/2313998/cc24059b-bad5-4e51-9415-b0ead51d2f80"
/>

<Box sx={{flexBasis: 0, flexGrow: 1}}>

There are two recommended ways an inactive button should respond to user input:

1. **Show a dialog on click:** When a user tries to activate an inactive the button, open a [dialog](/components/dialog) that explains why the action cannot be completed and give them a path forward if possible. It is required to provide some kind of feedback when a user clicks a button.
2. **Show a tooltip on hover or focus:** Before a user tries to activate a non-functional control, a [tooltip](/components/tooltip) with additional context may be displayed on hover or focus. It is *not* required to respond to hover and focus.

</Box>

</Box>

## Best practices

### Primary and outline button usage
Expand Down Expand Up @@ -349,6 +405,12 @@ Limit primary button usage. Only use one primary button on the page, whenever po

## Accessibility

### Do not disable buttons

There are rare cases where it's ok to disable a button, but it should generally be avoided. Disabling a button makes it invisible to assistive technologies such as screen readers.

For more information on disabled controls, see GitHub's [link and button a11y guidance](https://accessibility-playbook.github.com/link-and-button-guidance#disabling-links-and-buttons) (GitHub staff only).

### Descriptive buttons

Labeling buttons properly lets users know what will happen when they activate the control, lessens errors, and increases confidence.
Expand Down
40 changes: 4 additions & 36 deletions content/ui-patterns/degraded-experiences.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ Common types of page navigation include [underline nav](/components/underline-na

<img
width="960"
alt="Decision tree for how to handle a non-functional button. Could removing the button be disorienting? If no, don't render the button. If yes: does it respond to a hover or click? If yes, use an inert button. If no, use a disabled button."
src="https://github.com/primer/design/assets/2313998/4f93c6ef-0f0f-427b-b81c-2fdac957c9b3"
alt="Decision tree for how to handle a non-functional button. Could removing the button be disorienting? If no, don't render the button. If yes: does it respond to a hover or click? If yes, use an inactive button. If no, use a disabled button."
src="https://github.com/primer/react/assets/2313998/89a15946-ecc8-498b-a9e1-4802c3bc49b1"
/>

#### Removing a non-functional button
Expand Down Expand Up @@ -303,41 +303,9 @@ Default to removing non-functional buttons from the UI. Don't remove buttons tha

#### Indicating a button is non-functional without disabling it

<Box
mb={3}
display="flex"
alignItems="flex-start"
justifyContent="space-between"
flexDirection={['column', 'column', 'column', 'column', 'row']}
sx={{gap: 3}}
>

<div>

If a button is too critical to be omitted and responds to user input by showing more info about why it's non-functional, use an inert button. An inert button has the same styles as a disabled button, but it still reponds to user input.

An inert button is the accessible option because buttons may not be disabled if they respond to user input. For example, if a button shows a tooltip when hovered or focused, or a dialog when clicked.
If a button is too critical to be omitted and responds to user input by showing more info about why it's non-functional, use an inactive button.

</div>

<img
width="456"
alt="A default button and an inert button"
src="https://github.com/primer/design/assets/2313998/fd1a7c99-b8c3-43fd-9f74-ae509e9efa31"
/>

</Box>

There are two recommended ways an inert button should respond to user input:

1. **Show a dialog on click:** When a user tries to activate an inert the button, open a [dialog](/components/dialog) that explains why the action cannot be completed and give them a path forward if possible. It is required to provide some kind of feedback when a user clicks a button.
2. **Show a tooltip on hover or focus:** Before a user tries to activate a non-functional control, a [tooltip](/components/tooltip) with additional context may be displayed on hover or focus. It is *not* required to respond to hover and focus.

<CustomVideoPlayer
width="960"
loop
src="https://github.com/primer/design/assets/2313998/f7837087-a6ff-4572-9ef6-d5dfad158b88"
/>
For more information, see the the [inactive button guidelines](/components/button#inactive)

### Handling action menus with non-functional items

Expand Down
2 changes: 1 addition & 1 deletion content/ui-patterns/loading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ If non-sequential groups of navigation links are in a loading state, preserve th
src="https://github.com/primer/design/assets/2313998/1b619fa0-0870-4356-a5a6-78519a36f539"
/>

If some links in the right side sheet cannot be loaded, default to showing each [nav list](components/nav-list) item in an inert state. The users should still be able to hover, click, and focus inert items, but they don't link to anywhere. Optionally, a tooltip may be displayed explaining that the navigation item is unavailable. An error banner is not necessary for this case.
If some links in the right side sheet cannot be loaded, default to showing each [nav list](components/nav-list) item in an inactive state. The users should still be able to hover, click, and focus inactive items, but they don't link to anywhere. Optionally, a tooltip may be displayed explaining that the navigation item is unavailable. An error banner is not necessary for this case.

<Box
mb={3}
Expand Down
Loading