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

ButtonGroup: Fix button and icon button styling when tooltips are used on them #4371

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
784d775
Explore wrapping button group items with a div to simplify css selection
broccolinisoup Mar 8, 2024
49784c9
fix type
broccolinisoup Mar 8, 2024
2ac0412
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Mar 13, 2024
6a50500
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Apr 5, 2024
2f70a76
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Apr 22, 2024
13fff82
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup May 8, 2024
2c8af92
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup May 27, 2024
1ff84fd
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Jun 27, 2024
4ce67b2
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Jul 1, 2024
5dcd503
fix stroybook type
broccolinisoup Jul 1, 2024
d71ae30
remove button group util tests from deprecated button
broccolinisoup Jul 1, 2024
d4eda64
linting
broccolinisoup Jul 1, 2024
43e8e49
make it a forward ref component
broccolinisoup Jul 1, 2024
94c66fa
rest and ref on the parent element not the children
broccolinisoup Jul 2, 2024
7abb1be
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Jul 3, 2024
9496530
Add e2e tests
broccolinisoup Jul 3, 2024
e3b2d82
test(vrt): update snapshots
broccolinisoup Jul 3, 2024
eab4812
disable tooltip animations on playwright
broccolinisoup Jul 3, 2024
7c962bf
test(vrt): update snapshots
broccolinisoup Jul 4, 2024
52c4828
disable animations
broccolinisoup Jul 4, 2024
8842661
test(vrt): update snapshots
broccolinisoup Jul 5, 2024
c9415df
Merge branch 'main' into explore-wrapping-button-group-items
broccolinisoup Jul 8, 2024
ea8b026
use unsafeDisableTooltip prop for iconbuttons and remove explicit too…
broccolinisoup Jul 8, 2024
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
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.
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.
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.
256 changes: 256 additions & 0 deletions e2e/components/ButtonGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,260 @@ test.describe('ButtonGroup', () => {
})
}
})

test.describe('Icon Buttons with Tooltip', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-features--icon-buttons-with-tooltip',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Icon Buttons with Tooltip.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-features--icon-buttons-with-tooltip',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Links with Tooltip', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-features--links-with-tooltip',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Links with Tooltip.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-features--links-with-tooltip',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Button and Link with Tooltip 1', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--button-and-link-with-tooltip-1',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Button and Link with Tooltip 1.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--button-and-link-with-tooltip-1',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Button and Link with Tooltip 2', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--button-and-link-with-tooltip-2',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Button and Link with Tooltip 2.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--button-and-link-with-tooltip-2',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Icon Buttons with Tooltip 1', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--icon-buttons-with-tooltip-1',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Icon Buttons with Tooltip 1.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--icon-buttons-with-tooltip-1',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Link and Button with Tooltip 1', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--link-and-button-with-tooltip-1',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Link and Button with Tooltip 1.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--link-and-button-with-tooltip-1',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Link and Button with Tooltip 2', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--link-and-button-with-tooltip-2',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Link and Button with Tooltip 2.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--link-and-button-with-tooltip-2',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Links with Tooltip 1', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--links-with-tooltip-1',
globals: {
colorScheme: theme,
},
})

// Default state
// focus on the first button to make sure the tooltip is visible
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ButtonGroup.Links with Tooltip 1.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-buttongroup-devonly--links-with-tooltip-1',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
100 changes: 100 additions & 0 deletions packages/react/src/ButtonGroup/ButtonGroup.dev.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React from 'react'
import type {Meta} from '@storybook/react'
import ButtonGroup from './ButtonGroup'
import {Button, IconButton} from '../Button'
import {PlusIcon, DashIcon, CopilotIcon} from '@primer/octicons-react'
import {Tooltip as TooltipV2} from '../drafts'
import {Box, Tooltip, ThemeProvider, BaseStyles} from '..'

const meta: Meta<typeof ButtonGroup> = {
title: 'Components/ButtonGroup/DevOnly',
component: ButtonGroup,
decorators: [
Story => {
// Add some padding to the wrapper box to make sure tooltip v1 is always in the viewport
return (
<ThemeProvider>
<BaseStyles>
<Box padding={5}>{Story()}</Box>
</BaseStyles>
</ThemeProvider>
)
},
],
}

export default meta

export const IconButtonsWithTooltip1 = () => (
<ButtonGroup>
<Tooltip text="Add" direction="s">
<IconButton icon={PlusIcon} aria-label="Add" />
</Tooltip>
<Tooltip text="Subtract" direction="s">
<IconButton icon={DashIcon} aria-label="Subtract" />
</Tooltip>
</ButtonGroup>
)

export const LinksWithTooltip1 = () => (
<ButtonGroup>
<Tooltip text="Additonal text for link 1" direction="s">
<Button as="a" href="https://primer.style">
Sample Link 1
</Button>
</Tooltip>
<Tooltip text="Additonal text for link 2" direction="s">
<Button as="a" href="https://primer.style">
Sample Link 2
</Button>
</Tooltip>
</ButtonGroup>
)

export const LinkAndButtonWithTooltip1 = () => (
<ButtonGroup sx={{pl: 2}}>
<Tooltip text="Additional info">
<Button as="a" href="https://primer.style">
Link
</Button>
</Tooltip>
<Tooltip text="Open GitHub Copilot chat" direction="s">
<IconButton icon={CopilotIcon} aria-label="Open GitHub Copilot chat" />
</Tooltip>
</ButtonGroup>
)

export const ButtonAndLinkWithTooltip1 = () => (
<ButtonGroup sx={{pl: 2}}>
<Tooltip text="Open GitHub Copilot chat" direction="se">
<IconButton icon={CopilotIcon} aria-label="Open GitHub Copilot chat" />
</Tooltip>
<Tooltip text="Additional info about the link">
<Button as="a" href="https://primer.style">
Link
</Button>
</Tooltip>
</ButtonGroup>
)

export const LinkAndButtonWithTooltip2 = () => (
<ButtonGroup sx={{pl: 2}}>
<TooltipV2 text="Additional info about the link">
<Button as="a" href="https://primer.style">
Link
</Button>
</TooltipV2>
<IconButton icon={CopilotIcon} aria-label="Open GitHub Copilot chat" unsafeDisableTooltip={false} />
</ButtonGroup>
)

export const ButtonAndLinkWithTooltip2 = () => (
<ButtonGroup sx={{pl: 2}}>
<IconButton icon={CopilotIcon} aria-label="Open GitHub Copilot chat" unsafeDisableTooltip={false} />
<TooltipV2 text="Additional info about the link">
<Button as="a" href="https://primer.style">
Link
</Button>
</TooltipV2>
</ButtonGroup>
)
Loading
Loading