mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Pagination): add show-prev-button, show-next-button props (#11780)
This commit is contained in:
parent
c7df4290e2
commit
a052b410cb
@ -6,6 +6,7 @@ import {
|
|||||||
} from 'vue';
|
} from 'vue';
|
||||||
import {
|
import {
|
||||||
clamp,
|
clamp,
|
||||||
|
truthProp,
|
||||||
makeStringProp,
|
makeStringProp,
|
||||||
makeNumberProp,
|
makeNumberProp,
|
||||||
makeNumericProp,
|
makeNumericProp,
|
||||||
@ -40,6 +41,8 @@ export const paginationProps = {
|
|||||||
showPageSize: makeNumericProp(5),
|
showPageSize: makeNumericProp(5),
|
||||||
itemsPerPage: makeNumericProp(10),
|
itemsPerPage: makeNumericProp(10),
|
||||||
forceEllipses: Boolean,
|
forceEllipses: Boolean,
|
||||||
|
showPrevButton: truthProp,
|
||||||
|
showNextButton: truthProp,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PaginationProps = ExtractPropTypes<typeof paginationProps>;
|
export type PaginationProps = ExtractPropTypes<typeof paginationProps>;
|
||||||
@ -128,7 +131,12 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const renderPrevButton = () => {
|
const renderPrevButton = () => {
|
||||||
const { mode, modelValue } = props;
|
const { mode, modelValue, showPrevButton } = props;
|
||||||
|
|
||||||
|
if (!showPrevButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const slot = slots['prev-text'];
|
const slot = slots['prev-text'];
|
||||||
const disabled = modelValue === 1;
|
const disabled = modelValue === 1;
|
||||||
return (
|
return (
|
||||||
@ -150,7 +158,12 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderNextButton = () => {
|
const renderNextButton = () => {
|
||||||
const { mode, modelValue } = props;
|
const { mode, modelValue, showNextButton } = props;
|
||||||
|
|
||||||
|
if (!showNextButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const slot = slots['next-text'];
|
const slot = slots['next-text'];
|
||||||
const disabled = modelValue === count.value;
|
const disabled = modelValue === count.value;
|
||||||
return (
|
return (
|
||||||
|
@ -81,6 +81,8 @@ export default {
|
|||||||
| page-count | The total number of pages, if not set, will be calculated based on `total-items` and `items-per-page` | _number \| string_ | `-` |
|
| page-count | The total number of pages, if not set, will be calculated based on `total-items` and `items-per-page` | _number \| string_ | `-` |
|
||||||
| show-page-size | Count of page size to show | _number \| string_ | `5` |
|
| show-page-size | Count of page size to show | _number \| string_ | `5` |
|
||||||
| force-ellipses | Whether to show ellipses | _boolean_ | `false` |
|
| force-ellipses | Whether to show ellipses | _boolean_ | `false` |
|
||||||
|
| show-prev-button `v4.2.1` | Whether to show prev button | _boolean_ | `true` |
|
||||||
|
| show-next-button `v4.2.1` | Whether to show next button | _boolean_ | `true` |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -89,6 +89,8 @@ export default {
|
|||||||
| items-per-page | 每页记录数 | _number \| string_ | `10` |
|
| items-per-page | 每页记录数 | _number \| string_ | `10` |
|
||||||
| show-page-size | 显示的页码个数 | _number \| string_ | `5` |
|
| show-page-size | 显示的页码个数 | _number \| string_ | `5` |
|
||||||
| force-ellipses | 是否显示省略号 | _boolean_ | `false` |
|
| force-ellipses | 是否显示省略号 | _boolean_ | `false` |
|
||||||
|
| show-prev-button `v4.2.1` | 是否展示上一页按钮 | _boolean_ | `true` |
|
||||||
|
| show-next-button `v4.2.1` | 是否展示下一页按钮 | _boolean_ | `true` |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -52,3 +52,17 @@ test('should emit change event after the page is changed', async () => {
|
|||||||
await wrapper.find('.van-pagination__item--next button').trigger('click');
|
await wrapper.find('.van-pagination__item--next button').trigger('click');
|
||||||
expect(wrapper.emitted('change')).toEqual([[3], [2], [3]]);
|
expect(wrapper.emitted('change')).toEqual([[3], [2], [3]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should allow to hide prev button and next button', () => {
|
||||||
|
const wrapper = mount(Pagination, {
|
||||||
|
props: {
|
||||||
|
totalItems: 50,
|
||||||
|
showPageSize: 5,
|
||||||
|
showPrevButton: false,
|
||||||
|
showNextButton: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('.van-pagination__item--prev').exists()).toBeFalsy();
|
||||||
|
expect(wrapper.find('.van-pagination__item--next').exists()).toBeFalsy();
|
||||||
|
});
|
||||||
|
@ -2,12 +2,12 @@ import {
|
|||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
computed,
|
computed,
|
||||||
|
nextTick,
|
||||||
reactive,
|
reactive,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
type PropType,
|
type PropType,
|
||||||
type CSSProperties,
|
type CSSProperties,
|
||||||
type ExtractPropTypes,
|
type ExtractPropTypes,
|
||||||
nextTick,
|
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
@ -16,13 +16,13 @@ import {
|
|||||||
isHidden,
|
isHidden,
|
||||||
unitToPx,
|
unitToPx,
|
||||||
numericProp,
|
numericProp,
|
||||||
|
windowWidth,
|
||||||
|
windowHeight,
|
||||||
getScrollTop,
|
getScrollTop,
|
||||||
getZIndexStyle,
|
getZIndexStyle,
|
||||||
makeStringProp,
|
makeStringProp,
|
||||||
makeNumericProp,
|
makeNumericProp,
|
||||||
createNamespace,
|
createNamespace,
|
||||||
windowWidth,
|
|
||||||
windowHeight,
|
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
|
|
||||||
// Composables
|
// Composables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user