-
-
Notifications
You must be signed in to change notification settings - Fork 658
fix: honor the floatingUIOptions positioning strategy #3480
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
chuckcarpenter
wants to merge
1
commit into
main
Choose a base branch
from
fix/3269-floating-ui-fixed-strategy
base: main
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
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 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 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 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
57 changes: 57 additions & 0 deletions
57
shepherd.js/test/cypress/examples/positioning-strategy.html
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,57 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" href="../../../dist/css/shepherd.css" /> | ||
| <script type="module"> | ||
| import Shepherd from '../../../dist/js/shepherd.mjs'; | ||
| window.Shepherd = Shepherd; | ||
| </script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| /* Tall enough that the window can scroll with the target on screen. */ | ||
| height: 3000px; | ||
| } | ||
|
|
||
| .page-target { | ||
| position: absolute; | ||
| top: 1200px; | ||
| left: 400px; | ||
| padding: 20px; | ||
| background: red; | ||
| } | ||
|
|
||
| .overflow-container { | ||
| position: absolute; | ||
| top: 200px; | ||
| left: 400px; | ||
| width: 400px; | ||
| height: 300px; | ||
| overflow: auto; | ||
| background: #eee; | ||
| } | ||
|
|
||
| .overflow-content { | ||
| height: 1200px; | ||
| } | ||
|
|
||
| .overflow-target { | ||
| margin: 600px 0 0 40px; | ||
| padding: 20px; | ||
| width: 120px; | ||
| background: blue; | ||
| } | ||
| </style> | ||
|
|
||
| <div class="page-target">Page target</div> | ||
|
|
||
| <div class="overflow-container"> | ||
| <div class="overflow-content"> | ||
| <div class="overflow-target">Overflow target</div> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> | ||
150 changes: 150 additions & 0 deletions
150
shepherd.js/test/cypress/integration/positioning-strategy.cy.js
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,150 @@ | ||
| import setupTour from '../utils/setup-tour'; | ||
|
|
||
| // End-to-end guard for #3269. Unit tests run in happy-dom, which has no layout | ||
| // engine, so this is the only place where a step that drifts away from its | ||
| // target while scrolling actually fails a test. | ||
| describe('positioning strategy', () => { | ||
| let Shepherd; | ||
|
|
||
| beforeEach(() => { | ||
| Shepherd = null; | ||
|
|
||
| cy.visit('/test/cypress/examples/positioning-strategy', { | ||
| onLoad(contentWindow) { | ||
| if (contentWindow.Shepherd) { | ||
| return (Shepherd = contentWindow.Shepherd); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * Vector from the target to the step, in viewport coordinates. If the step | ||
| * tracks its target, this vector is identical at every scroll offset. | ||
| */ | ||
| const offsetFromTarget = (targetSelector, stepId) => { | ||
| return cy.get(targetSelector).then(($target) => { | ||
| return cy.get(`[data-shepherd-step-id="${stepId}"]`).then(($step) => { | ||
| const target = $target[0].getBoundingClientRect(); | ||
| const step = $step[0].getBoundingClientRect(); | ||
|
|
||
| return { | ||
| dx: Math.round(step.left - target.left), | ||
| dy: Math.round(step.top - target.top) | ||
| }; | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| const startTour = (floatingUIOptions) => { | ||
| const tour = setupTour(Shepherd, { scrollTo: false }, () => [ | ||
| { | ||
| attachTo: { element: '.page-target', on: 'bottom' }, | ||
| id: 'strategy', | ||
| title: 'Strategy step', | ||
| text: 'positioned against a target the page scrolls past', | ||
| floatingUIOptions | ||
| } | ||
| ]); | ||
|
|
||
| tour.start(); | ||
| cy.wait(250); | ||
|
|
||
| return tour; | ||
| }; | ||
|
|
||
| it('keeps a `fixed` strategy step locked to its target while the page scrolls', () => { | ||
| startTour({ strategy: 'fixed' }); | ||
|
|
||
| cy.scrollTo(0, 700); | ||
| cy.wait(250); | ||
|
|
||
| cy.get('[data-shepherd-step-id="strategy"]').should( | ||
| 'have.css', | ||
| 'position', | ||
| 'fixed' | ||
| ); | ||
|
|
||
| let before; | ||
|
|
||
| offsetFromTarget('.page-target', 'strategy') | ||
| .then((offset) => { | ||
| before = offset; | ||
|
|
||
| cy.scrollTo(0, 800); | ||
| cy.wait(250); | ||
|
|
||
| return offsetFromTarget('.page-target', 'strategy'); | ||
| }) | ||
| .then((after) => { | ||
| // Before the fix, the step element was hardcoded to | ||
| // `position: absolute` while `computePosition` returned | ||
| // viewport-relative coordinates, so `after.dy` was `before.dy - 100` — | ||
| // exactly the scroll delta. | ||
| expect(after).to.deep.equal(before); | ||
| }); | ||
| }); | ||
|
|
||
| it('keeps a default strategy step locked to its target while the page scrolls', () => { | ||
| startTour(undefined); | ||
|
|
||
| cy.scrollTo(0, 700); | ||
| cy.wait(250); | ||
|
|
||
| cy.get('[data-shepherd-step-id="strategy"]').should( | ||
| 'have.css', | ||
| 'position', | ||
| 'absolute' | ||
| ); | ||
|
|
||
| let before; | ||
|
|
||
| offsetFromTarget('.page-target', 'strategy') | ||
| .then((offset) => { | ||
| before = offset; | ||
|
|
||
| cy.scrollTo(0, 800); | ||
| cy.wait(250); | ||
|
|
||
| return offsetFromTarget('.page-target', 'strategy'); | ||
| }) | ||
| .then((after) => { | ||
| expect(after).to.deep.equal(before); | ||
| }); | ||
| }); | ||
|
|
||
| it('tracks a target inside a scrolling container under the default strategy', () => { | ||
| const tour = setupTour(Shepherd, { scrollTo: false }, () => [ | ||
| { | ||
| attachTo: { element: '.overflow-target', on: 'bottom' }, | ||
| id: 'overflow', | ||
| title: 'Overflow step', | ||
| text: 'positioned against a target inside an overflow container' | ||
| } | ||
| ]); | ||
|
|
||
| tour.start(); | ||
|
|
||
| cy.get('.overflow-container').scrollTo(0, 500); | ||
| cy.wait(250); | ||
|
|
||
| let before; | ||
|
|
||
| offsetFromTarget('.overflow-target', 'overflow') | ||
| .then((offset) => { | ||
| before = offset; | ||
|
|
||
| cy.get('.overflow-container').scrollTo(0, 600); | ||
| cy.wait(250); | ||
|
|
||
| return offsetFromTarget('.overflow-target', 'overflow'); | ||
| }) | ||
| .then((after) => { | ||
| // `autoUpdate` recomputes on ancestor scroll, so the default | ||
| // `absolute` strategy already follows a target inside an `overflow` | ||
| // container. This is why the docs do not recommend `fixed` for that | ||
| // case. | ||
| expect(after).to.deep.equal(before); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.