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 all 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.
76 changes: 76 additions & 0 deletions docs/content/drafts/Tooltip.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
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>
```

## Props

<ComponentProps data={data} />
175 changes: 175 additions & 0 deletions e2e/components/Tooltip--experimental.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
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`,
{
threshold: 0.1,
},
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip--default',
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`,
{
threshold: 0.1,
},
)
})

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`,
{
threshold: 0.1,
},
)
})

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`,
{
threshold: 0.1,
},
)
})

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`,
{
threshold: 0.1,
},
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'drafts-components-tooltip-features--label-type',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
12 changes: 11 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

'use strict'

const path = require('node:path')
const {REACT_VERSION_17} = process.env

/**
Expand All @@ -17,12 +18,21 @@ module.exports = {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/stories/**', '!**/*.stories.{js,jsx,ts,tsx}'],
moduleNameMapper: {
'\\.css$': 'jest-css-modules',
// We need to specify this package subpath because it does not provide a `require` conditional export path
broccolinisoup marked this conversation as resolved.
Show resolved Hide resolved
'@oddbird/popover-polyfill/fn': path.join(
__dirname,
'node_modules',
'@oddbird',
'popover-polyfill',
'dist',
'popover-fn.js',
),
},
setupFiles: ['<rootDir>/src/utils/test-helpers.tsx'],
setupFilesAfterEnv: ['<rootDir>/src/utils/test-matchers.tsx', '<rootDir>/src/utils/test-deprecations.tsx'],
testMatch: ['<rootDir>/(src|codemods)/**/*.test.[jt]s?(x)', '!**/*.types.test.[jt]s?(x)'],
transformIgnorePatterns: [
'node_modules/(?!@github/combobox-nav|@koddsson/textarea-caret|@github/[a-z-]+-element|@lit-labs/react)',
'node_modules/(?!@github/combobox-nav|@koddsson/textarea-caret|@github/[a-z-]+-element|@lit-labs/react|@oddbird/popover-polyfill)',
],
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
}
10 changes: 8 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"@github/paste-markdown": "^1.4.0",
"@github/relative-time-element": "^4.1.2",
"@lit-labs/react": "^1.1.1",
"@oddbird/popover-polyfill": "0.2.2",
"@primer/behaviors": "^1.3.4",
"@primer/octicons-react": "^19.7.0",
"@primer/primitives": "^7.11.11",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const ESM_ONLY = new Set([
'@github/paste-markdown',
'@github/relative-time-element',
'@lit-labs/react',
'@oddbird/popover-polyfill',
])
const dependencies = [
...Object.keys(packageJson.peerDependencies ?? {}),
Expand Down
39 changes: 39 additions & 0 deletions script/generate-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,45 @@ const components = new Map([
],
},
],
[
'Tooltip--experimental',
{
stories: [
{
id: 'drafts-components-tooltip--default',
name: 'Default',
},
{
id: 'drafts-components-tooltip-features--anchor-has-margin',
name: 'Anchor Has Margin',
},
{
id: 'drafts-components-tooltip-features--calculated-direction',
name: 'Calculated Direction',
},
{
id: 'drafts-components-tooltip-features--icon-button-with-description',
name: 'Icon Button With Description',
},
{
id: 'drafts-components-tooltip-features--label-type',
name: 'Label Type',
},
{
id: 'drafts-components-tooltip-features--multiline-text',
name: 'Multiline Text',
},
{
id: 'drafts-components-tooltip-features--on-action-menu-anchor',
name: 'On Action Menu Anchor',
},
{
id: 'drafts-components-tooltip-examples--files-page',
name: 'Files Page Example',
},
],
},
],
[
'TreeView',
{
Expand Down
Loading
Loading