Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pagination): pagination pagesize controlled #444

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export default defineComponent({
const { t, global } = useConfig('pagination');
const COMPONENT_NAME = usePrefixClass('pagination');

const { pageCount, ...paginationClasses } = usePaginationClasses(props, innerCurrent, COMPONENT_NAME);
const { pageCount, ...paginationClasses } = usePaginationClasses(
props,
innerCurrent,
innerPageSize,
COMPONENT_NAME,
);

const { prevMore, isPrevMoreShow, curPageLeftCount, nextMore, isNextMoreShow, curPageRightCount } = useMoreAction(
props,
Expand Down Expand Up @@ -115,7 +120,7 @@ export default defineComponent({
const pageInfo = {
current,
previous: prev,
pageSize: props.pageSize,
pageSize: innerPageSize.value,
};
if (isTriggerChange !== false) {
props.onChange?.(pageInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/pagination/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
/** 分页总页数 */
pageSize: {
type: Number,
default: 10,
default: undefined,
},
/** 分页总页数,非受控属性 */
defaultPageSize: {
Expand Down
9 changes: 7 additions & 2 deletions src/pagination/usePaginationClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { computed, Ref } from 'vue';
import CLASSNAMES from '../utils/classnames';
import { TdPaginationProps } from './type';

export default function usePaginationClasses(props: TdPaginationProps, innerCurrent: Ref<number>, name: Ref<string>) {
export default function usePaginationClasses(
props: TdPaginationProps,
innerCurrent: Ref<number>,
innerPageSize: Ref<number>,
name: Ref<string>,
) {
const pageCount = computed(() => {
const c: number = Math.ceil(props.total / props.pageSize);
const c: number = Math.ceil(props.total / innerPageSize.value);
return c > 0 ? c : 1;
});

Expand Down
16 changes: 8 additions & 8 deletions test/ssr/__snapshots__/ssr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38490,8 +38490,8 @@ exports[`ssr snapshot test renders ./examples/table/demos/pagination.vue correct
<ul class="t-select__groups t-select__list">
<!--[-->
<!--[-->
<li class="t-select-option t-size-m" title="5 条/页"><span>5 条/页</span></li>
<li class="t-select-option t-is-selected t-size-m" title="10 条/页"><span>10 条/页</span></li>
<li class="t-select-option t-is-selected t-size-m" title="5 条/页"><span>5 条/页</span></li>
<li class="t-select-option t-size-m" title="10 条/页"><span>10 条/页</span></li>
<li class="t-select-option t-size-m" title="20 条/页"><span>20 条/页</span></li>
<li class="t-select-option t-size-m" title="50 条/页"><span>50 条/页</span></li>
<!--]-->
Expand All @@ -38508,7 +38508,7 @@ exports[`ssr snapshot test renders ./examples/table/demos/pagination.vue correct
<!---->
<!---->
<!--[-->
<!--]--><span class="t-tag t-tag--default t-tag--dark t-size-m" style="display:none;"><!----><!--[-->+0<!--]--><!----></span><span title="10" class="t-select__single">10</span>
<!--]--><span class="t-tag t-tag--default t-tag--dark t-size-m" style="display:none;"><!----><!--[-->+0<!--]--><!----></span><span title="5" class="t-select__single">5</span>
<!----><svg class="t-fake-arrow t-select__right-icon t-select__right-icon-polyfill" width="16" height="16" viewbox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="">
<path d="M3.75 5.7998L7.99274 10.0425L12.2361 5.79921" stroke="black" stroke-opacity="0.9" stroke-width="1.3"></path>
</svg>
Expand All @@ -38522,18 +38522,18 @@ exports[`ssr snapshot test renders ./examples/table/demos/pagination.vue correct
<path fill="currentColor" d="M9.54 3.54l.92.92L6.92 8l3.54 3.54-.92.92L5.08 8l4.46-4.46z" fill-opacity="0.9"></path>
</svg></div>
<ul class="t-pagination__pager">
<!---->
<li class="t-pagination__number">1</li>
<!---->
<!--[-->
<li class="t-pagination__number">1</li>
<li class="t-pagination__number t-is-current">2</li>
<li class="t-pagination__number">3</li>
<li class="t-pagination__number">4</li>
<li class="t-pagination__number">5</li>
<li class="t-pagination__number">6</li>
<!--]-->
<!---->
<!---->
<li class="t-pagination__number t-pagination__number--more"><svg fill="none" viewbox="0 0 16 16" width="1em" height="1em" class="t-icon t-icon-ellipsis" style="">
<path fill="currentColor" d="M3 9a1 1 0 110-2 1 1 0 010 2zM7 8a1 1 0 102 0 1 1 0 00-2 0zM12 8a1 1 0 102 0 1 1 0 00-2 0z" fill-opacity="0.9"></path>
</svg></li>
<li class="t-pagination__number">12</li>
</ul>
<div class="t-pagination__btn t-pagination__btn-next"><svg fill="none" viewbox="0 0 16 16" width="1em" height="1em" class="t-icon t-icon-chevron-right" style="">
<path fill="currentColor" d="M6.46 12.46l-.92-.92L9.08 8 5.54 4.46l.92-.92L10.92 8l-4.46 4.46z" fill-opacity="0.9"></path>
Expand Down
36 changes: 25 additions & 11 deletions test/unit/table/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20283,15 +20283,15 @@ exports[`Table Table paginationVue demo works fine 1`] = `


<li
class="t-select-option t-size-m"
class="t-select-option t-is-selected t-size-m"
title="5 条/页"
>
<span>
5 条/页
</span>
</li>
<li
class="t-select-option t-is-selected t-size-m"
class="t-select-option t-size-m"
title="10 条/页"
>
<span>
Expand Down Expand Up @@ -20344,9 +20344,9 @@ exports[`Table Table paginationVue demo works fine 1`] = `
</span>
<span
class="t-select__single"
title="10"
title="5"
>
10
5
</span>
<!---->
<svg
Expand Down Expand Up @@ -20391,14 +20391,13 @@ exports[`Table Table paginationVue demo works fine 1`] = `
<ul
class="t-pagination__pager"
>
<!---->
<!---->

<li
class="t-pagination__number"
>
1
</li>
<!---->

<li
class="t-pagination__number t-is-current"
>
Expand All @@ -20419,14 +20418,29 @@ exports[`Table Table paginationVue demo works fine 1`] = `
>
5
</li>

<li
class="t-pagination__number t-pagination__number--more"
>
<svg
class="t-icon t-icon-ellipsis"
fill="none"
height="1em"
viewBox="0 0 16 16"
width="1em"
>
<path
d="M3 9a1 1 0 110-2 1 1 0 010 2zM7 8a1 1 0 102 0 1 1 0 00-2 0zM12 8a1 1 0 102 0 1 1 0 00-2 0z"
fill="currentColor"
fill-opacity="0.9"
/>
</svg>
</li>
<li
class="t-pagination__number"
>
6
12
</li>

<!---->
<!---->
</ul>
<div
class="t-pagination__btn t-pagination__btn-next"
Expand Down