File tree Expand file tree Collapse file tree 6 files changed +80
-1
lines changed Expand file tree Collapse file tree 6 files changed +80
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## caption
2
+
3
+ <code src =" ../examples/caption.tsx " >
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import Table from 'rc-table' ;
3
+ import '../../assets/index.less' ;
4
+
5
+ const columns = [
6
+ {
7
+ title : 'Name' ,
8
+ dataIndex : 'name' ,
9
+ key : 'name' ,
10
+ } ,
11
+ {
12
+ title : 'Age' ,
13
+ dataIndex : 'age' ,
14
+ key : 'age' ,
15
+ } ,
16
+ {
17
+ title : 'Address' ,
18
+ dataIndex : 'address' ,
19
+ key : 'address' ,
20
+ } ,
21
+ ] ;
22
+
23
+ const data = [
24
+ { name : 'John' , age : '25' , address : '1 A Street' } ,
25
+ { name : 'Fred' , age : '38' , address : '2 B Street' } ,
26
+ { name : 'Anne' , age : '47' , address : '3 C Street' } ,
27
+ ] ;
28
+
29
+ const Demo = ( ) => (
30
+ < div >
31
+ < h2 > Table with basic caption</ h2 >
32
+ < Table columns = { columns } data = { data } caption = "Users including age and address" />
33
+ < br />
34
+ < h2 > Table with complex caption</ h2 >
35
+ < Table
36
+ columns = { columns }
37
+ data = { data }
38
+ caption = {
39
+ < div style = { { textAlign : 'right' } } >
40
+ Users who are < em > old</ em >
41
+ </ div >
42
+ }
43
+ />
44
+ </ div >
45
+ ) ;
46
+
47
+ export default Demo ;
Original file line number Diff line number Diff line change @@ -129,9 +129,9 @@ export interface TableProps<RecordType = unknown>
129
129
rowClassName ?: string | RowClassName < RecordType > ;
130
130
131
131
// Additional Part
132
- title ?: PanelRender < RecordType > ;
133
132
footer ?: PanelRender < RecordType > ;
134
133
summary ?: ( data : readonly RecordType [ ] ) => React . ReactNode ;
134
+ caption ?: string | React . ReactNode ;
135
135
136
136
// Customize
137
137
id ?: string ;
@@ -187,6 +187,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
187
187
title,
188
188
footer,
189
189
summary,
190
+ caption,
190
191
191
192
// Customize
192
193
id,
@@ -611,6 +612,9 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
611
612
< ColGroup colWidths = { flattenColumns . map ( ( { width } ) => width ) } columns = { flattenColumns } />
612
613
) ;
613
614
615
+ const captionElement =
616
+ caption !== null && caption !== undefined ? < caption className = { `${ prefixCls } -caption` } > { caption } </ caption > : undefined ;
617
+
614
618
const customizeScrollBody = getComponent ( [ 'body' ] ) as CustomizeScrollBody < RecordType > ;
615
619
616
620
if (
@@ -662,6 +666,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
662
666
tableLayout : mergedTableLayout ,
663
667
} }
664
668
>
669
+ { captionElement }
665
670
{ bodyColGroup }
666
671
{ bodyTable }
667
672
{ ! fixFooter && summaryNode && (
@@ -743,6 +748,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
743
748
ref = { scrollBodyRef }
744
749
>
745
750
< TableComponent style = { { ...scrollTableStyle , tableLayout : mergedTableLayout } } >
751
+ { captionElement }
746
752
{ bodyColGroup }
747
753
{ showHeader !== false && < Header { ...headerProps } { ...columnContext } /> }
748
754
{ bodyTable }
Original file line number Diff line number Diff line change @@ -175,6 +175,8 @@ export interface LegacyExpandableProps<RecordType> {
175
175
expandedRowClassName ?: RowClassName < RecordType > ;
176
176
/** @deprecated Use `expandable.childrenColumnName` instead */
177
177
childrenColumnName ?: string ;
178
+ /** @deprecated Use `caption` instead */
179
+ title ?: PanelRender < RecordType > ;
178
180
}
179
181
180
182
export type ExpandedRowRender < ValueType > = (
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export function getExpandableProps<RecordType>(
32
32
'expandedRowClassName' ,
33
33
'expandIconColumnIndex' ,
34
34
'showExpandColumn' ,
35
+ 'title' ,
35
36
] . some ( prop => prop in props )
36
37
) {
37
38
warning ( false , 'expanded related props have been moved into `expandable`.' ) ;
Original file line number Diff line number Diff line change @@ -162,6 +162,26 @@ describe('Table.Basic', () => {
162
162
} ) ;
163
163
} ) ;
164
164
165
+ describe ( 'caption' , ( ) => {
166
+ it ( 'renders string caption' , ( ) => {
167
+ const miscProps = { caption : 'test_caption' } ;
168
+ const wrapper = mount ( createTable ( miscProps ) ) ;
169
+ expect ( wrapper . find ( '.rc-table-caption' ) ) . toBeTruthy ( ) ;
170
+ } ) ;
171
+
172
+ it ( 'renders React.Node caption' , ( ) => {
173
+ const miscProps = { caption : < div className = "caption_inner" /> } ;
174
+ const wrapper = mount ( createTable ( miscProps ) ) ;
175
+ expect ( wrapper . find ( '.rc-table-caption .caption_inner' ) ) . toBeTruthy ( ) ;
176
+ } ) ;
177
+
178
+ it ( 'renders without caption' , ( ) => {
179
+ const miscProps = { } ;
180
+ const wrapper = mount ( createTable ( miscProps ) ) ;
181
+ expect ( wrapper . find ( '.rc-table-caption' ) . length ) . toBeFalsy ( ) ;
182
+ } ) ;
183
+ } ) ;
184
+
165
185
it ( 'renders tableLayout' , ( ) => {
166
186
const wrapper = mount ( createTable ( { tableLayout : 'fixed' } ) ) ;
167
187
expect ( wrapper . find ( 'table' ) . props ( ) . style . tableLayout ) . toEqual ( 'fixed' ) ;
You can’t perform that action at this time.
0 commit comments