mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 22:49:15 +08:00
[improvement] TreeSelect: add height prop (#1905)
This commit is contained in:
parent
ae15bbd141
commit
396819c355
@ -106,7 +106,6 @@ export default {
|
|||||||
this.mainActiveIndex = index;
|
this.mainActiveIndex = index;
|
||||||
},
|
},
|
||||||
onItemClick(data) {
|
onItemClick(data) {
|
||||||
console.log(data);
|
|
||||||
this.activeId = data.id;
|
this.activeId = data.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,12 @@ export default {
|
|||||||
| Attribute | Description | Type | Default |
|
| Attribute | Description | Type | Default |
|
||||||
|-----------|-----------|-----------|-------------|
|
|-----------|-----------|-----------|-------------|
|
||||||
| items | Required datasets for the component, see Data Structure for detail. | `Array` | `[]` |
|
| items | Required datasets for the component, see Data Structure for detail. | `Array` | `[]` |
|
||||||
|
| height | Height (px) | `Number` | `300` |
|
||||||
| main-Active-index | The index of selected parent node | `Number` | `0` |
|
| main-Active-index | The index of selected parent node | `Number` | `0` |
|
||||||
| active-id | Id of selected item | `String | Number` | `0` |
|
| active-id | Id of selected item | `String | Number` | `0` |
|
||||||
|
|
||||||
#### Event
|
#### Event
|
||||||
|
|
||||||
| Event | Description | Arguments |
|
| Event | Description | Arguments |
|
||||||
|-----------|-----------|-----------|
|
|-----------|-----------|-----------|
|
||||||
| navclick | triggered when parent node is selected | index: index of selected parent |
|
| navclick | triggered when parent node is selected | index: index of selected parent |
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="b()" :style="{ height: mainHeight + 'px' }">
|
<div :class="b()" :style="{ height: height + 'px' }">
|
||||||
<div :class="b('nav')">
|
<div :class="b('nav')">
|
||||||
<div
|
<div
|
||||||
v-for="(item, index) in items"
|
v-for="(item, index) in items"
|
||||||
@ -9,13 +9,14 @@
|
|||||||
{{ item.text }}
|
{{ item.text }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div :class="b('content')" :style="{ height: itemHeight + 'px' }">
|
<div :class="b('content')">
|
||||||
<div
|
<div
|
||||||
v-for="item in subItems"
|
v-for="item in subItems"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
class="van-ellipsis"
|
class="van-ellipsis"
|
||||||
:class="b('item', { active: activeId === item.id })"
|
:class="b('item', { active: activeId === item.id })"
|
||||||
@click="onItemSelect(item)">
|
@click="onItemSelect(item)"
|
||||||
|
>
|
||||||
{{ item.text }}
|
{{ item.text }}
|
||||||
<icon
|
<icon
|
||||||
v-if="activeId === item.id"
|
v-if="activeId === item.id"
|
||||||
@ -46,7 +47,7 @@ export default create({
|
|||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 0
|
default: 0
|
||||||
},
|
},
|
||||||
maxHeight: {
|
height: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 300
|
default: 300
|
||||||
}
|
}
|
||||||
@ -56,19 +57,12 @@ export default create({
|
|||||||
subItems() {
|
subItems() {
|
||||||
const selectedItem = this.items[this.mainActiveIndex] || {};
|
const selectedItem = this.items[this.mainActiveIndex] || {};
|
||||||
return selectedItem.children || [];
|
return selectedItem.children || [];
|
||||||
},
|
|
||||||
mainHeight() {
|
|
||||||
const maxHeight = Math.max(this.items.length * 44, this.subItems.length * 44);
|
|
||||||
return Math.min(maxHeight, this.maxHeight);
|
|
||||||
},
|
|
||||||
itemHeight() {
|
|
||||||
return Math.min(this.subItems.length * 44, this.maxHeight);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onItemSelect(data) {
|
onItemSelect(data) {
|
||||||
this.$emit('itemclick', { ...data });
|
this.$emit('itemclick', data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@ exports[`renders demo correctly 1`] = `
|
|||||||
江苏
|
江苏
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-tree-select__content" style="height:300px;">
|
<div class="van-tree-select__content">
|
||||||
<div class="van-ellipsis van-tree-select__item van-tree-select__item--active">
|
<div class="van-ellipsis van-tree-select__item van-tree-select__item--active">
|
||||||
杭州
|
杭州
|
||||||
<i class="van-icon van-icon-success van-tree-select__selected" style="color:undefined;font-size:undefined;">
|
<i class="van-icon van-icon-success van-tree-select__selected" style="color:undefined;font-size:undefined;">
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`empty list 1`] = `
|
exports[`empty list 1`] = `
|
||||||
<div class="van-tree-select" style="height: 0px;">
|
<div class="van-tree-select" style="height: 300px;">
|
||||||
<div class="van-tree-select__nav"></div>
|
<div class="van-tree-select__nav"></div>
|
||||||
<div class="van-tree-select__content" style="height: 0px;"></div>
|
<div class="van-tree-select__content"></div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -50,7 +50,8 @@ export default {
|
|||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
|-----------|-----------|-----------|-------------|
|
|-----------|-----------|-----------|-------------|
|
||||||
| items | 分类显示所需的数据,具体数据结构可看 数据结构 | `Array` | `[]` |
|
| items | 分类显示所需的数据,结构参见下方 | `Array` | `[]` |
|
||||||
|
| height | 高度,单位为 px | `Number` | `300` |
|
||||||
| main-active-index | 左侧导航高亮的索引 | `Number` | `0` |
|
| main-active-index | 左侧导航高亮的索引 | `Number` | `0` |
|
||||||
| active-id | 右侧选择项,高亮的数据id | `String | Number` | `0` |
|
| active-id | 右侧选择项,高亮的数据id | `String | Number` | `0` |
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
&__nav {
|
&__nav {
|
||||||
width: 143px;
|
width: 35%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -20,14 +20,20 @@
|
|||||||
padding: 0 15px;
|
padding: 0 15px;
|
||||||
background-color: $white;
|
background-color: $white;
|
||||||
|
|
||||||
|
&:active,
|
||||||
&--active {
|
&--active {
|
||||||
background-color: $background-color;
|
background-color: $background-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--active {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__content {
|
&__content {
|
||||||
|
height: 100%;
|
||||||
padding: 0 15px;
|
padding: 0 15px;
|
||||||
margin-left: 143px;
|
margin-left: 35%;
|
||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
}
|
}
|
||||||
@ -38,8 +44,9 @@
|
|||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
padding-right: 18px;
|
padding-right: 18px;
|
||||||
|
|
||||||
|
&:active,
|
||||||
&--active {
|
&--active {
|
||||||
color: $button-danger-background-color;
|
color: $red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user