-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(react-tooltip): hide tooltip when trigger scrolls out of overflow container #36386
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
Open
PaulGMardling
wants to merge
5
commits into
microsoft:master
Choose a base branch
from
PaulGMardling:fix/tooltip-hidden-outside-overflow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1c67f2a
fix(react-tooltip): hide tooltip when trigger scrolls out of overflow…
PaulGMardling 9d0c2fc
fix(react-tooltip): hide tooltip when trigger scrolls out of overflow…
PaulGMardling 1f1b19e
fix(react-tooltio): remove test comments
PaulGMardling a5f7cd0
chore(vrt): stabilize storywright timing under CI load
PaulGMardling f38b0ba
chore: update tooltip change description
PaulGMardling 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-tooltip-b1816358-7b53-4ebc-8579-8308e77a0468.json
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,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "tooltip appears outside of overflow", | ||
| "packageName": "@fluentui/react-tooltip", | ||
| "email": "paulmardling@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
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
3 changes: 3 additions & 0 deletions
3
packages/react-components/react-tooltip/library/cypress.config.ts
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,3 @@ | ||
| import { baseConfig } from '@fluentui/scripts-cypress'; | ||
|
|
||
| export default baseConfig; |
107 changes: 107 additions & 0 deletions
107
packages/react-components/react-tooltip/library/src/components/Tooltip/Tooltip.cy.tsx
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,107 @@ | ||
| import 'cypress-real-events'; | ||
| import * as React from 'react'; | ||
| import { mount as mountBase } from '@fluentui/scripts-cypress'; | ||
| import { FluentProvider } from '@fluentui/react-provider'; | ||
| import { teamsLightTheme } from '@fluentui/react-theme'; | ||
| import { Button } from '@fluentui/react-button'; | ||
| import { Tooltip } from './index'; | ||
|
|
||
| const mount = (element: React.ReactElement) => { | ||
| mountBase(<FluentProvider theme={teamsLightTheme}>{element}</FluentProvider>); | ||
| }; | ||
|
|
||
| // The data attribute the positioning middleware writes when the reference is hidden | ||
| const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden'; | ||
|
|
||
| describe('Tooltip', () => { | ||
| describe('overflow behavior (regression: #32882)', () => { | ||
| /** | ||
| * Renders a tooltip trigger inside an overflow:hidden container tall enough | ||
| * to scroll the trigger out of view, then verifies the tooltip content element | ||
| * gets `data-popper-reference-hidden` set once scrolled, and loses it once | ||
| * scrolled back. | ||
| * | ||
| * This is the E2E complement to the unit tests in createPositionManager.test.ts | ||
| * and the CSS fix in useTooltipStyles.styles.ts. | ||
| */ | ||
| it('sets data-popper-reference-hidden on the tooltip when the trigger scrolls out of view', () => { | ||
| mount( | ||
| <div | ||
| id="scroll-container" | ||
| style={{ | ||
| height: '100px', | ||
| width: '200px', | ||
| overflow: 'hidden scroll', | ||
| position: 'relative', | ||
| }} | ||
| > | ||
| <div style={{ height: '400px', paddingTop: '8px' }}> | ||
| <Tooltip content="Overflow tooltip" relationship="label" data-testid="tooltip-content"> | ||
| <Button id="trigger">Hover me</Button> | ||
| </Tooltip> | ||
| </div> | ||
| </div>, | ||
| ); | ||
|
|
||
| cy.get('#trigger').realHover(); | ||
| cy.get('[role="tooltip"]').should('be.visible'); | ||
| cy.get('#scroll-container').scrollTo(0, 300); | ||
| cy.get('[role="tooltip"]').should('have.attr', DATA_POSITIONING_HIDDEN); | ||
| }); | ||
|
|
||
| it('removes data-popper-reference-hidden when the trigger scrolls back into view', () => { | ||
| mount( | ||
| <div | ||
| id="scroll-container" | ||
| style={{ | ||
| height: '100px', | ||
| width: '200px', | ||
| overflow: 'hidden scroll', | ||
| position: 'relative', | ||
| }} | ||
| > | ||
| <div style={{ height: '400px', paddingTop: '8px' }}> | ||
| <Tooltip content="Overflow tooltip" relationship="label"> | ||
| <Button id="trigger">Hover me</Button> | ||
| </Tooltip> | ||
| </div> | ||
| </div>, | ||
| ); | ||
|
|
||
| cy.get('#trigger').realHover(); | ||
| cy.get('[role="tooltip"]').should('be.visible'); | ||
|
|
||
| cy.get('#scroll-container').scrollTo(0, 300); | ||
| cy.get('[role="tooltip"]').should('have.attr', DATA_POSITIONING_HIDDEN); | ||
|
|
||
| cy.get('#scroll-container').scrollTo(0, 0); | ||
| cy.get('[role="tooltip"]').should('not.have.attr', DATA_POSITIONING_HIDDEN); | ||
| }); | ||
|
|
||
| it('applies visibility:hidden CSS when data-popper-reference-hidden is present', () => { | ||
| mount( | ||
| <div | ||
| id="scroll-container" | ||
| style={{ | ||
| height: '100px', | ||
| width: '200px', | ||
| overflow: 'hidden scroll', | ||
| position: 'relative', | ||
| }} | ||
| > | ||
| <div style={{ height: '400px', paddingTop: '8px' }}> | ||
| <Tooltip content="Overflow tooltip" relationship="label"> | ||
| <Button id="trigger">Hover me</Button> | ||
| </Tooltip> | ||
| </div> | ||
| </div>, | ||
| ); | ||
|
|
||
| cy.get('#trigger').realHover(); | ||
| cy.get('[role="tooltip"]').should('be.visible'); | ||
|
|
||
| cy.get('#scroll-container').scrollTo(0, 300); | ||
| cy.get('[role="tooltip"]').should('have.css', 'visibility', 'hidden'); | ||
| }); | ||
| }); | ||
| }); |
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
9 changes: 9 additions & 0 deletions
9
packages/react-components/react-tooltip/library/tsconfig.cy.json
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,9 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "isolatedModules": false, | ||
| "types": ["node", "cypress", "cypress-real-events"], | ||
| "typeRoots": ["../../../../node_modules", "../../../../node_modules/@types"] | ||
| }, | ||
| "include": ["**/*.cy.ts", "**/*.cy.tsx"] | ||
| } |
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
49 changes: 49 additions & 0 deletions
49
...ages/react-components/react-tooltip/stories/src/Tooltip/TooltipOverflowHidden.stories.tsx
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,49 @@ | ||
| import * as React from 'react'; | ||
| import type { JSXElement } from '@fluentui/react-components'; | ||
| import { Button, Tooltip } from '@fluentui/react-components'; | ||
|
|
||
| /** | ||
| * A tooltip whose trigger is inside an `overflow: hidden` container. | ||
| * When the trigger is scrolled out of view, the tooltip should become hidden | ||
| * (via `data-popper-reference-hidden` set by the positioning middleware). | ||
| * | ||
| * Regression story for https://github.com/microsoft/fluentui/issues/32882 | ||
| */ | ||
| export const OverflowHidden = (): JSXElement => { | ||
| return ( | ||
| <div style={{ display: 'flex', flexDirection: 'column', gap: '8px', alignItems: 'flex-start' }}> | ||
| <p style={{ margin: 0, fontSize: '14px' }}> | ||
| Scroll the box below. The tooltip should disappear when the button scrolls out of view, not follow it outside | ||
| the container boundary. | ||
| </p> | ||
| <div | ||
| style={{ | ||
| height: '120px', | ||
| width: '240px', | ||
| overflow: 'hidden scroll', | ||
| border: '1px solid #ccc', | ||
| borderRadius: '4px', | ||
| position: 'relative', | ||
| }} | ||
| > | ||
| <div style={{ height: '300px', paddingTop: '8px', paddingLeft: '8px' }}> | ||
| <Tooltip content="I should hide when scrolled out of view" relationship="label"> | ||
| <Button>Hover me, then scroll</Button> | ||
| </Tooltip> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| OverflowHidden.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: `When a tooltip trigger is inside an \`overflow: hidden\` container and the trigger scrolls out | ||
| of view, the tooltip must be hidden rather than appearing outside the overflow boundary. | ||
|
|
||
| The positioning middleware sets \`data-popper-reference-hidden\` on the tooltip element when the trigger | ||
| is clipped by its scroll container. The Tooltip styles respond to this attribute with \`visibility: hidden\`.`, | ||
| }, | ||
| }, | ||
| }; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Menu Converged - submenuIndicator slotted content 2 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/ProgressBar converged 2 screenshots
vr-tests-react-components/TagPicker 3 screenshots
There were 3 duplicate changes discarded. Check the build logs for more information.