Skip to content

Commit 75e1540

Browse files
committed
fix(ui-pagination): make Pagination wrap on smaller screen sizes and prevent scrollbars
INSTUI-4461
1 parent 318fb44 commit 75e1540

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

cypress/component/Pagination.cy.tsx

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424
import React from 'react'
25-
import { Pagination, ScreenReaderContent } from '../../packages/ui'
25+
import { Pagination, ScreenReaderContent } from '@instructure/ui'
2626

2727
import '../support/component'
2828
import 'cypress-real-events'
@@ -68,4 +68,54 @@ describe('<Pagination/>', () => {
6868
})
6969
})
7070
})
71+
72+
it('should wrap at a small viewport width', () => {
73+
cy.mount(
74+
<Pagination
75+
as="nav"
76+
margin="small"
77+
variant="compact"
78+
currentPage={4}
79+
totalPageNumber={100000}
80+
siblingCount={3}
81+
boundaryCount={2}
82+
/>
83+
)
84+
85+
cy.viewport(1000, 800)
86+
87+
cy.get('[role="navigation"]').within(() => {
88+
cy.get('button').then(($items) => {
89+
const firstItem = $items[0]
90+
const firstItemTop = firstItem.getBoundingClientRect().top
91+
92+
let hasWrapped = false
93+
$items.each((index, item) => {
94+
const itemTop = item.getBoundingClientRect().top
95+
if (index > 0 && itemTop > firstItemTop) {
96+
hasWrapped = true
97+
}
98+
})
99+
expect(hasWrapped).to.be.false
100+
})
101+
})
102+
103+
cy.viewport(300, 800)
104+
105+
cy.get('[role="navigation"]').within(() => {
106+
cy.get('button').then(($items) => {
107+
const firstItem = $items[0]
108+
const firstItemTop = firstItem.getBoundingClientRect().top
109+
110+
let hasWrapped = false
111+
$items.each((index, item) => {
112+
const itemTop = item.getBoundingClientRect().top
113+
if (index > 0 && itemTop > firstItemTop) {
114+
hasWrapped = true
115+
}
116+
})
117+
expect(hasWrapped).to.be.true
118+
})
119+
})
120+
})
71121
})

packages/ui-pagination/src/Pagination/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class Pagination extends Component<PaginationProps> {
105105
siblingCount: 1,
106106
boundaryCount: 1,
107107
ellipsis: '…',
108-
renderPageIndicator: (page: number) => page
108+
renderPageIndicator: (page: number) => page,
109+
margin: 'space8'
109110
}
110111

111112
static Page = PaginationButton

packages/ui-pagination/src/Pagination/props.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ type PaginationOwnProps = {
118118
variant?: 'full' | 'compact' | 'input'
119119

120120
/**
121-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
122-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
123-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
121+
* Spacing token values can be found here: [Spacing Tokens](https://instructure.design/#layout-spacing/%23Tokens)
122+
*
123+
* Apply these values via familiar CSS-like shorthand. For example: `margin="space8 0 space12"`.
124124
*/
125125
margin?: Spacing
126126

packages/ui-pagination/src/Pagination/styles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const generateStyle = (componentTheme: PaginationTheme): PaginationStyle => {
4141
all: 'unset',
4242
display: 'flex',
4343
alignItems: 'center',
44-
gap: componentTheme.pageIndicatorGap
44+
gap: componentTheme.pageIndicatorGap,
45+
flexWrap: 'wrap',
46+
justifyContent: 'center'
4547
},
4648
pagination: {
4749
label: 'pagination',

0 commit comments

Comments
 (0)