Skip to content

Commit d9cdfa6

Browse files
committed
fix: descriptions warning, close #5250
1 parent 2d0e2b6 commit d9cdfa6

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

components/descriptions/__tests__/__snapshots__/index.test.js.snap

+28-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`Descriptions Descriptions support colon 1`] = `
77
<table>
88
<tbody>
99
<tr class="ant-descriptions-row">
10-
<td class="ant-descriptions-item" colspan="3">
10+
<td class="ant-descriptions-item" colspan="1">
1111
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label ant-descriptions-item-no-colon">Product</span><span class="ant-descriptions-item-content">Cloud Database</span></div>
1212
</td>
1313
</tr>
@@ -24,7 +24,7 @@ exports[`Descriptions Descriptions support style 1`] = `
2424
<table>
2525
<tbody>
2626
<tr class="ant-descriptions-row">
27-
<td class="ant-descriptions-item" colspan="3">
27+
<td class="ant-descriptions-item" colspan="1">
2828
<div class="ant-descriptions-item-container">
2929
<!----><span class="ant-descriptions-item-content">Cloud Database</span>
3030
</div>
@@ -43,7 +43,7 @@ exports[`Descriptions Descriptions.Item support className 1`] = `
4343
<table>
4444
<tbody>
4545
<tr class="ant-descriptions-row">
46-
<td class="ant-descriptions-item my-class" colspan="3">
46+
<td class="ant-descriptions-item my-class" colspan="1">
4747
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Product</span><span class="ant-descriptions-item-content">Cloud Database</span></div>
4848
</td>
4949
</tr>
@@ -93,43 +93,51 @@ exports[`Descriptions vertical layout 1`] = `
9393
<!---->
9494
</div>
9595
</th>
96-
<th class="ant-descriptions-item" colspan="1">
97-
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Billing</span>
98-
<!---->
99-
</div>
100-
</th>
101-
<th class="ant-descriptions-item" colspan="1">
102-
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">time</span>
103-
<!---->
104-
</div>
105-
</th>
10696
</tr>
10797
<tr class="ant-descriptions-row">
10898
<td class="ant-descriptions-item" colspan="1">
10999
<div class="ant-descriptions-item-container">
110100
<!----><span class="ant-descriptions-item-content">Cloud Database</span>
111101
</div>
112102
</td>
103+
</tr>
104+
<tr class="ant-descriptions-row">
105+
<th class="ant-descriptions-item" colspan="1">
106+
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Billing</span>
107+
<!---->
108+
</div>
109+
</th>
110+
</tr>
111+
<tr class="ant-descriptions-row">
113112
<td class="ant-descriptions-item" colspan="1">
114113
<div class="ant-descriptions-item-container">
115114
<!----><span class="ant-descriptions-item-content">Prepaid</span>
116115
</div>
117116
</td>
117+
</tr>
118+
<tr class="ant-descriptions-row">
119+
<th class="ant-descriptions-item" colspan="1">
120+
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">time</span>
121+
<!---->
122+
</div>
123+
</th>
124+
</tr>
125+
<tr class="ant-descriptions-row">
118126
<td class="ant-descriptions-item" colspan="1">
119127
<div class="ant-descriptions-item-container">
120128
<!----><span class="ant-descriptions-item-content">18:00:00</span>
121129
</div>
122130
</td>
123131
</tr>
124132
<tr class="ant-descriptions-row">
125-
<th class="ant-descriptions-item" colspan="3">
133+
<th class="ant-descriptions-item" colspan="1">
126134
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Amount</span>
127135
<!---->
128136
</div>
129137
</th>
130138
</tr>
131139
<tr class="ant-descriptions-row">
132-
<td class="ant-descriptions-item" colspan="3">
140+
<td class="ant-descriptions-item" colspan="1">
133141
<div class="ant-descriptions-item-container">
134142
<!----><span class="ant-descriptions-item-content">$80.00</span>
135143
</div>
@@ -151,15 +159,19 @@ exports[`Descriptions when item is rendered conditionally 1`] = `
151159
<td class="ant-descriptions-item" colspan="1">
152160
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Product</span><span class="ant-descriptions-item-content">Cloud Database</span></div>
153161
</td>
162+
</tr>
163+
<tr class="ant-descriptions-row">
154164
<td class="ant-descriptions-item" colspan="1">
155165
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Billing</span><span class="ant-descriptions-item-content">Prepaid</span></div>
156166
</td>
167+
</tr>
168+
<tr class="ant-descriptions-row">
157169
<td class="ant-descriptions-item" colspan="1">
158170
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">time</span><span class="ant-descriptions-item-content">18:00:00</span></div>
159171
</td>
160172
</tr>
161173
<tr class="ant-descriptions-row">
162-
<td class="ant-descriptions-item" colspan="3">
174+
<td class="ant-descriptions-item" colspan="1">
163175
<div class="ant-descriptions-item-container"><span class="ant-descriptions-item-label">Amount</span><span class="ant-descriptions-item-content">$80.00</span></div>
164176
</td>
165177
</tr>

components/descriptions/index.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import type {
99
CSSProperties,
1010
InjectionKey,
1111
} from 'vue';
12-
import { ref, defineComponent, onMounted, onBeforeUnmount, provide, toRef, computed } from 'vue';
12+
import {
13+
onBeforeMount,
14+
ref,
15+
defineComponent,
16+
onBeforeUnmount,
17+
provide,
18+
toRef,
19+
computed,
20+
} from 'vue';
1321
import warning from '../_util/warning';
1422
import type { Breakpoint, ScreenMap } from '../_util/responsiveObserve';
1523
import ResponsiveObserve, { responsiveArray } from '../_util/responsiveObserve';
@@ -78,7 +86,6 @@ function getFilledItem(node: VNode, span: number | undefined, rowRestCol: number
7886
clone = cloneElement(node, {
7987
span: rowRestCol,
8088
});
81-
8289
warning(
8390
span === undefined,
8491
'Descriptions',
@@ -95,7 +102,6 @@ function getRows(children: VNode[], column: number) {
95102

96103
let tmpRow: VNode[] = [];
97104
let rowRestCol = column;
98-
99105
childNodes.forEach((node, index) => {
100106
const span: number | undefined = node.props?.span;
101107
const mergedSpan = span || 1;
@@ -155,17 +161,13 @@ const Descriptions = defineComponent({
155161
Item: DescriptionsItem,
156162
setup(props, { slots }) {
157163
const { prefixCls, direction } = useConfigInject('descriptions', props);
158-
159164
let token: number;
160-
161165
const screens = ref<ScreenMap>({});
162-
163-
onMounted(() => {
166+
onBeforeMount(() => {
164167
token = ResponsiveObserve.subscribe(screen => {
165168
if (typeof props.column !== 'object') {
166169
return;
167170
}
168-
169171
screens.value = screen;
170172
});
171173
});

0 commit comments

Comments
 (0)