-
Notifications
You must be signed in to change notification settings - Fork 610
Tooltip: anchoredPosition + IconButton #2006
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
Merged
Merged
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
f427dbf
Add breaking story
siddharthkp 8772f31
Add memex story
siddharthkp b9cbf8c
use behaviors deploy preview
siddharthkp 3aaf1f4
add tooltip triangle
siddharthkp 67a5eed
update snapshot
siddharthkp 3ad30cc
add label tooltips for story
siddharthkp 5a91f96
update @primer/behaviors to latest
siddharthkp 68bbdde
Merge branch 'main' into siddharthkp/fix-anchored-position
siddharthkp ecfb54e
lint: remove unused import
siddharthkp 8a872c5
Refactor Tooltip
siddharthkp 98fdc4a
Use Tooltip in IconButton
siddharthkp 623f2b2
Add triangle styles for all directions
siddharthkp c4c65fd
Add docs
siddharthkp b9ed36c
Added delay
siddharthkp 505c1a5
change ReactElement to ReactNode
siddharthkp 1e26ba1
keep ReactElement
siddharthkp 24b01a4
Add tests!
siddharthkp 13461ea
compatible types :)
siddharthkp 36bf0fc
Fix docs
siddharthkp 8d199cb
Merge branch 'main' into siddharthkp/fix-anchored-position
siddharthkp 3aaf29a
update snapshots
siddharthkp 8a98ac8
update behaviors to next minor
siddharthkp e228b09
update snapshots
siddharthkp 1b1166a
Fix IconButton duplicate label
siddharthkp a81b671
Merge branch 'main' into siddharthkp/fix-anchored-position
siddharthkp 6c62bf0
missed a spot!
siddharthkp 38ffda3
Fix Button story with tooltip
siddharthkp 393c440
Apply suggestions from code review
siddharthkp 3bd3382
fix alignment with span
siddharthkp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
--- | ||
componentId: tooltip | ||
title: Tooltip | ||
status: Alpha | ||
source: https://github.com/primer/react/tree/main/src/Tooltip | ||
storybook: '/react/storybook?path=/story/composite-components-tooltip' | ||
description: The Tooltip component adds a tooltip to add context to elements on the page. | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
Tooltip only appears on mouse hover or keyboard focus and contain a label or description text. Use tooltips sparingly and as a last resort. [Consider these alternatives](https://primer.style/design/accessibility/tooltip-alternatives). | ||
|
||
import {Tooltip, IconButton, Button} from '@primer/react' | ||
import {BellIcon, MentionIcon} from '@primer/octicons-react' | ||
import InlineCode from '@primer/gatsby-theme-doctocat/src/components/inline-code' | ||
|
||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
border: '1px solid', | ||
borderColor: 'border.default', | ||
borderRadius: 2, | ||
padding: 6, | ||
paddingTop: 8, | ||
marginBottom: 3 | ||
}} | ||
> | ||
<Tooltip text="You have no unread notifications" sx={{visibility: 'visible', opacity: 1}}> | ||
<IconButton icon={BellIcon} aria-label="Notifications" /> | ||
</Tooltip> | ||
</Box> | ||
|
||
When using a tooltip, follow the provided guidelines to avoid accessibility issues. | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- Tooltip text should be brief and to the point. | ||
- Tooltips should contain only **non-essential text**. Tooltips can easily be missed and are not accessible on touch devices so never use tooltips to convey critical information. | ||
|
||
## Examples | ||
|
||
### As a description for icon-only button | ||
|
||
If the tooltip content provides supplementary description, wrap the target in a `Tooltip`. The trigger element should also have a concise accessible label via `aria-label`. | ||
|
||
```jsx live | ||
<Tooltip text="Directly mention a team or user"> | ||
<IconButton aria-label="Mentions" icon={MentionIcon} variant="invisible" /> | ||
</Tooltip> | ||
``` | ||
|
||
### As a description for a button with visible label | ||
|
||
```jsx live | ||
<Tooltip text="This will immediately impact all organization members"> | ||
<Button variant="primary">Save</Button> | ||
</Tooltip> | ||
``` | ||
|
||
### With direction | ||
|
||
Set direction of tooltip with `direction`. The tooltip is responsive and will automatically adjust direction to avoid cutting off. | ||
|
||
```jsx live | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: 8, | ||
marginY: 4, | ||
'[data-component=tooltip]': {visibility: 'visible', opacity: 1} | ||
}} | ||
> | ||
<Box sx={{display: 'flex', justifyContent: 'space-between', gap: 1}}> | ||
<Tooltip direction="nw" text="Tooltip text"> | ||
<Button>North West</Button> | ||
</Tooltip> | ||
<Tooltip direction="n" text="Tooltip text"> | ||
<Button>North</Button> | ||
</Tooltip> | ||
<Tooltip direction="ne" text="Tooltip text"> | ||
<Button>North East</Button> | ||
</Tooltip> | ||
</Box> | ||
<Box sx={{display: 'flex', justifyContent: 'space-between', gap: 1}}> | ||
<Tooltip direction="e" text="Tooltip text"> | ||
<Button>East</Button> | ||
</Tooltip> | ||
<Tooltip direction="w" text="Tooltip text"> | ||
<Button>West</Button> | ||
</Tooltip> | ||
</Box> | ||
<Box sx={{display: 'flex', justifyContent: 'space-between', gap: 1}}> | ||
<Tooltip direction="sw" text="Tooltip text"> | ||
<Button>South West</Button> | ||
</Tooltip> | ||
<Tooltip direction="s" text="Tooltip text"> | ||
<Button>South</Button> | ||
</Tooltip> | ||
<Tooltip direction="se" text="Tooltip text"> | ||
<Button>South East</Button> | ||
</Tooltip> | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Box> | ||
</Box> | ||
``` | ||
|
||
## Props | ||
|
||
<PropsTable> | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<PropsTableRow name="children" required type="React.ReactNode" description="Tooltip target, single element" /> | ||
|
||
<PropsTableRow | ||
name="text" | ||
type="string" | ||
description="The text content of the tooltip. This should be brief and no longer than a sentence" | ||
/> | ||
<PropsTableRow | ||
deprecated | ||
name="aria-label" | ||
type="string" | ||
description={ | ||
<> | ||
Use <InlineCode>text</InlineCode> instead | ||
</> | ||
} | ||
/> | ||
<PropsTableRow | ||
name="type" | ||
type="description | label" | ||
defaultValue="description" | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description={ | ||
<> | ||
Use <InlineCode>aria-describedby</InlineCode> or <InlineCode>aria-labelledby</InlineCode> | ||
</> | ||
} | ||
/> | ||
<PropsTableRow | ||
name="direction" | ||
type="nw | n | ne | e | se | s | sw | w" | ||
defaultValue="n" | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description="Sets where the tooltip renders in relation to the target" | ||
/> | ||
<PropsTableRow name="align" deprecated type="left | right" description="Use direction instead. Alignment relative to target" /> | ||
siddharthkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<PropsTableRow | ||
name="noDelay" | ||
type="boolean" | ||
defaultValue="false" | ||
description={ | ||
<> | ||
When set to <InlineCode>true</InlineCode>, tooltip appears without any delay | ||
</> | ||
} | ||
/> | ||
<PropsTableRow | ||
name="wrap" | ||
type="boolean" | ||
deprecated | ||
description={ | ||
<> | ||
Use to allow text within tooltip to wrap. Deprecated: always set to <InlineCode>true</InlineCode> now. | ||
</> | ||
} | ||
/> | ||
<PropsTableSxRow /> | ||
</PropsTable> | ||
|
||
## Status | ||
|
||
<ComponentChecklist | ||
items={{ | ||
propsDocumented: true, | ||
noUnnecessaryDeps: true, | ||
adaptsToThemes: true, | ||
adaptsToScreenSizes: true, | ||
fullTestCoverage: true, | ||
usedInProduction: true, | ||
usageExamplesDocumented: true, | ||
hasStorybookStories: true, | ||
designReviewed: false, | ||
a11yReviewed: false, | ||
stableApi: true, | ||
addressedApiFeedback: false, | ||
hasDesignGuidelines: false, | ||
hasFigmaComponent: true | ||
}} | ||
/> | ||
|
||
## Further reading | ||
|
||
- [Tooltip alternatives](https://primer.style/design/accessibility/tooltip-alternatives) | ||
|
||
## Related components | ||
|
||
- [IconButton](/IconButton) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love these docs updates 💖