-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(segment-view): scroll to correct content when height is not set #30547
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f1b025
test(segment-view): add segment view with input test
brandyscarney ee5d774
fix(segment-view): scroll to correct content when height is not set
brandyscarney d61cd78
test(segment-view): add dynamic height e2e test
brandyscarney 42e44ad
test(segment-view): add a test for scrolling to a dynamic height content
brandyscarney 424f62a
test(segment-view): wait for image to load
brandyscarney 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
75 changes: 75 additions & 0 deletions
75
core/src/components/segment-view/test/dynamic-height/index.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,75 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Segment View - Dynamic Height</title> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
| /> | ||
| <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> | ||
|
|
||
| <style> | ||
| ion-segment-content { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: fit-content; | ||
| } | ||
|
|
||
| ion-segment-content:nth-of-type(1) { | ||
| background: lightpink; | ||
| } | ||
| ion-segment-content:nth-of-type(2) { | ||
| background: lightblue; | ||
| } | ||
| ion-segment-content:nth-of-type(3) { | ||
| background: lightgreen; | ||
| } | ||
| </style> | ||
| </head> | ||
|
|
||
| <body> | ||
| <ion-app> | ||
| <ion-header> | ||
| <ion-toolbar> | ||
| <ion-title>Segment View - Dynamic Height</ion-title> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
|
|
||
| <ion-content> | ||
| <ion-segment> | ||
| <ion-segment-button value="first" content-id="first"> | ||
| <ion-label>First</ion-label> | ||
| </ion-segment-button> | ||
| <ion-segment-button value="second" content-id="second"> | ||
| <ion-label>Second</ion-label> | ||
| </ion-segment-button> | ||
| <ion-segment-button value="third" content-id="third"> | ||
| <ion-label>Third</ion-label> | ||
| </ion-segment-button> | ||
| </ion-segment> | ||
| <ion-segment-view> | ||
| <ion-segment-content id="first"> | ||
| Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora | ||
| quaeritis. Summus brains sit, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum mauris. | ||
| Hi mindless mortuis soulless creaturas, imo evil stalking monstra adventus resi dentevil vultus comedat | ||
| cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The voodoo | ||
| sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for solum oculi eorum defunctis | ||
| go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv | ||
| </ion-segment-content> | ||
| <ion-segment-content id="second"> | ||
| <ion-input value="" label="Email"></ion-input> | ||
| </ion-segment-content> | ||
| <ion-segment-content id="third"> | ||
| <ion-img class="img-part" src="https://picsum.photos/200/300"></ion-img> | ||
| </ion-segment-content> | ||
| </ion-segment-view> | ||
| </ion-content> | ||
| </ion-app> | ||
| </body> | ||
| </html> |
85 changes: 85 additions & 0 deletions
85
core/src/components/segment-view/test/dynamic-height/segment-view.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,85 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * This behavior does not vary across modes/directions | ||
| */ | ||
| configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { | ||
| test.describe(title('segment-view: dynamic height'), () => { | ||
| test('should show the third content when clicking the third button', async ({ page, skip }) => { | ||
| // Skip this test on Chrome and Firefox | ||
| skip.browser('firefox', 'Original issue only happens on Safari.'); | ||
| skip.browser('chromium', 'Original issue only happens on Safari.'); | ||
|
|
||
| await page.setContent( | ||
| ` | ||
| <style> | ||
| ion-segment-content { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: fit-content; | ||
| } | ||
| </style> | ||
|
|
||
| <ion-segment> | ||
| <ion-segment-button value="first" content-id="first"> | ||
| <ion-label>First</ion-label> | ||
| </ion-segment-button> | ||
| <ion-segment-button value="second" content-id="second"> | ||
| <ion-label>Second</ion-label> | ||
| </ion-segment-button> | ||
| <ion-segment-button value="third" content-id="third"> | ||
| <ion-label>Third</ion-label> | ||
| </ion-segment-button> | ||
| </ion-segment> | ||
| <ion-segment-view> | ||
| <ion-segment-content id="first"> | ||
| Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora | ||
| quaeritis. Summus brains sit, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum | ||
| mauris. Hi mindless mortuis soulless creaturas, imo evil stalking monstra adventus resi dentevil vultus | ||
| comedat cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The | ||
| voodoo sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for solum oculi eorum | ||
| defunctis go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv | ||
| </ion-segment-content> | ||
| <ion-segment-content id="second"> | ||
| <ion-input value="" label="Email"></ion-input> | ||
| </ion-segment-content> | ||
| <ion-segment-content id="third"> | ||
| <ion-img class="img-part" src="https://picsum.photos/200/300"></ion-img> | ||
| </ion-segment-content> | ||
| </ion-segment-view> | ||
| `, | ||
| config | ||
| ); | ||
|
|
||
| // Click the third button | ||
| await page.locator('ion-segment-button[value="third"]').click(); | ||
|
|
||
| // Wait for the content to be scrolled | ||
| await page.waitForChanges(); | ||
|
|
||
| // Wait for the image to load and be visible | ||
| const imgLocator = page.locator('ion-segment-content#third ion-img'); | ||
| await imgLocator.waitFor({ state: 'visible', timeout: 10000 }); | ||
|
|
||
| // Wait for any layout adjustments | ||
| await page.waitForChanges(); | ||
|
|
||
| // Check that the third content is visible | ||
| const segmentView = page.locator('ion-segment-view'); | ||
| const thirdContent = page.locator('ion-segment-content#third'); | ||
|
|
||
| const viewBox = await segmentView.boundingBox(); | ||
| const contentBox = await thirdContent.boundingBox(); | ||
|
|
||
| if (!viewBox || !contentBox) throw new Error('Bounding box not found'); | ||
|
|
||
| // Allow a small tolerance to account for subpixel rendering, | ||
| // scrollbars, or layout rounding differences | ||
| const tolerance = 10; | ||
| expect(contentBox.x).toBeGreaterThanOrEqual(viewBox.x); | ||
| expect(contentBox.x + contentBox.width).toBeLessThanOrEqual(viewBox.x + viewBox.width + tolerance); | ||
| }); | ||
| }); | ||
| }); | ||
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.