Skip to content

Commit f4c1525

Browse files
author
Guillaume Castellant
committed
[added] pagination boundaryLinks
fix(pagination) add test coverage fix(pagination) combined if statement
1 parent 79dc1ec commit f4c1525

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

Diff for: docs/examples/PaginationAdvanced.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const PaginationAdvanced = React.createClass({
1919
first
2020
last
2121
ellipsis
22+
boundaryLinks
2223
items={20}
2324
maxButtons={5}
2425
activePage={this.state.activePage}

Diff for: docs/src/sections/PaginationSection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function PaginationSection() {
1616
<ReactPlayground codeText={Samples.PaginationBasic} />
1717

1818
<h4><Anchor id="pagination-more">More options</Anchor></h4>
19-
<p>such as <code>first</code>, <code>last</code>, <code>previous</code>, <code>next</code> and <code>ellipsis</code>.</p>
19+
<p>such as <code>first</code>, <code>last</code>, <code>previous</code>, <code>next</code>, <code>boundaryLinks</code> and <code>ellipsis</code>.</p>
2020
<ReactPlayground codeText={Samples.PaginationAdvanced} />
2121

2222
<h3><Anchor id="pagination-props">Props</Anchor></h3>

Diff for: src/Pagination.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const Pagination = React.createClass({
1111
activePage: React.PropTypes.number,
1212
items: React.PropTypes.number,
1313
maxButtons: React.PropTypes.number,
14+
/**
15+
* When `true`, will display the first and the last button page
16+
*/
17+
boundaryLinks: React.PropTypes.bool,
1418
/**
1519
* When `true`, will display the default node value ('...').
1620
* Otherwise, will display provided node (when specified).
@@ -68,6 +72,7 @@ const Pagination = React.createClass({
6872
prev: false,
6973
next: false,
7074
ellipsis: true,
75+
boundaryLinks: false,
7176
buttonComponentClass: SafeAnchor,
7277
bsClass: 'pagination'
7378
};
@@ -82,7 +87,8 @@ const Pagination = React.createClass({
8287
items,
8388
onSelect,
8489
ellipsis,
85-
buttonComponentClass
90+
buttonComponentClass,
91+
boundaryLinks
8692
} = this.props;
8793

8894
if (maxButtons) {
@@ -117,6 +123,30 @@ const Pagination = React.createClass({
117123
);
118124
}
119125

126+
if (boundaryLinks && ellipsis && startPage !== 1) {
127+
pageButtons.unshift(
128+
<PaginationButton
129+
key="ellipsisFirst"
130+
disabled
131+
buttonComponentClass={buttonComponentClass}>
132+
<span aria-label="More">
133+
{this.props.ellipsis === true ? '...' : this.props.ellipsis}
134+
</span>
135+
</PaginationButton>
136+
);
137+
138+
pageButtons.unshift(
139+
<PaginationButton
140+
key={1}
141+
eventKey={1}
142+
active={false}
143+
onSelect={onSelect}
144+
buttonComponentClass={buttonComponentClass}>
145+
1
146+
</PaginationButton>
147+
);
148+
}
149+
120150
if (maxButtons && hasHiddenPagesAfter && ellipsis) {
121151
pageButtons.push(
122152
<PaginationButton
@@ -128,6 +158,19 @@ const Pagination = React.createClass({
128158
</span>
129159
</PaginationButton>
130160
);
161+
162+
if (boundaryLinks && endPage !== items) {
163+
pageButtons.push(
164+
<PaginationButton
165+
key={items}
166+
eventKey={items}
167+
active={false}
168+
onSelect={onSelect}
169+
buttonComponentClass={buttonComponentClass}>
170+
{items}
171+
</PaginationButton>
172+
);
173+
}
131174
}
132175

133176
return pageButtons;

Diff for: test/PaginationSpec.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Pagination', () => {
5353
pageButtons[4].className.should.match(/\bactive\b/);
5454
});
5555

56-
it('Should show the ellipsis, first, last, prev and next button with default labels', () => {
56+
it('Should show the ellipsis, boundaryLinks, first, last, prev and next button with default labels', () => {
5757
let instance = ReactTestUtils.renderIntoDocument(
5858
<Pagination
5959
first={true}
@@ -77,6 +77,27 @@ describe('Pagination', () => {
7777

7878
});
7979

80+
it('Should show the boundaryLinks, first, last, prev and next button', () => {
81+
let instance = ReactTestUtils.renderIntoDocument(
82+
<Pagination
83+
first={true}
84+
last={true}
85+
prev={true}
86+
next={true}
87+
ellipsis={true}
88+
boundaryLinks={true}
89+
maxButtons={3}
90+
activePage={10}
91+
items={20} />
92+
);
93+
let pageButtons = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'li');
94+
// add first, last, prev, next and ellipsis button
95+
assert.equal(pageButtons[2].innerText, '1');
96+
assert.equal(pageButtons[3].innerText, '...');
97+
assert.equal(pageButtons[7].innerText, '...');
98+
assert.equal(pageButtons[8].innerText, '20');
99+
});
100+
80101
it('Should show the ellipsis, first, last, prev and next button with custom labels', () => {
81102
let instance = ReactTestUtils.renderIntoDocument(
82103
<Pagination

0 commit comments

Comments
 (0)