Skip to content
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

va-pagination: add resize listener to adapt to mobile devices and zoomed layouts #1476

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e7ece77
First commit to confirm ResizeObserver triggers.
1Copenut Feb 3, 2025
2fcec36
Renamed state variables. Refactored magic numbers to instance constants.
1Copenut Feb 3, 2025
06efa84
Updated Storybook instances and e2e tests.
1Copenut Feb 3, 2025
0821778
Refactored prev, next, first, last logic to private functions.
1Copenut Feb 6, 2025
39ab503
Moved renderPages to a private function outside render.
1Copenut Feb 6, 2025
ff05f59
Commented and refactored pageNumbers func for logic readability.
1Copenut Feb 7, 2025
68c8926
Added return types to new render UI functions.
1Copenut Feb 7, 2025
f6a8145
Updated stories to 6 as lower bound.
1Copenut Feb 7, 2025
db09b81
Adding a CSS override for ellipses at smallest breakpoint.
1Copenut Feb 7, 2025
aca4288
Added a debounce method to utils.
1Copenut Feb 7, 2025
8b747eb
Added debounce to resizeObserver. Changed constant names for descript…
1Copenut Feb 7, 2025
5e57916
Added tests to check for ellipses on small screens.
1Copenut Feb 7, 2025
014a83a
Swapped conditional classname for container query.
1Copenut Feb 10, 2025
55e0362
Merge branch 'main' into tpierce-2199-bug-va-pagination
1Copenut Feb 10, 2025
02a20d3
Update packages/web-components/src/components/va-pagination/va-pagina…
1Copenut Feb 11, 2025
abc397c
Removing render function comment blocks.
1Copenut Feb 11, 2025
5b51cff
WIP. Refactoring use case 2 to use switch statement.
1Copenut Feb 12, 2025
8730cea
WIP. Refactoring use case 3 to use switch statement.
1Copenut Feb 12, 2025
009dfa3
Adjusted logic for handing off from last with one ellipsis to middle.
1Copenut Feb 12, 2025
4b4bc7a
Removing maxListLengthState. No longer needed with new logic tree.
1Copenut Feb 12, 2025
61b55e4
Added logic for 6-9 pages. Removed console.log statements.
1Copenut Feb 12, 2025
937c86f
WIP. Added logic for middle page starts.
1Copenut Mar 3, 2025
330beb4
Further improvements for use cases 3 and 4.
1Copenut Mar 3, 2025
7236bb7
Use case 1 confirmed correct.
1Copenut Mar 4, 2025
3388b43
Use case 3 confirmed correct.
1Copenut Mar 4, 2025
714a2a9
Use case 4 confirmed correct.
1Copenut Mar 4, 2025
605599d
Use case 2 confirmed correct.
1Copenut Mar 4, 2025
186dabc
Use case 5 confirmed correct. Added isTabletViewport state.
1Copenut Mar 4, 2025
8f5b4a2
Final cleanup and comment removal.
1Copenut Mar 4, 2025
41cc266
Added e2e tests for mobile, small tablet viewport widths.
1Copenut Mar 4, 2025
67a6e5d
Updated the SCSS comment explaining magic number in container query.
1Copenut Mar 5, 2025
0aba699
Refactoring high counts starting at 1 for mobile devices.
1Copenut Mar 5, 2025
5ca3781
Fixing two e2e tests for small viewport.
1Copenut Mar 6, 2025
19f2ee6
Merge branch 'main' into tpierce-2199-bug-va-pagination
1Copenut Mar 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 58 additions & 36 deletions packages/storybook/stories/va-pagination-uswds.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import { getWebComponentDocs, propStructure, StoryDocs } from './wc-helpers';
import { VaPagination } from '@department-of-veterans-affairs/web-components/react-bindings';

Expand All @@ -11,22 +11,22 @@ export default {
componentSubtitle: 'va-pagination web component',
docs: {
page: () => <StoryDocs storyDefault={Default} data={paginationDocs} />,
}
}
}
},
},
};

const defaultArgs = {
page: 1,
pages: 24,
'max-page-list-length': 7,
unbounded: false
}
'page': 1,
'pages': 24,
'max-page-list-length': 10,
'unbounded': false,
};

const Template = ({
'page': currentPage,
pages,
'max-page-list-length': maxPageListLength,
unbounded
unbounded,
}) => {
const [page, setPage] = useState(currentPage);
const handlePageSelect = event => {
Expand All @@ -41,7 +41,7 @@ const Template = ({
onPageSelect={handlePageSelect}
/>
);
}
};

export const Default = Template.bind(null);
Default.args = {
Expand All @@ -51,38 +51,48 @@ Default.argTypes = propStructure(paginationDocs);

export const WithMiddle = Template.bind(null);
WithMiddle.args = {
...defaultArgs, page: 10
}
...defaultArgs,
page: 10,
};

export const WithLast = Template.bind(null);
WithLast.args = {
...defaultArgs, page: 24
}
...defaultArgs,
page: 24,
};

export const WithUnboundedFirst = Template.bind(null);
WithUnboundedFirst.args = {
...defaultArgs, unbounded: true
}
...defaultArgs,
unbounded: true,
};

export const WithUnboundedMiddle = Template.bind(null);
WithUnboundedMiddle.args = {
...defaultArgs, unbounded: true, page: 10
}
...defaultArgs,
unbounded: true,
page: 10,
};

export const WithSevenOrLess = Template.bind(null);
WithSevenOrLess.args = {
...defaultArgs, pages: 7
}
export const WithSixOrLess = Template.bind(null);
WithSixOrLess.args = {
...defaultArgs,
pages: 6,
};

export const WithSevenOrLessMiddle = Template.bind(null);
WithSevenOrLessMiddle.args = {
...defaultArgs, pages: 7, page: 3
}
export const WithSixOrLessMiddle = Template.bind(null);
WithSixOrLessMiddle.args = {
...defaultArgs,
pages: 6,
page: 3,
};

export const WithSevenOrLessLast = Template.bind(null);
WithSevenOrLessLast.args = {
...defaultArgs, pages: 7, page: 7
}
export const WithSixOrLessLast = Template.bind(null);
WithSixOrLessLast.args = {
...defaultArgs,
pages: 6,
page: 6,
};

export const Internationalization = () => {
const [lang, setLang] = useState('en');
Expand All @@ -95,13 +105,25 @@ export const Internationalization = () => {

return (
<div>
<va-button onClick={() => setLang('es')} text="Español"/>
<va-button onClick={() => setLang('en')} text="English"/>
<va-button onClick={() => setLang('es')} text="Español" />
<va-button onClick={() => setLang('en')} text="English" />
<div style={{ marginTop: '20px' }}>
<h4>Default</h4>
<VaPagination page={page1} pages={24} maxPageListLength={7} onPageSelect={(event) => setPage1(event.detail.page) }/>
<VaPagination
page={page1}
pages={24}
maxPageListLength={10}
onPageSelect={event => setPage1(event.detail.page)}
/>
<h4>Unbounded</h4>
<VaPagination page={page2} pages={24} maxPageListLength={7} unbounded onPageSelect={(event) => setPage2(event.detail.page)}/>
<VaPagination
page={page2}
pages={24}
maxPageListLength={10}
unbounded
onPageSelect={event => setPage2(event.detail.page)}
/>
</div>
</div>
)};
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,61 @@ describe('va-pagination', () => {
// should be 8, 6 as set by the max-page-list-length, and 2 prev/next buttons
expect(paginationItems).toHaveLength(8);
});

it('renders the correct number of links on small screens', async () => {
const page = await newE2EPage();
await page.setViewport({
// iPhone X
width: 375,
height: 812,
deviceScaleFactor: 1,
});
await page.setContent(`<va-pagination page="1" pages="24" />`);
const paginationItems = await page.findAll(
'va-pagination >>> li.usa-pagination__item',
);
expect(paginationItems).toHaveLength(6);
});

it('renders one ellipse correctly on small screens', async () => {
const page = await newE2EPage();
await page.setViewport({
// iPhone X
width: 375,
height: 812,
deviceScaleFactor: 1,
});
await page.setContent(`<va-pagination page="2" pages="24" unbounded/>`);
const paginationOverflowItems = await page.findAll(
'va-pagination >>> li.usa-pagination__overflow',
);
expect(paginationOverflowItems).toHaveLength(1);
});

it('renders two ellipses correctly on small screens', async () => {
const page = await newE2EPage();
await page.setViewport({
// iPhone X
width: 375,
height: 812,
deviceScaleFactor: 1,
});
await page.setContent(`<va-pagination page="9" pages="24" />`);
const paginationOverflowItems = await page.findAll(
'va-pagination >>> li.usa-pagination__overflow',
);
expect(paginationOverflowItems).toHaveLength(2);
});

it('passes an axe check on small screens', async () => {
const page = await newE2EPage();
await page.setViewport({
// iPhone X
width: 375,
height: 812,
deviceScaleFactor: 1,
});
await page.setContent(`<va-pagination page="1" pages="24" />`);
await axeCheck(page);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
:host {
background-color: var(--vads-color-white);
border-top: 1px solid var(--vads-color-base-lightest);
container-type: inline-size;
display: flex;
font-family: var(--font-source-sans);
justify-content: center;
Expand Down Expand Up @@ -55,3 +56,9 @@ button {
transition: all 0.3s ease-in-out;
transition-property: color, background-color;
}

@container (max-width: 640px) { // Variables won't compile. Matching TSX file for now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Variables won't compile. Matching TSX file for now.

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having quite a time passing the USWDS $tablet variable into this container query. I tried var(--tablet) and $tablet and #${tablet} but they either wouldn't render the CSS rule at all, or failed during compilation. Happy to change it if there's something I'm missing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really interesting 🤔 I wonder if that's a Stencil limitation? Thanks for explaining!

Do you mind just mentioning in the comment that the value is for the --tablet variable/property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a limitation in Sass. I found this article Want CSS variables in media query declarations? Try this! that digs into the specifics of Sass variables in media and container queries. I'll update the comment explaining the issue.

.usa-pagination__overflow {
margin: 0;
}
}
Loading
Loading