Skip to content

Commit fcb36a1

Browse files
committed
Merge pull request react-bootstrap#1376 from mdziekon/pagination-custom-labels
[added] Custom labels for Pagination's special element
2 parents 69bca94 + b67bb44 commit fcb36a1

2 files changed

Lines changed: 81 additions & 11 deletions

File tree

src/Pagination.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,46 @@ const Pagination = React.createClass({
1212
activePage: React.PropTypes.number,
1313
items: React.PropTypes.number,
1414
maxButtons: React.PropTypes.number,
15-
ellipsis: React.PropTypes.bool,
16-
first: React.PropTypes.bool,
17-
last: React.PropTypes.bool,
18-
prev: React.PropTypes.bool,
19-
next: React.PropTypes.bool,
15+
/**
16+
* When `true`, will display the default node value ('...').
17+
* Otherwise, will display provided node (when specified).
18+
*/
19+
ellipsis: React.PropTypes.oneOfType([
20+
React.PropTypes.bool,
21+
React.PropTypes.node
22+
]),
23+
/**
24+
* When `true`, will display the default node value ('«').
25+
* Otherwise, will display provided node (when specified).
26+
*/
27+
first: React.PropTypes.oneOfType([
28+
React.PropTypes.bool,
29+
React.PropTypes.node
30+
]),
31+
/**
32+
* When `true`, will display the default node value ('»').
33+
* Otherwise, will display provided node (when specified).
34+
*/
35+
last: React.PropTypes.oneOfType([
36+
React.PropTypes.bool,
37+
React.PropTypes.node
38+
]),
39+
/**
40+
* When `true`, will display the default node value ('‹').
41+
* Otherwise, will display provided node (when specified).
42+
*/
43+
prev: React.PropTypes.oneOfType([
44+
React.PropTypes.bool,
45+
React.PropTypes.node
46+
]),
47+
/**
48+
* When `true`, will display the default node value ('›').
49+
* Otherwise, will display provided node (when specified).
50+
*/
51+
next: React.PropTypes.oneOfType([
52+
React.PropTypes.bool,
53+
React.PropTypes.node
54+
]),
2055
onSelect: React.PropTypes.func,
2156
/**
2257
* You can use a custom element for the buttons
@@ -89,7 +124,9 @@ const Pagination = React.createClass({
89124
key="ellipsis"
90125
disabled
91126
buttonComponentClass={buttonComponentClass}>
92-
<span aria-label="More">...</span>
127+
<span aria-label="More">
128+
{this.props.ellipsis === true ? '...' : this.props.ellipsis}
129+
</span>
93130
</PaginationButton>
94131
);
95132
}
@@ -109,7 +146,9 @@ const Pagination = React.createClass({
109146
disabled={this.props.activePage === 1}
110147
onSelect={this.props.onSelect}
111148
buttonComponentClass={this.props.buttonComponentClass}>
112-
<span aria-label="Previous">&lsaquo;</span>
149+
<span aria-label="Previous">
150+
{this.props.prev === true ? '\u2039' : this.props.prev}
151+
</span>
113152
</PaginationButton>
114153
);
115154
},
@@ -126,7 +165,9 @@ const Pagination = React.createClass({
126165
disabled={this.props.activePage >= this.props.items}
127166
onSelect={this.props.onSelect}
128167
buttonComponentClass={this.props.buttonComponentClass}>
129-
<span aria-label="Next">&rsaquo;</span>
168+
<span aria-label="Next">
169+
{this.props.next === true ? '\u203a' : this.props.next}
170+
</span>
130171
</PaginationButton>
131172
);
132173
},
@@ -143,7 +184,9 @@ const Pagination = React.createClass({
143184
disabled={this.props.activePage === 1 }
144185
onSelect={this.props.onSelect}
145186
buttonComponentClass={this.props.buttonComponentClass}>
146-
<span aria-label="First">&laquo;</span>
187+
<span aria-label="First">
188+
{this.props.first === true ? '\u00ab' : this.props.first}
189+
</span>
147190
</PaginationButton>
148191
);
149192
},
@@ -160,7 +203,9 @@ const Pagination = React.createClass({
160203
disabled={this.props.activePage >= this.props.items}
161204
onSelect={this.props.onSelect}
162205
buttonComponentClass={this.props.buttonComponentClass}>
163-
<span aria-label="Last">&raquo;</span>
206+
<span aria-label="Last">
207+
{this.props.last === true ? '\u00bb' : this.props.last}
208+
</span>
164209
</PaginationButton>
165210
);
166211
},

test/PaginationSpec.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ describe('Pagination', () => {
5353
pageButtons[4].className.should.match(/\bactive\b/);
5454
});
5555

56-
it('Should show the ellipsis, first, last, prev and next button', () => {
56+
it('Should show the ellipsis, first, last, prev and next button with default labels', () => {
5757
let instance = ReactTestUtils.renderIntoDocument(
5858
<Pagination
5959
first={true}
6060
last={true}
6161
prev={true}
6262
next={true}
63+
ellipsis={true}
6364
maxButtons={3}
6465
activePage={10}
6566
items={20} />
@@ -76,6 +77,30 @@ describe('Pagination', () => {
7677

7778
});
7879

80+
it('Should show the ellipsis, first, last, prev and next button with custom labels', () => {
81+
let instance = ReactTestUtils.renderIntoDocument(
82+
<Pagination
83+
first='first'
84+
last='last'
85+
prev='prev'
86+
next='next'
87+
ellipsis='more'
88+
maxButtons={3}
89+
activePage={10}
90+
items={20} />
91+
);
92+
let pageButtons = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'li');
93+
// add first, last, prev, next and ellipsis button
94+
assert.equal(pageButtons.length, 8);
95+
96+
assert.equal(React.findDOMNode(pageButtons[0]).innerText, 'first');
97+
assert.equal(React.findDOMNode(pageButtons[1]).innerText, 'prev');
98+
assert.equal(React.findDOMNode(pageButtons[5]).innerText, 'more');
99+
assert.equal(React.findDOMNode(pageButtons[6]).innerText, 'next');
100+
assert.equal(React.findDOMNode(pageButtons[7]).innerText, 'last');
101+
102+
});
103+
79104
it('Should enumerate pagenums correctly when ellipsis=true', () => {
80105
const instance = ReactTestUtils.renderIntoDocument(
81106
<Pagination

0 commit comments

Comments
 (0)