Skip to content

Commit

Permalink
Adds 'inactive' state to buttons (#3812)
Browse files Browse the repository at this point in the history
* adds inactive state to button components

* update snapshots

* adds changeset

* test(vrt): update snapshots

* Update src/Button/ButtonBase.tsx

Co-authored-by: Katie Langerman <18661030+langermank@users.noreply.github.com>

* follow-up on resolving merge conflicts

* adds new button style for inactive buttons

* refactors inactive styles, lets disabled style override inactive style

* adds docs for 'inactive' prop

* upgrades styled components, fixes hover and active style bugs on inactive buttons

* fix drafts/Button2 inactive implementation

* cursor style tweak, update snapshots, update package-lock.json

* test(vrt): update snapshots

* upgrades @primer/primitives

* test next primitives release

* upgrades @primer/primitives to 7.15.3

* updates jest snaps

* test(vrt): update snapshots

* rm disabled styles

* preserves border on inactive buttons

* test(vrt): update snapshots

---------

Co-authored-by: mperrotti <mperrotti@users.noreply.github.com>
Co-authored-by: Katie Langerman <18661030+langermank@users.noreply.github.com>
Co-authored-by: Eric Bailey <ericwbailey@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 5, 2023
1 parent debf495 commit 3f82a1c
Show file tree
Hide file tree
Showing 26 changed files with 341 additions and 56 deletions.
7 changes: 7 additions & 0 deletions .changeset/soft-pans-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': minor
---

Adds an 'inactive' state to buttons. An inactive button looks disabled and has aria-disabled, but it can still be clicked and focused. This was added to support buttons that are broken due to availability issues, but can't be removed from the page.

<!-- Changed components: Button, Button2, IconButton -->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions e2e/components/Button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,40 @@ test.describe('Button', () => {
}
})

test.describe('Inactive', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-button-features--inactive',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Button.Inactive.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-button-features--inactive',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})

test.describe('Dev: Invisible Variants', () => {
for (const theme of themes) {
test.describe(theme, () => {
Expand Down
56 changes: 28 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"@oddbird/popover-polyfill": "^0.3.1",
"@primer/behaviors": "^1.5.1",
"@primer/octicons-react": "^19.8.0",
"@primer/primitives": "^7.11.11",
"@primer/primitives": "7.15.3",
"@react-aria/ssr": "^3.5.0",
"@styled-system/css": "^5.1.5",
"@styled-system/props": "^5.1.5",
"@styled-system/theme-get": "^5.1.2",
Expand Down
5 changes: 5 additions & 0 deletions src/Button/Button.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"type": "React.ElementType",
"description": "A visual to display after the button text."
},
{
"name": "inactive",
"type": "boolean",
"description": "Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button.\n This is intended to be used when a system error such as an outage prevents the button from performing its usual action.\n Inactive styles are slightly different from disabled styles because inactive buttons need to have an accessible color contrast ratio. This is because inactive buttons can have tooltips or perform an action such as opening a dialog explaining why it's inactive.\n If both `disabled` and `inactive` are true, `disabled` takes precedence."
},
{
"name": "as",
"type": "React.ElementType",
Expand Down
6 changes: 6 additions & 0 deletions src/Button/Button.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export const Block = () => <Button block>Default</Button>

export const Disabled = () => <Button disabled>Default</Button>

export const Inactive = () => (
<Button variant="primary" inactive>
Default
</Button>
)

export const Small = () => <Button size="small">Default</Button>

export const Medium = () => <Button size="medium">Default</Button>
Expand Down
6 changes: 6 additions & 0 deletions src/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Playground.argTypes = {
type: 'boolean',
},
},
inactive: {
control: {
type: 'boolean',
},
},
variant: {
control: {
type: 'radio',
Expand All @@ -51,6 +56,7 @@ Playground.args = {
block: false,
size: 'medium',
disabled: false,
inactive: false,
variant: 'default',
alignContent: 'center',
trailingVisual: null,
Expand Down
2 changes: 2 additions & 0 deletions src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ButtonBase = forwardRef(
size = 'medium',
alignContent = 'center',
block = false,
inactive,
...rest
} = props

Expand Down Expand Up @@ -68,6 +69,7 @@ const ButtonBase = forwardRef(
data-block={block ? 'block' : null}
data-size={size === 'small' || size === 'large' ? size : undefined}
data-no-visuals={!LeadingVisual && !TrailingVisual && !TrailingAction ? true : undefined}
data-inactive={inactive ? true : undefined}
>
{Icon ? (
<Icon />
Expand Down
5 changes: 5 additions & 0 deletions src/Button/IconButton.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"defaultValue": "",
"description": "Changes the size of the icon button component"
},
{
"name": "inactive",
"type": "boolean",
"description": "Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button."
},
{
"name": "icon",
"type": "Component",
Expand Down
6 changes: 6 additions & 0 deletions src/Button/IconButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Playground.argTypes = {
type: 'boolean',
},
},
inactive: {
control: {
type: 'boolean',
},
},
variant: {
control: {
type: 'radio',
Expand All @@ -34,6 +39,7 @@ Playground.argTypes = {
Playground.args = {
size: 'medium',
disabled: false,
inactive: false,
variant: 'default',
'aria-label': 'Icon button description',
icon: XIcon,
Expand Down
Loading

0 comments on commit 3f82a1c

Please sign in to comment.