Repository navigation
feat(gallery): resolve breakpoints from config #31519
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
+484
−42
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5848759
feat(gallery): resolve breakpoints from config
brandyscarney 21b785c
test(gallery): add an e2e test for breakpoints
brandyscarney 085bb4b
fix(gallery): fallback to xs when xs is larger than 0 and screen is s…
brandyscarney d193d81
style(gallery): use proper type and update comments
brandyscarney b026453
docs(gallery): update prop descriptions
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| export interface GalleryBreakpoints<T = string | number> { | ||
| xs?: T; | ||
| sm?: T; | ||
| md?: T; | ||
| lg?: T; | ||
| xl?: T; | ||
| xxl?: T; | ||
| } | ||
| import type { BreakpointMap } from '@utils/breakpoints'; | ||
|
|
||
| export type GalleryColumns = GalleryBreakpoints | string | number; | ||
| export type GalleryGap = GalleryBreakpoints | string | number; | ||
| export type GalleryBreakpoints = BreakpointMap<string | number>; | ||
|
|
||
| export type GalleryColumns = string | number | GalleryBreakpoints; | ||
| export type GalleryGap = string | number | GalleryBreakpoints; |
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
46 changes: 46 additions & 0 deletions
46
core/src/components/gallery/test/breakpoints/gallery.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,46 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test } from '@utils/test/playwright'; | ||
| import type { E2EPage } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * The test page configures every breakpoint below its default | ||
| * (xs 0, sm 200, md 400, lg 600, xl 800, xxl 1000). | ||
| * | ||
| * Only the first test verifies that the configured breakpoints are honored: | ||
| * 500px resolves to md with the override but xs with the defaults. The second | ||
| * verifies that the gallery resolves against its own width rather than the | ||
| * viewport, which is why it also passes with the defaults, both widths | ||
| * resolving to the same breakpoint; the gallery fills the viewport by default, | ||
| * so its width tracks the window unless a test explicitly narrows it. | ||
| * | ||
| * This behavior is the same across modes and directions. | ||
| */ | ||
| configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { | ||
| test.describe(title('gallery: breakpoints'), () => { | ||
| const columnsFor = (page: E2EPage) => | ||
| page.locator('#gallery').evaluate((el: HTMLElement) => el.style.getPropertyValue('--internal-gallery-columns')); | ||
|
|
||
| test('should resolve columns against the configured breakpoints', async ({ page }) => { | ||
| // 500px is above the configured md (400), so it resolves to md and the | ||
| // page's md value of 3. With the defaults it would be xs, since sm does | ||
| // not start until 576, and give 1 instead. | ||
| await page.setViewportSize({ width: 500, height: 800 }); | ||
| await page.goto('/src/components/gallery/test/breakpoints', config); | ||
|
|
||
| expect(await columnsFor(page)).toBe('3'); | ||
| }); | ||
|
|
||
| test('should resolve against its own width rather than the viewport', async ({ page }) => { | ||
| await page.setViewportSize({ width: 1600, height: 800 }); | ||
| await page.goto('/src/components/gallery/test/breakpoints', config); | ||
|
|
||
| // Filling the viewport, the gallery is xxl and takes the default columns. | ||
| expect(await columnsFor(page)).toBe('10'); | ||
|
|
||
| // Narrowing only the gallery drops it to xs, without the viewport moving. | ||
| await page.locator('#gallery-sizer').evaluate((el: HTMLElement) => (el.style.width = '150px')); | ||
|
|
||
| await expect.poll(() => columnsFor(page)).toBe('1'); | ||
| }); | ||
| }); | ||
| }); | ||
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.
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.
The "each width below resolves to a different breakpoint" part only holds for the first test, since the second resolves to xxl and then xs under the default breakpoints too, and it still passes with the defaults. That's fine because it's checking the gallery's own width against the viewport, but I think the comment should say so, so nobody expects it to catch the config being ignored.
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.
d193d81