Skip to content

Commit 2843352

Browse files
authored
[new feature] TreeSelect: support string type of height prop (youzan#4107)
1 parent 7ad5323 commit 2843352

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

src/tree-select/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252
| Attribute | Description | Type | Default |
5353
|------|------|------|------|
5454
| items | Required datasets for the component | `Item[]` | `[]` |
55-
| height | Height (px) | `number` | `300` |
55+
| height | Height | `string | number` | `300` |
5656
| main-Active-index | The index of selected parent node | `number` | `0` |
5757
| active-id | Id of selected item | `string | number` | `0` |
5858

src/tree-select/README.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252
| 参数 | 说明 | 类型 | 默认值 | 版本 |
5353
|------|------|------|------|------|
5454
| items | 分类显示所需的数据 | `Item[]` | `[]` | - |
55-
| height | 高度,单位为 px | `number` | `300` | - |
55+
| height | 高度,默认单位为 px | `string | number` | `300` | - |
5656
| main-active-index | 左侧导航高亮的索引 | `number` | `0` | - |
5757
| active-id | 右侧选择项,高亮的数据id | `string | number` | `0` | - |
5858

src/tree-select/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createNamespace } from '../utils';
1+
import { createNamespace, addUnit } from '../utils';
22
import { emit, inherit } from '../utils/functional';
33
import Icon from '../icon';
44

@@ -19,7 +19,7 @@ export type TreeSelectChildren = {
1919
};
2020

2121
export type TreeSelectProps = {
22-
height: number;
22+
height: number | string;
2323
items: TreeSelectItem[];
2424
activeId: number | string;
2525
mainActiveIndex: number;
@@ -98,7 +98,7 @@ function TreeSelect(
9898
}
9999

100100
return (
101-
<div class={bem()} style={{ height: `${height}px` }} {...inherit(ctx)}>
101+
<div class={bem()} style={{ height: addUnit(height) }} {...inherit(ctx)}>
102102
<div class={bem('nav')}>{Nav}</div>
103103
<div class={bem('content')}>{Content()}</div>
104104
</div>
@@ -111,7 +111,7 @@ TreeSelect.props = {
111111
default: () => []
112112
},
113113
height: {
114-
type: Number,
114+
type: [Number, String],
115115
default: 300
116116
},
117117
activeId: {

src/tree-select/test/__snapshots__/index.spec.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ exports[`empty list 1`] = `
1515
<div class="van-tree-select__content"></div>
1616
</div>
1717
`;
18+
19+
exports[`height prop 1`] = `
20+
<div class="van-tree-select" style="height: 100vh;">
21+
<div class="van-tree-select__nav"></div>
22+
<div class="van-tree-select__content"></div>
23+
</div>
24+
`;

src/tree-select/test/index.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,13 @@ test('content slot', () => {
141141

142142
expect(wrapper).toMatchSnapshot();
143143
});
144+
145+
test('height prop', () => {
146+
const wrapper = mount(TreeSelect, {
147+
propsData: {
148+
height: '100vh'
149+
}
150+
});
151+
152+
expect(wrapper).toMatchSnapshot();
153+
});

0 commit comments

Comments
 (0)