Skip to content

Commit

Permalink
fix(descriptions): fixes the issue related to the layout distribution…
Browse files Browse the repository at this point in the history
… of span (#3409)
  • Loading branch information
oljc authored Jan 7, 2025
1 parent 04fd194 commit 39b69d5
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 137 deletions.
4 changes: 3 additions & 1 deletion packages/web-vue/components/descriptions/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ description: Generally used for the information display of the detail page.
@import ./__demo__/layout.md
@import ./__demo__/example.md
## API
Expand Down Expand Up @@ -67,6 +69,6 @@ description: Generally used for the information display of the detail page.
|---|---|---|:---:|
|label|Label|`string \| RenderFunction`|`-`|
|value|Data|`string \| RenderFunction`|`-`|
|span|number of columns|`number`|`-`|
|span|number of columns|`number`|`1`|


4 changes: 3 additions & 1 deletion packages/web-vue/components/descriptions/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: 一般用于详情页的信息展示。
@import ./__demo__/layout.md
@import ./__demo__/example.md
## API
Expand Down Expand Up @@ -65,6 +67,6 @@ description: 一般用于详情页的信息展示。
|---|---|---|:---:|
|label|标签|`string \| RenderFunction`|`-`|
|value|数据|`string \| RenderFunction`|`-`|
|span|所占列数|`number`|`-`|
|span|所占列数|`number`|`1`|


2 changes: 2 additions & 0 deletions packages/web-vue/components/descriptions/TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ description: Generally used for the information display of the detail page.
@import ./__demo__/layout.md
@import ./__demo__/example.md
## API
%%API(descriptions.tsx)%%
Expand Down
102 changes: 102 additions & 0 deletions packages/web-vue/components/descriptions/__demo__/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
```yaml
title:
zh-CN: 布局示例
en-US: Layout Example
```
## zh-CN
`span` 所占列数大于 `column` 可放置的数据个数时,`span` 会被设置为 `column` 的值,当行剩余列数不够放置下一列时将自动换行,每行末尾列会自动填充剩余量。

---

## en-US
When the number of columns occupied by `span` is greater than the number of data that can be placed in `column`, `span` will be set to the value of `column`. When the remaining columns in the row are not enough to place the next column, it will automatically wrap, and the last column of each row will automatically fill the remaining amount.

---

```vue
<template>
<a-form :model="form" auto-label-width>
<a-form-item label="size">
<a-radio-group v-model="form.size" type="button" :options="sizeOptions" />
</a-form-item>
<a-form-item label="layout">
<a-radio-group
v-model="form.layout"
type="button"
:options="layoutOptions"
/>
</a-form-item>
<a-form-item label="table-layout">
<a-radio-group
v-model="form.tableLayout"
type="button"
:options="['auto', 'fixed']"
/>
</a-form-item>
<a-form-item label="column">
<a-radio-group
v-model="form.column"
type="button"
:options="columnOptions"
/>
</a-form-item>
<a-form-item label="firstSpan">
<a-radio-group
v-model="form.firstSpan"
type="button"
:options="firstSpanOptions"
/>
</a-form-item>
</a-form>
<div style="margin-top: 20px">
<a-descriptions
title="Layout Example"
:size="form.size"
:column="form.column"
:layout="form.layout"
:table-layout="form.tableLayout"
bordered
>
<a-descriptions-item label="Item1" :span="form.firstSpan">
<div>Span:{{form.firstSpan}}
<span v-if="form.firstSpan > form.column" style="color: red;">
Exceeds Column, set to Column size
</span>
</div>
</a-descriptions-item>
<a-descriptions-item label="Item2" :span="2">Span:2</a-descriptions-item>
<a-descriptions-item label="Item3" :span="3">Span:3</a-descriptions-item>
<a-descriptions-item label="Item4" :span="2">Span:2</a-descriptions-item>
<a-descriptions-item label="Item5" :span="1">Span:1</a-descriptions-item>
<a-descriptions-item label="Item6" :span="1">Span:1</a-descriptions-item>
</a-descriptions>
</div>
</template>
<script setup>
import { reactive } from 'vue';
const form = reactive({
size: 'medium',
layout: 'horizontal',
column: 4,
tableLayout: 'auto',
firstSpan: 2
});
const layoutOptions = [
'horizontal',
'inline-horizontal',
'vertical',
'inline-vertical',
];
const columnOptions = [1, 2, 3, 4, 5];
const firstSpanOptions = [1, 2, 3, 4, 5];
const sizeOptions = ['mini', 'small', 'medium', 'large'];
</script>
```
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ exports[`<descriptions> demo: render [basic] correctly 1`] = `
<tbody>
<tr class=\\"arco-descriptions-row\\">
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Name</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"1\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->Socrates<!--v-if--><!--v-if--></span></td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"5\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->Socrates<!--v-if--><!--v-if--></span></td>
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Mobile</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"1\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->123-1234-1234<!--v-if--><!--v-if--></span></td>
</tr>
<tr class=\\"arco-descriptions-row\\">
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Residence</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"1\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->Beijing<!--v-if--><!--v-if--></span></td>
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Hometown</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"1\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->Beijing<!--v-if--><!--v-if--></span></td>
</tr>
<tr class=\\"arco-descriptions-row\\">
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Address</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"7\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->Yingdu Building, Zhichun Road, Beijing<!--v-if--><!--v-if--></span></td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"3\\"><span class=\\"arco-tag arco-tag-size-medium arco-tag-checked\\"><!--v-if-->Yingdu Building, Zhichun Road, Beijing<!--v-if--><!--v-if--></span></td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -188,6 +188,114 @@ exports[`<descriptions> demo: render [bordered] correctly 1`] = `
</div>"
`;
exports[`<descriptions> demo: render [example] correctly 1`] = `
"<form class=\\"arco-form arco-form-layout-horizontal arco-form-size-medium arco-form-auto-label-width\\">
<div class=\\"arco-row arco-row-nowrap arco-row-align-start arco-row-justify-start arco-form-item arco-form-item-layout-horizontal\\">
<div class=\\"arco-col arco-col-5 arco-form-item-label-col arco-form-item-label-col-flex\\"><label class=\\"arco-form-item-label\\">
<!--v-if-->size
<!--v-if-->
<!--v-if-->
</label></div>
<div class=\\"arco-col arco-form-item-wrapper-col\\" style=\\"flex-basis: auto;\\">
<div class=\\"arco-form-item-content-wrapper\\">
<div class=\\"arco-form-item-content arco-form-item-content-flex\\"><span class=\\"arco-radio-group-button arco-radio-group-size-medium arco-radio-group-direction-horizontal\\"><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"mini\\"><span class=\\"arco-radio-button-content\\">mini</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"small\\"><span class=\\"arco-radio-button-content\\">small</span></label><label class=\\"arco-radio-button arco-radio-checked\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"medium\\"><span class=\\"arco-radio-button-content\\">medium</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"large\\"><span class=\\"arco-radio-button-content\\">large</span></label></span></div>
</div>
<!--v-if-->
<!--v-if-->
</div>
</div>
<div class=\\"arco-row arco-row-nowrap arco-row-align-start arco-row-justify-start arco-form-item arco-form-item-layout-horizontal\\">
<div class=\\"arco-col arco-col-5 arco-form-item-label-col arco-form-item-label-col-flex\\"><label class=\\"arco-form-item-label\\">
<!--v-if-->layout
<!--v-if-->
<!--v-if-->
</label></div>
<div class=\\"arco-col arco-form-item-wrapper-col\\" style=\\"flex-basis: auto;\\">
<div class=\\"arco-form-item-content-wrapper\\">
<div class=\\"arco-form-item-content arco-form-item-content-flex\\"><span class=\\"arco-radio-group-button arco-radio-group-size-medium arco-radio-group-direction-horizontal\\"><label class=\\"arco-radio-button arco-radio-checked\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"horizontal\\"><span class=\\"arco-radio-button-content\\">horizontal</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"inline-horizontal\\"><span class=\\"arco-radio-button-content\\">inline-horizontal</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"vertical\\"><span class=\\"arco-radio-button-content\\">vertical</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"inline-vertical\\"><span class=\\"arco-radio-button-content\\">inline-vertical</span></label></span></div>
</div>
<!--v-if-->
<!--v-if-->
</div>
</div>
<div class=\\"arco-row arco-row-nowrap arco-row-align-start arco-row-justify-start arco-form-item arco-form-item-layout-horizontal\\">
<div class=\\"arco-col arco-col-5 arco-form-item-label-col arco-form-item-label-col-flex\\"><label class=\\"arco-form-item-label\\">
<!--v-if-->table-layout
<!--v-if-->
<!--v-if-->
</label></div>
<div class=\\"arco-col arco-form-item-wrapper-col\\" style=\\"flex-basis: auto;\\">
<div class=\\"arco-form-item-content-wrapper\\">
<div class=\\"arco-form-item-content arco-form-item-content-flex\\"><span class=\\"arco-radio-group-button arco-radio-group-size-medium arco-radio-group-direction-horizontal\\"><label class=\\"arco-radio-button arco-radio-checked\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"auto\\"><span class=\\"arco-radio-button-content\\">auto</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"fixed\\"><span class=\\"arco-radio-button-content\\">fixed</span></label></span></div>
</div>
<!--v-if-->
<!--v-if-->
</div>
</div>
<div class=\\"arco-row arco-row-nowrap arco-row-align-start arco-row-justify-start arco-form-item arco-form-item-layout-horizontal\\">
<div class=\\"arco-col arco-col-5 arco-form-item-label-col arco-form-item-label-col-flex\\"><label class=\\"arco-form-item-label\\">
<!--v-if-->column
<!--v-if-->
<!--v-if-->
</label></div>
<div class=\\"arco-col arco-form-item-wrapper-col\\" style=\\"flex-basis: auto;\\">
<div class=\\"arco-form-item-content-wrapper\\">
<div class=\\"arco-form-item-content arco-form-item-content-flex\\"><span class=\\"arco-radio-group-button arco-radio-group-size-medium arco-radio-group-direction-horizontal\\"><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"1\\"><span class=\\"arco-radio-button-content\\">1</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"2\\"><span class=\\"arco-radio-button-content\\">2</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"3\\"><span class=\\"arco-radio-button-content\\">3</span></label><label class=\\"arco-radio-button arco-radio-checked\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"4\\"><span class=\\"arco-radio-button-content\\">4</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"5\\"><span class=\\"arco-radio-button-content\\">5</span></label></span></div>
</div>
<!--v-if-->
<!--v-if-->
</div>
</div>
<div class=\\"arco-row arco-row-nowrap arco-row-align-start arco-row-justify-start arco-form-item arco-form-item-layout-horizontal\\">
<div class=\\"arco-col arco-col-5 arco-form-item-label-col arco-form-item-label-col-flex\\"><label class=\\"arco-form-item-label\\">
<!--v-if-->firstSpan
<!--v-if-->
<!--v-if-->
</label></div>
<div class=\\"arco-col arco-form-item-wrapper-col\\" style=\\"flex-basis: auto;\\">
<div class=\\"arco-form-item-content-wrapper\\">
<div class=\\"arco-form-item-content arco-form-item-content-flex\\"><span class=\\"arco-radio-group-button arco-radio-group-size-medium arco-radio-group-direction-horizontal\\"><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"1\\"><span class=\\"arco-radio-button-content\\">1</span></label><label class=\\"arco-radio-button arco-radio-checked\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"2\\"><span class=\\"arco-radio-button-content\\">2</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"3\\"><span class=\\"arco-radio-button-content\\">3</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"4\\"><span class=\\"arco-radio-button-content\\">4</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"5\\"><span class=\\"arco-radio-button-content\\">5</span></label></span></div>
</div>
<!--v-if-->
<!--v-if-->
</div>
</div>
</form>
<div style=\\"margin-top: 20px;\\">
<div class=\\"arco-descriptions arco-descriptions-layout-horizontal arco-descriptions-size-medium arco-descriptions-border\\">
<div class=\\"arco-descriptions-title\\">Layout Example</div>
<div class=\\"arco-descriptions-body\\">
<table class=\\"arco-descriptions-table\\">
<tbody>
<tr class=\\"arco-descriptions-row\\">
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Item1</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"3\\">
<div>Span:2
<!--v-if-->
</div>
</td>
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Item2</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"3\\">Span:2</td>
</tr>
<tr class=\\"arco-descriptions-row\\">
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Item3</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"7\\">Span:3</td>
</tr>
<tr class=\\"arco-descriptions-row\\">
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Item4</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"3\\">Span:2</td>
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Item5</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"1\\">Span:1</td>
<td class=\\"arco-descriptions-item-label arco-descriptions-item-label-block\\" style=\\"text-align: left;\\">Item6</td>
<td class=\\"arco-descriptions-item-value arco-descriptions-item-value-block\\" style=\\"text-align: left;\\" colspan=\\"1\\">Span:1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>"
`;
exports[`<descriptions> demo: render [layout] correctly 1`] = `
"<span class=\\"arco-radio-group-button arco-radio-group-size-medium arco-radio-group-direction-horizontal\\"><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"mini\\"><span class=\\"arco-radio-button-content\\">mini</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"small\\"><span class=\\"arco-radio-button-content\\">small</span></label><label class=\\"arco-radio-button arco-radio-checked\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"medium\\"><span class=\\"arco-radio-button-content\\">medium</span></label><label class=\\"arco-radio-button\\"><input type=\\"radio\\" class=\\"arco-radio-target\\" value=\\"large\\"><span class=\\"arco-radio-button-content\\">large</span></label></span>
<div style=\\"margin-top: 20px;\\">
Expand Down
10 changes: 0 additions & 10 deletions packages/web-vue/components/descriptions/context.ts

This file was deleted.

52 changes: 2 additions & 50 deletions packages/web-vue/components/descriptions/descriptions-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@
</template>

<script lang="ts">
import {
defineComponent,
getCurrentInstance,
inject,
onBeforeUnmount,
onMounted,
onUpdated,
reactive,
ref,
toRefs,
} from 'vue';
import { defineComponent } from 'vue';
import { getPrefixCls } from '../_utils/global-config';
import { DescriptionsContext, descriptionsInjectionKey } from './context';
import { useIndex } from '../_hooks/use-index';
export default defineComponent({
name: 'DescriptionsItem',
Expand All @@ -43,44 +31,8 @@ export default defineComponent({
* @slot label
* @version 2.18.0
*/
setup(props) {
const { span } = toRefs(props);
setup() {
const prefixCls = getPrefixCls('descriptions');
const descCtx = inject(descriptionsInjectionKey, {} as DescriptionsContext);
const instance = getCurrentInstance();
const itemRef = ref<HTMLElement>();
const { computedIndex } = useIndex({
itemRef,
selector: `.${prefixCls}-item-value`,
parentClassName: `${prefixCls}-table`,
});
const itemData = reactive({
index: computedIndex.value,
span: span.value,
});
if (instance?.uid) {
descCtx.addItem?.(instance.uid, itemData);
}
const getItemRef = () => {
const itemEle = (instance?.proxy?.$el as Node).parentElement;
if (itemEle && itemEle !== itemRef.value) {
itemRef.value = itemEle;
}
};
onMounted(() => getItemRef());
onUpdated(() => getItemRef());
onBeforeUnmount(() => {
if (instance?.uid) {
descCtx.removeItem?.(instance.uid);
}
});
return {
prefixCls,
Expand Down
Loading

0 comments on commit 39b69d5

Please sign in to comment.