Skip to content

Commit abaed58

Browse files
committed
fix(ui-pagination): make Pagination wrap on smaller screen sizes and prevent scrollbars
INSTUI-4461
1 parent 142c508 commit abaed58

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
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/styles.ts

Lines changed: 5 additions & 2 deletions
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',
@@ -50,7 +52,8 @@ const generateStyle = (componentTheme: PaginationTheme): PaginationStyle => {
5052
pages: {
5153
label: 'pagination__pages',
5254
display: 'inline-flex',
53-
alignItems: 'center'
55+
alignItems: 'center',
56+
margin: '0.3rem'
5457
}
5558
}
5659
}

0 commit comments

Comments
 (0)