mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: migrate DropdownMenu
This commit is contained in:
parent
0a570b2382
commit
998c7d8da6
@ -57,4 +57,6 @@ module.exports = [
|
|||||||
'search',
|
'search',
|
||||||
'stepper',
|
'stepper',
|
||||||
'uploader',
|
'uploader',
|
||||||
|
'dropdown-menu',
|
||||||
|
'dropdown-item',
|
||||||
];
|
];
|
||||||
|
@ -44,6 +44,7 @@ Vant 遵循 [Semver](https://semver.org/lang/zh-CN/) 语义化版本规范。
|
|||||||
- Checkbox
|
- Checkbox
|
||||||
- CheckboxGroup
|
- CheckboxGroup
|
||||||
- DatetimePicker
|
- DatetimePicker
|
||||||
|
- DropdownItem
|
||||||
- Field
|
- Field
|
||||||
- Radio
|
- Radio
|
||||||
- RadioGroup
|
- RadioGroup
|
||||||
|
@ -17,9 +17,9 @@ export default createComponent({
|
|||||||
mixins: [PortalMixin({ ref: 'wrapper' }), ChildrenMixin('vanDropdownMenu')],
|
mixins: [PortalMixin({ ref: 'wrapper' }), ChildrenMixin('vanDropdownMenu')],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: null,
|
|
||||||
title: String,
|
title: String,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
|
modelValue: null,
|
||||||
titleClass: String,
|
titleClass: String,
|
||||||
options: {
|
options: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@ -31,6 +31,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['open', 'opened', 'close', 'closed', 'change', 'update:modelValue'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
transition: true,
|
transition: true,
|
||||||
@ -46,7 +48,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const match = this.options.filter(
|
const match = this.options.filter(
|
||||||
(option) => option.value === this.value
|
(option) => option.value === this.modelValue
|
||||||
);
|
);
|
||||||
return match.length ? match[0].text : '';
|
return match.length ? match[0].text : '';
|
||||||
},
|
},
|
||||||
@ -98,6 +100,10 @@ export default createComponent({
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onTogglePopup(show) {
|
||||||
|
this.showPopup = show;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -112,7 +118,7 @@ export default createComponent({
|
|||||||
} = this.parent;
|
} = this.parent;
|
||||||
|
|
||||||
const Options = this.options.map((option) => {
|
const Options = this.options.map((option) => {
|
||||||
const active = option.value === this.value;
|
const active = option.value === this.modelValue;
|
||||||
return (
|
return (
|
||||||
<Cell
|
<Cell
|
||||||
clickable
|
clickable
|
||||||
@ -124,8 +130,8 @@ export default createComponent({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.showPopup = false;
|
this.showPopup = false;
|
||||||
|
|
||||||
if (option.value !== this.value) {
|
if (option.value !== this.modelValue) {
|
||||||
this.$emit('input', option.value);
|
this.$emit('update:modelValue', option.value);
|
||||||
this.$emit('change', option.value);
|
this.$emit('change', option.value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -154,7 +160,7 @@ export default createComponent({
|
|||||||
onClick={this.onClickWrapper}
|
onClick={this.onClickWrapper}
|
||||||
>
|
>
|
||||||
<Popup
|
<Popup
|
||||||
vModel={this.showPopup}
|
show={this.showPopup}
|
||||||
overlay={overlay}
|
overlay={overlay}
|
||||||
class={bem('content')}
|
class={bem('content')}
|
||||||
position={direction === 'down' ? 'top' : 'bottom'}
|
position={direction === 'down' ? 'top' : 'bottom'}
|
||||||
@ -169,9 +175,10 @@ export default createComponent({
|
|||||||
this.showWrapper = false;
|
this.showWrapper = false;
|
||||||
this.$emit('closed');
|
this.$emit('closed');
|
||||||
}}
|
}}
|
||||||
|
{...{ 'onUpdate:modelValue': this.onTogglePopup }}
|
||||||
>
|
>
|
||||||
{Options}
|
{Options}
|
||||||
{this.slots('default')}
|
{this.$slots.default?.()}
|
||||||
</Popup>
|
</Popup>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -117,7 +117,7 @@ export default createComponent({
|
|||||||
style={{ color: item.showPopup ? this.activeColor : '' }}
|
style={{ color: item.showPopup ? this.activeColor : '' }}
|
||||||
>
|
>
|
||||||
<div class="van-ellipsis">
|
<div class="van-ellipsis">
|
||||||
{item.slots('title') || item.displayTitle}
|
{item.$slots.title ? item.$slots.title() : item.displayTitle}
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -132,7 +132,7 @@ export default createComponent({
|
|||||||
>
|
>
|
||||||
{Titles}
|
{Titles}
|
||||||
</div>
|
</div>
|
||||||
{this.slots('default')}
|
{this.$slots.default?.()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -188,10 +188,10 @@ module.exports = {
|
|||||||
path: 'dialog',
|
path: 'dialog',
|
||||||
title: 'Dialog 弹出框',
|
title: 'Dialog 弹出框',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: 'dropdown-menu',
|
path: 'dropdown-menu',
|
||||||
// title: 'DropdownMenu 下拉菜单',
|
title: 'DropdownMenu 下拉菜单',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
path: 'loading',
|
path: 'loading',
|
||||||
title: 'Loading 加载',
|
title: 'Loading 加载',
|
||||||
@ -522,10 +522,10 @@ module.exports = {
|
|||||||
path: 'dialog',
|
path: 'dialog',
|
||||||
title: 'Dialog',
|
title: 'Dialog',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: 'dropdown-menu',
|
path: 'dropdown-menu',
|
||||||
// title: 'DropdownMenu',
|
title: 'DropdownMenu',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
path: 'loading',
|
path: 'loading',
|
||||||
title: 'Loading',
|
title: 'Loading',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user