Skip to content

Commit

Permalink
feat(dropdown-menu): add multiple custom class support (#5099)
Browse files Browse the repository at this point in the history
  • Loading branch information
landluck authored Nov 18, 2022
1 parent f4c71d3 commit 01a389c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/dropdown-item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { VantComponent } from '../common/component';
import { Option } from './shared';

VantComponent({
classes: ['item-title-class'],
field: true,

relation: useParent('dropdown-menu', function () {
Expand Down Expand Up @@ -84,7 +85,7 @@ VantComponent({

onOptionTap(event: WechatMiniprogram.TouchEvent) {
const { option } = event.currentTarget.dataset;
const { value } = (option as unknown) as Option;
const { value } = option as unknown as Option;

const shouldEmitChange = this.data.value !== value;
this.setData({ showPopup: false, value });
Expand Down
4 changes: 2 additions & 2 deletions packages/dropdown-item/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<view
wx:if="{{ showWrapper }}"
class="{{ utils.bem('dropdown-item', direction) }}"
class="{{ utils.bem('dropdown-item', direction) }} custom-class"
style="{{ wrapperStyle }}"
>
<van-popup
Expand Down Expand Up @@ -30,7 +30,7 @@
>
<view
slot="title"
class="van-dropdown-item__title"
class="van-dropdown-item__title item-title-class"
style="{{ item.value === value ? 'color:' + activeColor : '' }}"
>
{{ item.text }}
Expand Down
32 changes: 20 additions & 12 deletions packages/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ Page({

### DropdownItem Props

| 参数 | 说明 | 类型 | 默认值 |
| ----------- | ---------------------- | ------------------ | -------------- |
| value | 当前选中项对应的 value | _number \| string_ | - |
| title | 菜单项标题 | _string_ | 当前选中项文字 |
| options | 选项数组 | _Option[]_ | `[]` |
| disabled | 是否禁用菜单 | _boolean_ | `false` |
| title-class | 标题额外类名 | _string_ | - |
| popup-style | 自定义弹出层样式 | _string_ | - |
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| value | 当前选中项对应的 value | _number \| string_ | - |
| title | 菜单项标题 | _string_ | 当前选中项文字 |
| options | 选项数组 | _Option[]_ | `[]` |
| disabled | 是否禁用菜单 | _boolean_ | `false` |
| title-class | 标题额外类名,建议使用自定义样式 item-title-class 代替 | _string_ | - |
| popup-style | 自定义弹出层样式 | _string_ | - |

### DropdownItem Events

Expand Down Expand Up @@ -186,8 +186,16 @@ Page({
| value | 标识符 | _number \| string_ |
| icon | 左侧[图标名称](#/icon)或图片链接 | _string_ |

### 外部样式类
### DropdownMenu 外部样式类

| 类名 | 说明 |
| --------------------- | ------------ |
| custom-class | 根节点样式类 |
| title-class `v1.10.7` | 选中项样式类 |

### DropdownItem 外部样式类

| 类名 | 说明 |
| ------------ | ------------ |
| custom-class | 根节点样式类 |
| 类名 | 说明 |
| -------------------------- | ------------ |
| custom-class `v1.10.7` | 根节点样式类 |
| item-title-class `v1.10.7` | 选项样式类 |
1 change: 1 addition & 0 deletions packages/dropdown-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let ARRAY: WechatMiniprogram.Component.TrivialInstance[] = [];

VantComponent({
field: true,
classes: ['title-class'],

relation: useChildren('dropdown-item', function () {
this.updateItemListData();
Expand Down
2 changes: 1 addition & 1 deletion packages/dropdown-menu/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
bind:tap="onTitleTap"
>
<view
class="{{ item.titleClass }} {{ utils.bem('dropdown-menu__title', { active: item.showPopup, down: item.showPopup === (direction === 'down') }) }}"
class="{{ item.titleClass }} {{ utils.bem('dropdown-menu__title', { active: item.showPopup, down: item.showPopup === (direction === 'down') }) }} title-class"
style="{{ item.showPopup ? 'color:' + activeColor : '' }}"
>
<view class="van-ellipsis">
Expand Down
20 changes: 10 additions & 10 deletions packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand All @@ -41,7 +41,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand Down Expand Up @@ -80,7 +80,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand All @@ -98,7 +98,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand Down Expand Up @@ -139,7 +139,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand All @@ -157,7 +157,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand Down Expand Up @@ -196,7 +196,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title van-dropdown-menu__title--down"
class=" van-dropdown-menu__title van-dropdown-menu__title--down title-class"
style=""
>
<wx-view
Expand All @@ -214,7 +214,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title van-dropdown-menu__title--down"
class=" van-dropdown-menu__title van-dropdown-menu__title--down title-class"
style=""
>
<wx-view
Expand Down Expand Up @@ -253,7 +253,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand All @@ -271,7 +271,7 @@ exports[`should render demo and match snapshot 1`] = `
bind:tap="onTitleTap"
>
<wx-view
class=" van-dropdown-menu__title"
class=" van-dropdown-menu__title title-class"
style=""
>
<wx-view
Expand Down

0 comments on commit 01a389c

Please sign in to comment.