Skip to content

Commit 9808c39

Browse files
committed
🐛 fix pagination component bugs on less than 5page
#262
1 parent 1bd77d4 commit 9808c39

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

lib/pagination/index.js

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,38 @@ class Pagination extends Component {
3636

3737
const steps = [];
3838

39-
// eslint-disable-next-line no-restricted-syntax
40-
for (const key of Array(3).keys()) {
41-
let page;
42-
43-
if (currentActive > 2) {
44-
if (currentActive >= total - 1) {
45-
page = (key - 3) + total;
39+
if (total >= 3) {
40+
const innerSteps = total > 5 ? 3 : (total - 2); // FIX THIS for 3,4 pages
41+
// eslint-disable-next-line no-restricted-syntax
42+
for (const key of Array(innerSteps).keys()) {
43+
let page;
44+
45+
if (currentActive > 2) {
46+
if ((currentActive >= total - 1) && total > 4) {
47+
page = (key - 3) + total;
48+
} else if (total === 4 && currentActive === 4) {
49+
page = currentActive + (key - 2);
50+
} else {
51+
page = currentActive + (key - 1);
52+
}
4653
} else {
47-
page = currentActive + (key - 1);
54+
page = key + 2;
4855
}
49-
} else {
50-
page = key + 2;
56+
/* eslint-disable jsx-a11y/click-events-have-key-events */
57+
/* eslint-disable jsx-a11y/no-static-element-interactions */
58+
steps.push(<div
59+
className={classnames(theme['pagination-steps'], {
60+
[theme.active]: page === currentActive,
61+
})}
62+
data-react-active-page={page === currentActive ? 'active' : undefined}
63+
key={page}
64+
onClick={() => this.navigate(page)}
65+
>
66+
{page}
67+
{/* eslint-disable-next-line react/jsx-closing-tag-location */}
68+
</div>);
5169
}
52-
/* eslint-disable jsx-a11y/click-events-have-key-events */
53-
/* eslint-disable jsx-a11y/no-static-element-interactions */
54-
steps.push(<div
55-
className={classnames(theme['pagination-steps'], {
56-
[theme.active]: page === currentActive,
57-
})}
58-
data-react-active-page={page === currentActive ? 'active' : undefined}
59-
key={page}
60-
onClick={() => this.navigate(page)}
61-
>
62-
{page}
63-
{/* eslint-disable-next-line react/jsx-closing-tag-location */}
64-
</div>);
6570
}
66-
6771
return [
6872
<div
6973
className={classnames(theme['pagination-steps'], {
@@ -75,19 +79,21 @@ class Pagination extends Component {
7579
>
7680
{1}
7781
</div>,
78-
currentActive > 2 ? this.renderDots('left') : null,
79-
steps,
80-
currentActive < total - 1 ? this.renderDots('right') : null,
81-
<div
82-
className={classnames(theme['pagination-steps'], {
83-
[theme.active]: total === currentActive,
84-
})}
85-
key={total}
86-
data-react-active-page={total === currentActive ? 'active' : undefined}
87-
onClick={() => this.navigate(total)}
88-
>
89-
{total}
90-
</div>,
82+
total > 5 && currentActive > 2 ? this.renderDots('left') : null,
83+
total >= 3 && steps,
84+
total > 5 && currentActive < total - 1 ? this.renderDots('right') : null,
85+
total >= 2 && (
86+
<div
87+
className={classnames(theme['pagination-steps'], {
88+
[theme.active]: total === currentActive,
89+
})}
90+
key={total}
91+
data-react-active-page={total === currentActive ? 'active' : undefined}
92+
onClick={() => this.navigate(total)}
93+
>
94+
{total}
95+
</div>
96+
),
9197
];
9298
};
9399

0 commit comments

Comments
 (0)