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

Tooltip: Tooltip V2 as an experimental/draft with the new popover API #3394

Merged
merged 61 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2ae8d45
Tooltip remediations as an experimental
broccolinisoup May 29, 2023
a8aad6e
Update generated/components.json
broccolinisoup May 29, 2023
c01b61f
fix export path
broccolinisoup May 29, 2023
3b65cd2
popover with keith and top layer height experiment to accomodate ::be…
broccolinisoup Jun 8, 2023
f846b38
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Jun 23, 2023
13d3aa2
get rid of caret, align styling and update the API
broccolinisoup Jun 23, 2023
43db250
fix after stuff
broccolinisoup Jul 5, 2023
46630d4
add a calculated direction to properly position ::after relatively to…
broccolinisoup Jul 11, 2023
4b0dd7d
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Jul 20, 2023
49b2ca8
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Jul 24, 2023
cd1bd7f
clean up
broccolinisoup Jul 24, 2023
99469e1
add a story for a dotcom usage
broccolinisoup Jul 24, 2023
a8b8fb6
re organise stories and remove caret styles for now
broccolinisoup Jul 24, 2023
966bdf8
ewmove unused Box
broccolinisoup Jul 24, 2023
851a6c2
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Aug 2, 2023
1632030
css polyfill issues are resolved - huge thanks to Keith
broccolinisoup Aug 2, 2023
beeace0
update tests to reflect default direction s
broccolinisoup Aug 2, 2023
7091285
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Aug 7, 2023
69dbf4e
ActionMenu.Anchor tooltip - not the cleanest code
broccolinisoup Aug 9, 2023
067a09e
ActionMenu.Anchor and ActionMenu.Button with tooltip
broccolinisoup Aug 10, 2023
364d2ea
only type the child
broccolinisoup Aug 11, 2023
c64323f
fix type
broccolinisoup Aug 11, 2023
8b6da3e
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Aug 11, 2023
2b3bf14
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Aug 15, 2023
51f738f
use React.forwardRef and clean up impl for action menu anchor buttons
broccolinisoup Aug 15, 2023
8e7d406
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Aug 18, 2023
12e5bde
move tooltip from experimental to drafts
broccolinisoup Aug 22, 2023
e65ff6f
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Aug 22, 2023
abddbf5
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Sep 4, 2023
7c24bb0
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Sep 8, 2023
65ed0f9
export tooltip in draft
broccolinisoup Sep 8, 2023
6507faf
SSR friendly polyfill
broccolinisoup Sep 8, 2023
0fd9735
Resolve oddbird-polyfil module resolution issue - huge thanks to Josh
broccolinisoup Sep 13, 2023
7e37448
add e2e stories, clean up
broccolinisoup Sep 14, 2023
70d09dc
test(vrt): update snapshots
broccolinisoup Sep 14, 2023
ab7edcd
add changeset
broccolinisoup Sep 14, 2023
ed27858
test(vrt): update snapshots
broccolinisoup Sep 14, 2023
b2d30fb
update docs
broccolinisoup Sep 15, 2023
78a2f35
to revert later - just adding a test story to sgare
broccolinisoup Sep 15, 2023
14b7ecd
delete snapshots to regenerate them
broccolinisoup Sep 15, 2023
f2c4157
test(vrt): update snapshots
broccolinisoup Sep 15, 2023
f48a15f
Remove animations delays and noDelay prop
broccolinisoup Sep 18, 2023
782dbdf
reorganise vrt
broccolinisoup Sep 18, 2023
1849f61
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Sep 18, 2023
22a48bb
test(vrt): update snapshots
broccolinisoup Sep 18, 2023
ec44813
add threshold to snapshots
broccolinisoup Sep 19, 2023
3e0cb79
delete failed snapshots
broccolinisoup Sep 19, 2023
0c8c5e6
delete failed snapshots
broccolinisoup Sep 19, 2023
def9954
ActionMenu.Button children undefined at dotcom
broccolinisoup Sep 19, 2023
a9e8019
🔥 snapshots
broccolinisoup Sep 19, 2023
9527ea4
reorganise if logic in actionmenu
broccolinisoup Sep 19, 2023
8cd5ebd
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Sep 19, 2023
229c527
test(vrt): update snapshots
broccolinisoup Sep 19, 2023
3f29dad
remove always failing or flaky snapshot tests
broccolinisoup Sep 19, 2023
ba5d060
reorganise action menu again
broccolinisoup Sep 19, 2023
edc0615
add popover polyfill to the esm only modules in rollup
broccolinisoup Sep 20, 2023
b56fb96
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Sep 21, 2023
a05474e
add test cases for tooltip on action menu both for v1 and v2
broccolinisoup Sep 25, 2023
bb78acc
Merge branch 'main' into bs/experimental-tooltip-with-popover
broccolinisoup Sep 25, 2023
a662853
clean up
broccolinisoup Sep 25, 2023
133246d
Update docs/gatsby-config.js
broccolinisoup Sep 25, 2023
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
7 changes: 7 additions & 0 deletions .changeset/blue-melons-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': minor
---

Tooltip: Release Tooltip v2 as a draft/experimental

<!-- Changed components: _none_ -->
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.
84 changes: 84 additions & 0 deletions docs/content/drafts/Tooltip.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
componentId: tooltip
title: Tooltip
status: Alpha
---

import data from '../../../src/drafts/Tooltip/Tooltip.docs.json'

The Tooltip component is used to add context to interactive elements on the page.

**_⚠️ Usage warning! ⚠️_**

Tooltips as a UI pattern should be our last resort for conveying information because it is hidden by default and often with zero or little visual indicator of its existence.

Before adding a tooltip, please consider: Is this information essential and necessary? Can the UI be made clearer? Can the information be shown on the page by default? See [Tooltip alternatives](https://primer.style/design/accessibility/tooltip-alternatives) for more accessible alternatives.

Tooltip should only be used on an element that is interactive such as a button or a link.

## Examples

### Default (For additional context)

Default tooltip is suitable for interactive controls that require additional context.

```jsx live
<Tooltip text="This change cannot be undone.">
<Button>Delete</Button>
</Tooltip>
```

### As a label

Tooltip can be used to label interactive controls that has no visible text label such as interactive icon links.

broccolinisoup marked this conversation as resolved.
Show resolved Hide resolved
```jsx live
<Tooltip text="Contribution Documentation for 'Primer React'" type="label">
<Link href="https://github.com/primer/react/contributor-docs/CONTRIBUTING.md" sx={{ml: 1, color: 'fg.muted'}}>
<StyledOcticon icon={BookIcon} sx={{color: 'fg.muted'}} />
</Link>
</Tooltip>
```

### With direction

```jsx live
<Box sx={{padding: 5, display: 'flex', gap: '8px'}}>
<Tooltip direction="n" text="Supplementary text">
<Button>North</Button>
</Tooltip>
<Tooltip direction="s" text="Supplementary text">
<Button>South</Button>
</Tooltip>
<Tooltip direction="e" text="Supplementary text">
<Button>East</Button>
</Tooltip>
<Tooltip direction="w" text="Supplementary text">
<Button>West</Button>
</Tooltip>
<Tooltip direction="ne" text="Supplementary text">
<Button>North East</Button>
</Tooltip>
<Tooltip direction="nw" text="Supplementary text">
<Button>North West</Button>
</Tooltip>
<Tooltip direction="se" text="Supplementary text">
<Button>Southeast</Button>
</Tooltip>
<Tooltip direction="sw" text="Supplementary text">
<Button>Southwest</Button>
</Tooltip>
</Box>
```

### With no delay

```jsx live
<Tooltip noDelay text="Supplemetary text">
Copy link
Member

@siddharthkp siddharthkp Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have honestly forgotten if we want to keep noDelay or remove it 😅

I personally think Tooltip should be very snappy by default and we should not have this customisable based on a page, that would leave to slight inconsistencies that feel unpolished 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll tag @langermank because we are a proposal for some visual changes in the design repo and might be good idea to bring it up there if this is something we are going to go forward with it 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great callout @siddharthkp! I agree Tooltip should be snappy by default, so I would actually remove this prop and remove the delay in the default styles. If there's a delay in Primer View Components I'll make sure to remove it as well when I update the caret styles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great! I'll update the code, docs and stories accordingly ✨

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see it!

<Button>Button</Button>
</Tooltip>
```

## Props

<ComponentProps data={data} />
1 change: 1 addition & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
'@primer/components': path.resolve(__dirname, '../src'),
'@primer/react': path.resolve(__dirname, '../src'),
'@primer/react/drafts': path.resolve(__dirname, '../src/drafts'),
'@primer/react/experimental': path.resolve(__dirname, '../src/experimental'),
broccolinisoup marked this conversation as resolved.
Show resolved Hide resolved
'styled-components': path.resolve(__dirname, '..', 'node_modules', 'styled-components'),
react: path.resolve(__dirname, 'node_modules', 'react'),
},
Expand Down
284 changes: 284 additions & 0 deletions e2e/components/Tooltip--experimental.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

test.describe('Tooltip--experimental', () => {
test.describe('Default', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip--default',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Default.${theme}.png`,
)
})

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

test.describe('All Directions', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--all-directions',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.North.${theme}.png`,
)
})

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

test.describe('Anchor Has Margin', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--anchor-has-margin',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Anchor Has Margin.${theme}.png`,
)
})

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

test.describe('Calculated Direction', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--calculated-direction',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Calculated Direction.${theme}.png`,
)
})

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

test.describe('Icon Button With Description', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--icon-button-with-description',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Icon Button With Description.${theme}.png`,
)
})

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

test.describe('Label Type', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--label-type',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Label Type.${theme}.png`,
)
})

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

test.describe('Multiline Text', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--multiline-text',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Multiline Text.${theme}.png`,
)
})

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

test.describe('On Action Menu Anchor', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--on-action-menu-anchor',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.On Action Menu Anchor.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--on-action-menu-anchor',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Files Page Example', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-examples--files-page',
globals: {
colorScheme: theme,
},
})

// Default state
await page.keyboard.press('Tab')
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`Tooltip--experimental.Files Page Example.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-examples--files-page',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
Loading
Loading