♻️(react) update Pagination behavior
We want to make the Pagination more intuitive and fluent. Now it displays the current page all the time, auto select, auto submits on blur.
This commit is contained in:
5
.changeset/poor-dragons-dress.md
Normal file
5
.changeset/poor-dragons-dress.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@openfun/cunningham-react": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
improve Pagination behavior
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { Fragment, useState } from "react";
|
import React, { Fragment, useEffect, useState } from "react";
|
||||||
import { Button } from ":/components/Button";
|
import { Button } from ":/components/Button";
|
||||||
import { Input } from ":/components/Forms/Input";
|
import { Input } from ":/components/Forms/Input";
|
||||||
import { useCunningham } from ":/components/Provider";
|
import { useCunningham } from ":/components/Provider";
|
||||||
@@ -47,6 +47,10 @@ export const Pagination = ({
|
|||||||
const { t } = useCunningham();
|
const { t } = useCunningham();
|
||||||
const [gotoValue, setGotoValue] = useState("");
|
const [gotoValue, setGotoValue] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setGotoValue(page + "");
|
||||||
|
}, [page]);
|
||||||
|
|
||||||
if (pagesCount <= 1) {
|
if (pagesCount <= 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -83,14 +87,13 @@ export const Pagination = ({
|
|||||||
|
|
||||||
const gotoPage = () => {
|
const gotoPage = () => {
|
||||||
let value = +gotoValue;
|
let value = +gotoValue;
|
||||||
if (value < 0) {
|
if (value < 0 || !value) {
|
||||||
value = 1;
|
value = 1;
|
||||||
}
|
}
|
||||||
if (value > pagesCount) {
|
if (value > pagesCount) {
|
||||||
value = pagesCount;
|
value = pagesCount;
|
||||||
}
|
}
|
||||||
onPageChange(value);
|
onPageChange(value);
|
||||||
setGotoValue("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const canPrevious = page > 1;
|
const canPrevious = page > 1;
|
||||||
@@ -161,6 +164,8 @@ export const Pagination = ({
|
|||||||
onChange={(e) => setGotoValue(e.target.value)}
|
onChange={(e) => setGotoValue(e.target.value)}
|
||||||
min={1}
|
min={1}
|
||||||
max={pagesCount}
|
max={pagesCount}
|
||||||
|
onBlur={() => gotoPage()}
|
||||||
|
onFocus={(e) => e.target.select()}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"components": {
|
"components": {
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"goto_label": "Go to",
|
"goto_label": "Go to page",
|
||||||
"goto_label_aria": "Go to any page",
|
"goto_label_aria": "Go to any page",
|
||||||
"next_aria": "Go to next page",
|
"next_aria": "Go to next page",
|
||||||
"previous_aria": "Go to previous page",
|
"previous_aria": "Go to previous page",
|
||||||
|
|||||||
Reference in New Issue
Block a user