-
Notifications
You must be signed in to change notification settings - Fork 860
feat(eui): add repositionOnScroll to componentDefaults #9152
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
weronikaolejniczak
merged 9 commits into
elastic:main
from
weronikaolejniczak:feat/reposition-on-scroll-component-defaults
Nov 5, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef80912
feat(eui): add repositionOnScroll to componentDefaults
weronikaolejniczak 146d593
chore(eui): remove expect.anything() from test assertion
weronikaolejniczak 918ae48
refactor(eui): add a generic function for reposition on scroll
weronikaolejniczak 06933f6
chore(eui): add meaningful repositionOnScroll Cypress tests
weronikaolejniczak d8101db
refactor(eui): rename `performRepositionTest` to `testRepositionOnScr…
weronikaolejniczak 2ed993e
refactor(eui): simplify `createRepositionOnScroll` function
weronikaolejniczak a37a47a
refactor(eui): remove redundant export
weronikaolejniczak 0e07439
refactor(eui): add return type to `createRepositionOnScroll`
weronikaolejniczak 7a4fcad
fix(eui): fix circular dependency for provider imports
weronikaolejniczak 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added `EuiPopover` and `EuiToolTip`'s `repositionOnScroll` to `componentDefaults` |
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
66 changes: 66 additions & 0 deletions
66
packages/eui/cypress/support/helpers/wait_for_position_to_settle.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,66 @@ | ||
| /** | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| /// <reference path="../index.d.ts" /> | ||
|
|
||
| /** | ||
| * A recursive helper function that polls an element's position. | ||
| * | ||
| * @param subject The Cypress subject (the DOM element). | ||
| * @param stabilityCount The number of times the position has been stable. | ||
| * @param retries The number of remaining retries. | ||
| * @param prevRect The element's rect from the previous check. | ||
| */ | ||
| export function waitForPositionToSettle( | ||
| subject: JQuery<HTMLElement>, | ||
| stabilityCount = 0, | ||
| retries = 40, // 40 * 50ms = 2s timeout | ||
| prevRect?: DOMRect | ||
| ): Cypress.Chainable<JQuery<HTMLElement>> { | ||
| const STABILITY_THRESHOLD = 3; // require 3 consecutive stable checks | ||
|
|
||
| if (retries < 0) { | ||
| throw new Error('Position did not settle in time after 2s'); | ||
| } | ||
|
|
||
| const currentRect = subject[0].getBoundingClientRect(); | ||
|
|
||
| let nextStabilityCount = stabilityCount; | ||
| if ( | ||
| prevRect && | ||
| currentRect.top === prevRect.top && | ||
| currentRect.left === prevRect.left | ||
| ) { | ||
| nextStabilityCount++; | ||
| } else { | ||
| // Position changed, reset counter | ||
| nextStabilityCount = 0; | ||
| } | ||
|
|
||
| if (nextStabilityCount >= STABILITY_THRESHOLD) { | ||
| cy.log('Position settled'); | ||
| return cy.wrap(subject); | ||
| } | ||
|
|
||
| return cy.wait(50, { log: false }).then(() => { | ||
| return waitForPositionToSettle( | ||
| subject, | ||
| nextStabilityCount, | ||
| retries - 1, | ||
| currentRect | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| Cypress.Commands.add( | ||
| 'waitForPositionToSettle', | ||
| { prevSubject: 'element' }, | ||
| (subject: JQuery<HTMLElement>) => { | ||
| return waitForPositionToSettle(subject); | ||
| } | ||
| ); | ||
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
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.