From 01a389c58b3d5bfe29d9871a6f36dfb85737eb03 Mon Sep 17 00:00:00 2001 From: landluck Date: Fri, 18 Nov 2022 10:52:52 +0800 Subject: [PATCH] feat(dropdown-menu): add multiple custom class support (#5099) --- packages/dropdown-item/index.ts | 3 +- packages/dropdown-item/index.wxml | 4 +-- packages/dropdown-menu/README.md | 32 ++++++++++++------- packages/dropdown-menu/index.ts | 1 + packages/dropdown-menu/index.wxml | 2 +- .../test/__snapshots__/demo.spec.ts.snap | 20 ++++++------ 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/packages/dropdown-item/index.ts b/packages/dropdown-item/index.ts index dea3213d..2137b69c 100644 --- a/packages/dropdown-item/index.ts +++ b/packages/dropdown-item/index.ts @@ -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 () { @@ -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 }); diff --git a/packages/dropdown-item/index.wxml b/packages/dropdown-item/index.wxml index dd75292f..c9d4aa57 100644 --- a/packages/dropdown-item/index.wxml +++ b/packages/dropdown-item/index.wxml @@ -2,7 +2,7 @@ {{ item.text }} diff --git a/packages/dropdown-menu/README.md b/packages/dropdown-menu/README.md index ce975191..5be11065 100644 --- a/packages/dropdown-menu/README.md +++ b/packages/dropdown-menu/README.md @@ -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 @@ -186,8 +186,16 @@ Page({ | value | 标识符 | _number \| string_ | | icon | 左侧[图标名称](#/icon)或图片链接 | _string_ | -### 外部样式类 +### DropdownMenu 外部样式类 -| 类名 | 说明 | -| ------------ | ------------ | -| custom-class | 根节点样式类 | +| 类名 | 说明 | +| --------------------- | ------------ | +| custom-class | 根节点样式类 | +| title-class `v1.10.7` | 选中项样式类 | + +### DropdownItem 外部样式类 + +| 类名 | 说明 | +| -------------------------- | ------------ | +| custom-class `v1.10.7` | 根节点样式类 | +| item-title-class `v1.10.7` | 选项样式类 | diff --git a/packages/dropdown-menu/index.ts b/packages/dropdown-menu/index.ts index 110699ef..5454686f 100644 --- a/packages/dropdown-menu/index.ts +++ b/packages/dropdown-menu/index.ts @@ -6,6 +6,7 @@ let ARRAY: WechatMiniprogram.Component.TrivialInstance[] = []; VantComponent({ field: true, + classes: ['title-class'], relation: useChildren('dropdown-item', function () { this.updateItemListData(); diff --git a/packages/dropdown-menu/index.wxml b/packages/dropdown-menu/index.wxml index cfd661d1..ec165a9d 100644 --- a/packages/dropdown-menu/index.wxml +++ b/packages/dropdown-menu/index.wxml @@ -10,7 +10,7 @@ bind:tap="onTitleTap" > diff --git a/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap b/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap index 3836157f..116138a2 100644 --- a/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap +++ b/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap @@ -23,7 +23,7 @@ exports[`should render demo and match snapshot 1`] = ` bind:tap="onTitleTap" >