-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(popover): ensure popover does not go offscreen when adjusting top position #25350
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 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ea24bc
test(popover): add failing test
liamdebeasi a3b4a72
fix(popover): ensure popover does not go offscreen when adjusting top…
liamdebeasi 46a6b46
chore(): lint
liamdebeasi 92ac0e4
chore(): clean up
liamdebeasi 9234af6
chore(): improve test clarify
liamdebeasi af1f1aa
chore(): prettier
liamdebeasi 015dadb
Merge branch 'main' into FW-1591
liamdebeasi c3a2258
Merge branch 'main' into FW-1591
liamdebeasi 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,136 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Popover - Adjustment</title> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" | ||
| /> | ||
| <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" /> | ||
| <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" /> | ||
| <script src="../../../../../scripts/testing/scripts.js"></script> | ||
| <script nomodule src="../../../../../dist/ionic/ionic.js"></script> | ||
| <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> | ||
| <script type="module"> | ||
| import { popoverController } from '../../../../dist/ionic/index.esm.js'; | ||
| window.popoverController = popoverController; | ||
| </script> | ||
| <style> | ||
| .app { | ||
| background: #222; | ||
| color: #fff; | ||
| height: 100%; | ||
| display: flex; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .frame { | ||
| width: 320px; | ||
| animation: size 5s linear infinite alternate; | ||
| } | ||
|
|
||
| .test { | ||
| background: rgba(255, 0, 0, 0.2); | ||
| } | ||
|
|
||
| .react { | ||
| text-align: center; | ||
| opacity: 0; | ||
| font-size: 2em; | ||
| padding: 10px; | ||
| animation: show 5s linear infinite alternate; | ||
| } | ||
|
|
||
| .react small { | ||
| font-size: 0.5em; | ||
| opacity: 0.5; | ||
| } | ||
|
|
||
| @keyframes size { | ||
| to { | ||
| width: 200px; | ||
| } | ||
| } | ||
|
|
||
| @keyframes show { | ||
| 60% { | ||
| opacity: 0; | ||
| } | ||
| 100% { | ||
| opacity: 1; | ||
| } | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <ion-app> | ||
| <ion-content> | ||
| <p style="text-align: center">Click everywhere to open the popover.</p> | ||
| </ion-content> | ||
| </ion-app> | ||
|
|
||
| <script> | ||
| // Follow element for popover position. | ||
| const followEl = document.createElement('div'); | ||
| followEl.style.position = 'absolute'; | ||
| followEl.classList.add('test'); | ||
| followEl.style.left = '0'; | ||
| followEl.style.top = '0'; | ||
| followEl.style.width = '100px'; | ||
| followEl.style.height = '100px'; | ||
| //followEl.style.backgroundColor = 'yellow'; | ||
| followEl.style.borderRadius = '50px'; | ||
| document.body.append(followEl); | ||
liamdebeasi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| window.addEventListener('click', handleButtonClick); | ||
|
|
||
| document.body.addEventListener('pointermove', (ev) => { | ||
| followEl.style.left = `${ev.clientX - 50}px`; | ||
| followEl.style.top = `${ev.clientY - 50}px`; | ||
| }); | ||
|
|
||
| async function handleButtonClick(ev) { | ||
| await dismissPopover(); | ||
|
|
||
| popover = await popoverController.create({ | ||
| component: 'popover-example-page', | ||
| event: ev, | ||
| translucent: true, | ||
| }); | ||
|
|
||
| return popover.present(); | ||
| } | ||
|
|
||
| async function dismissPopover() { | ||
| let i = 10; | ||
| while (i--) { | ||
liamdebeasi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const popover = await popoverController.getTop(); | ||
| if (popover) { | ||
| await popover.dismiss(); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| customElements.define( | ||
| 'popover-example-page', | ||
| class ModalContent extends HTMLElement { | ||
| connectedCallback() { | ||
| this.innerHTML = ` | ||
| <ion-list> | ||
| <ion-list-header>Ionic</ion-list-header> | ||
| <ion-item button>Learn Ionic</ion-item> | ||
| <ion-item button>Documentation</ion-item> | ||
| <ion-item button>Showcase</ion-item> | ||
| <ion-item button>GitHub Repo</ion-item> | ||
| <ion-item button>Another Item</ion-item> | ||
| </ion-list> | ||
| `; | ||
| } | ||
| } | ||
| ); | ||
| </script> | ||
| </body> | ||
| </html> | ||
32 changes: 32 additions & 0 deletions
32
core/src/components/popover/test/adjustment/popover.e2e.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,32 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { test } from '@utils/test/playwright'; | ||
|
|
||
| test.describe('popover: adjustment', async () => { | ||
| test('should not render the popover offscreen', async ({ page }) => { | ||
| await page.goto('/src/components/popover/test/adjustment'); | ||
|
|
||
| /** | ||
| * We need to click in an area where | ||
| * there is not enough room to show the popover | ||
| * below the click coordinates but not enough | ||
| * room above the click coordinates that we | ||
| * can just move the popover to without it going | ||
| * offscreen. | ||
| */ | ||
| await page.setViewportSize({ | ||
| width: 500, | ||
| height: 400, | ||
| }); | ||
|
|
||
| const ionPopoverDidPresent = await page.spyOnEvent('ionPopoverDidPresent'); | ||
|
|
||
| await page.mouse.click(300, 300); | ||
|
|
||
| await ionPopoverDidPresent.next(); | ||
|
|
||
| const popoverContent = page.locator('ion-popover .popover-content'); | ||
| const box = (await popoverContent.boundingBox())!; | ||
|
|
||
| expect(box.y > 0).toBe(true); | ||
| }); | ||
| }); |
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
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.