Skip to content

Commit 9c0758a

Browse files
authored
fix(Table): preserve pagination semantic classNames and styles (#59267)
1 parent 43bd281 commit 9c0758a

2 files changed

Lines changed: 81 additions & 3 deletions

File tree

‎components/table/InternalTable.tsx‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { omit, pickAttrs } from '@rc-component/util';
55
import { clsx } from 'clsx';
66

77
import { useProxyImperativeHandle } from '../_util/hooks';
8-
import { useMergeSemantic, useSemanticRootStyle } from '../_util/hooks/useMergeSemantic';
8+
import {
9+
mergeClassNames,
10+
mergeStyles,
11+
resolveStyleOrClass,
12+
useMergeSemantic,
13+
useSemanticRootStyle,
14+
} from '../_util/hooks/useMergeSemantic';
915
import type { GenerateSemantic } from '../_util/hooks/useMergeSemantic/semanticType';
1016
import { isFunction, isNumber, isPlainObject } from '../_util/is';
1117
import type { Breakpoint } from '../_util/responsiveObserver';
@@ -532,6 +538,15 @@ const InternalTable = <RecordType extends AnyObject = AnyObject>(
532538
pagination,
533539
);
534540

541+
const paginationClassNames: TablePaginationConfig['classNames'] = (info) =>
542+
mergeClassNames(
543+
{},
544+
mergedClassNames.pagination,
545+
resolveStyleOrClass(mergedPagination.classNames, info),
546+
);
547+
const paginationStyles: TablePaginationConfig['styles'] = (info) =>
548+
mergeStyles(resolveStyleOrClass(mergedPagination.styles, info), mergedStyles.pagination);
549+
535550
changeEventInfo.pagination =
536551
pagination === false ? {} : getPaginationParam(mergedPagination, pagination);
537552

@@ -631,8 +646,8 @@ const InternalTable = <RecordType extends AnyObject = AnyObject>(
631646
const renderPagination = (placement: 'start' | 'end' | 'center' = 'end') => (
632647
<Pagination
633648
{...mergedPagination}
634-
classNames={mergedClassNames.pagination}
635-
styles={mergedStyles.pagination}
649+
classNames={paginationClassNames}
650+
styles={paginationStyles}
636651
className={clsx(
637652
`${prefixCls}-pagination`,
638653
`${prefixCls}-pagination-${placement}`,

‎components/table/__tests__/semantic.test.tsx‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,69 @@ describe('Table', () => {
209209
});
210210
});
211211

212+
it('should merge pagination classNames and styles', () => {
213+
const { container } = render(
214+
<Table
215+
columns={[{ dataIndex: 'name' }]}
216+
dataSource={[
217+
{ key: '1', name: 'Bamboo' },
218+
{ key: '2', name: 'Little' },
219+
]}
220+
classNames={{
221+
pagination: {
222+
root: 'table-pagination-root',
223+
item: 'table-pagination-item',
224+
},
225+
}}
226+
styles={{
227+
pagination: {
228+
root: {
229+
backgroundColor: 'rgb(0, 0, 255)',
230+
color: 'rgb(0, 0, 0)',
231+
},
232+
item: {
233+
backgroundColor: 'rgb(0, 255, 0)',
234+
color: 'rgb(0, 0, 0)',
235+
},
236+
},
237+
}}
238+
pagination={{
239+
pageSize: 1,
240+
classNames: {
241+
root: 'pagination-root',
242+
item: 'pagination-item',
243+
},
244+
styles: {
245+
root: {
246+
color: 'rgb(255, 0, 0)',
247+
borderTopWidth: '1px',
248+
},
249+
item: {
250+
color: 'rgb(255, 165, 0)',
251+
borderLeftWidth: '2px',
252+
},
253+
},
254+
}}
255+
/>,
256+
);
257+
258+
const paginationRoot = container.querySelector('.ant-pagination');
259+
const paginationItem = container.querySelector('.ant-pagination-item');
260+
261+
expect(paginationRoot).toHaveClass('table-pagination-root', 'pagination-root');
262+
expect(paginationRoot).toHaveStyle({
263+
backgroundColor: 'rgb(0, 0, 255)',
264+
color: 'rgb(0, 0, 0)',
265+
borderTopWidth: '1px',
266+
});
267+
expect(paginationItem).toHaveClass('table-pagination-item', 'pagination-item');
268+
expect(paginationItem).toHaveStyle({
269+
backgroundColor: 'rgb(0, 255, 0)',
270+
color: 'rgb(0, 0, 0)',
271+
borderLeftWidth: '2px',
272+
});
273+
});
274+
212275
it('should work with function classNames and styles', () => {
213276
const columns = [
214277
{

0 commit comments

Comments
 (0)