Skip to content

Commit 0b0ac36

Browse files
committedOct 3, 2015
[added] Custom labels for Pagination's special element
(ellipsis, first, last, prev & next)
1 parent 1403cd3 commit 0b0ac36

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
 

‎src/Pagination.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const Pagination = React.createClass({
1717
last: React.PropTypes.bool,
1818
prev: React.PropTypes.bool,
1919
next: React.PropTypes.bool,
20+
firstLabel: React.PropTypes.node,
21+
lastLabel: React.PropTypes.node,
22+
prevLabel: React.PropTypes.node,
23+
nextLabel: React.PropTypes.node,
24+
ellipsisLabel: React.PropTypes.node,
2025
onSelect: React.PropTypes.func,
2126
/**
2227
* You can use a custom element for the buttons
@@ -34,6 +39,11 @@ const Pagination = React.createClass({
3439
prev: false,
3540
next: false,
3641
ellipsis: true,
42+
firstLabel: '\u00ab',
43+
lastLabel: '\u00bb',
44+
prevLabel: '\u2039',
45+
nextLabel: '\u203a',
46+
ellipsisLabel: '...',
3747
buttonComponentClass: SafeAnchor,
3848
bsClass: 'pagination'
3949
};
@@ -89,7 +99,7 @@ const Pagination = React.createClass({
8999
key="ellipsis"
90100
disabled
91101
buttonComponentClass={buttonComponentClass}>
92-
<span aria-label="More">...</span>
102+
<span aria-label="More">{this.props.ellipsisLabel}</span>
93103
</PaginationButton>
94104
);
95105
}
@@ -109,7 +119,7 @@ const Pagination = React.createClass({
109119
disabled={this.props.activePage === 1}
110120
onSelect={this.props.onSelect}
111121
buttonComponentClass={this.props.buttonComponentClass}>
112-
<span aria-label="Previous">&lsaquo;</span>
122+
<span aria-label="Previous">{this.props.prevLabel}</span>
113123
</PaginationButton>
114124
);
115125
},
@@ -126,7 +136,7 @@ const Pagination = React.createClass({
126136
disabled={this.props.activePage >= this.props.items}
127137
onSelect={this.props.onSelect}
128138
buttonComponentClass={this.props.buttonComponentClass}>
129-
<span aria-label="Next">&rsaquo;</span>
139+
<span aria-label="Next">{this.props.nextLabel}</span>
130140
</PaginationButton>
131141
);
132142
},
@@ -143,7 +153,7 @@ const Pagination = React.createClass({
143153
disabled={this.props.activePage === 1 }
144154
onSelect={this.props.onSelect}
145155
buttonComponentClass={this.props.buttonComponentClass}>
146-
<span aria-label="First">&laquo;</span>
156+
<span aria-label="First">{this.props.firstLabel}</span>
147157
</PaginationButton>
148158
);
149159
},
@@ -160,7 +170,7 @@ const Pagination = React.createClass({
160170
disabled={this.props.activePage >= this.props.items}
161171
onSelect={this.props.onSelect}
162172
buttonComponentClass={this.props.buttonComponentClass}>
163-
<span aria-label="Last">&raquo;</span>
173+
<span aria-label="Last">{this.props.lastLabel}</span>
164174
</PaginationButton>
165175
);
166176
},

‎test/PaginationSpec.js

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

55-
it('Should show the ellipsis, first, last, prev and next button', () => {
55+
it('Should show the ellipsis, first, last, prev and next button with default labels', () => {
5656
let instance = ReactTestUtils.renderIntoDocument(
5757
<Pagination
5858
first={true}
@@ -75,6 +75,34 @@ describe('Pagination', () => {
7575

7676
});
7777

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

0 commit comments

Comments
 (0)