Skip to content

Commit e7d0def

Browse files
authored
feat(dropdown-menu): support custom icon for arrow (#2240)
1 parent 4be1e88 commit e7d0def

File tree

7 files changed

+33
-12
lines changed

7 files changed

+33
-12
lines changed

src/dropdown-menu/README.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
name | type | default | description | required
77
-- | -- | -- | -- | --
8+
arrow-icon | String / Object | 'caret-down-small' | \- | N
89
close-on-click-overlay | Boolean | true | \- | N
910
duration | String / Number | 200 | \- | N
1011
external-classes | Array | - | `['t-class', 't-class-item', 't-class-label', 't-class-icon']` | N

src/dropdown-menu/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ isComponent: true
4646

4747
名称 | 类型 | 默认值 | 说明 | 必传
4848
-- | -- | -- | -- | --
49+
arrow-icon | String / Object | 'caret-down-small' | 自定义箭头图标 | N
4950
close-on-click-overlay | Boolean | true | 是否在点击遮罩层后关闭菜单 | N
5051
duration | String / Number | 200 | 动画时长 | N
5152
show-overlay | Boolean | true | 是否显示遮罩层 | N

src/dropdown-menu/__test__/__snapshots__/index.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ exports[`dropdown-menu :base 1`] = `
2525
菜单
2626
</wx-view>
2727
<t-icon
28+
class=""
2829
tClass="t-dropdown-menu__icon t-dropdown-menu__icon--active t-class-icon"
30+
bind:click=""
2931
>
3032
<wx-view
3133
ariaHidden="{{true}}"
@@ -56,7 +58,9 @@ exports[`dropdown-menu :base 1`] = `
5658
单列多选
5759
</wx-view>
5860
<t-icon
61+
class=""
5962
tClass="t-dropdown-menu__icon t-dropdown-menu__icon-- t-class-icon"
63+
bind:click=""
6064
>
6165
<wx-view
6266
ariaHidden="{{true}}"

src/dropdown-menu/dropdown-menu.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RelationsOptions, SuperComponent, wxComponent } from '../common/src/ind
22
import config from '../common/config';
33
import props from './props';
44
import type { TdDropdownMenuProps } from './type';
5+
import { calcIcon } from '../common/utils';
56

67
const { prefix } = config;
78
const name = `${prefix}-dropdown-menu`;
@@ -22,6 +23,7 @@ export default class DropdownMenu extends SuperComponent {
2223
menus: null,
2324
activeIdx: -1,
2425
bottom: 0,
26+
_arrowIcon: { name: props.arrowIcon.value },
2527
};
2628

2729
relations: RelationsOptions = {
@@ -36,6 +38,14 @@ export default class DropdownMenu extends SuperComponent {
3638
},
3739
};
3840

41+
observers = {
42+
arrowIcon(v) {
43+
this.setData({
44+
_arrowIcon: calcIcon(v),
45+
});
46+
},
47+
};
48+
3949
methods = {
4050
toggle(index: number) {
4151
const { activeIdx, duration } = this.data;

src/dropdown-menu/dropdown-menu.wxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<import src="../common/template/icon.wxml" />
12
<wxs src="../common/utils.wxs" module="_" />
23

34
<view style="{{_._style([style, customStyle])}}" class="{{ classPrefix }} class {{prefix}}-class" id="t-bar">
@@ -13,10 +14,9 @@
1314
aria-haspopup="menu"
1415
>
1516
<view class="{{classPrefix}}__title {{prefix}}-class-label">{{item.label}}</view>
16-
<t-icon
17-
name="caret-down-small"
18-
t-class="{{classPrefix}}__icon {{classPrefix}}__icon--{{activeIdx == index ? 'active' : ''}} {{prefix}}-class-icon"
19-
aria-hidden="{{true}}"
17+
<template
18+
is="icon"
19+
data="{{..._arrowIcon, ariaHidden: true, tClass: classPrefix + '__icon ' + classPrefix + '__icon--' + (activeIdx == index ? 'active ' : ' ') + prefix + '-class-icon'}}"
2020
/>
2121
</view>
2222
<slot />

src/dropdown-menu/props.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
import { TdDropdownMenuProps } from './type';
88
const props: TdDropdownMenuProps = {
9+
/** 自定义箭头图标 */
10+
arrowIcon: {
11+
type: null,
12+
value: 'caret-down-small',
13+
},
914
/** 是否在点击遮罩层后关闭菜单 */
1015
closeOnClickOverlay: {
1116
type: Boolean,

src/dropdown-menu/type.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
* */
66

77
export interface TdDropdownMenuProps {
8+
/**
9+
* 自定义箭头图标
10+
* @default 'caret-down-small'
11+
*/
12+
arrowIcon?: {
13+
type: null;
14+
value?: string | object;
15+
};
816
/**
917
* 是否在点击遮罩层后关闭菜单
1018
* @default true
@@ -13,14 +21,6 @@ export interface TdDropdownMenuProps {
1321
type: BooleanConstructor;
1422
value?: boolean;
1523
};
16-
/**
17-
* 自定义组件样式
18-
* @default ''
19-
*/
20-
style?: {
21-
type: StringConstructor;
22-
value?: string;
23-
};
2424
/**
2525
* 动画时长
2626
* @default 200

0 commit comments

Comments
 (0)