Skip to content

Commit 4dba2f1

Browse files
authored
fix(Pagination): set a default activePage in Pagination's state (#4037)
1 parent ebdb893 commit 4dba2f1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/addons/Pagination/Pagination.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import PaginationItem from './PaginationItem'
1515
* A component to render a pagination.
1616
*/
1717
export default class Pagination extends Component {
18+
getInitialAutoControlledState() {
19+
return { activePage: 1 }
20+
}
21+
1822
handleItemClick = (e, { value: nextActivePage }) => {
1923
const { activePage: prevActivePage } = this.state
2024

test/specs/addons/Pagination/Pagination-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,25 @@ describe('Pagination', () => {
7878
onPageChange.should.have.not.been.called()
7979
})
8080
})
81+
82+
describe('activePage', () => {
83+
it('defaults to "1"', () => {
84+
const wrapper = mount(<Pagination totalPages={3} />)
85+
86+
wrapper.find('PaginationItem').at(1).prop('value').should.equal(1)
87+
wrapper.find('PaginationItem').at(5).prop('value').should.equal(2)
88+
})
89+
90+
it('can be set via "defaultActivePage"', () => {
91+
const wrapper = mount(<Pagination defaultActivePage={2} totalPages={3} />)
92+
93+
wrapper.find('PaginationItem').at(3).should.have.prop('active')
94+
})
95+
96+
it('can be set via "activePage"', () => {
97+
const wrapper = mount(<Pagination activePage={2} totalPages={3} />)
98+
99+
wrapper.find('PaginationItem').at(3).should.have.prop('active')
100+
})
101+
})
81102
})

0 commit comments

Comments
 (0)