Skip to content

Commit bbad157

Browse files
fix(picker): fix button custom text invalid (#4480)
* fix(picker): fix button custom text invalid * chore: code style * fix(picker): fix button custom text invalid * chore: update example * fix: fix test unit * docs: add pr changelog --------- Co-authored-by: anlyyao <anly_yaw@163.com>
1 parent 3eacad2 commit bbad157

16 files changed

Lines changed: 116 additions & 48 deletions

File tree

packages/components/date-time-picker/__test__/__snapshots__/index.test.js.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ exports[`date-time-picker :base 1`] = `
3838
class="t-picker__cancel t-class-cancel"
3939
bind:tap="onCancel"
4040
>
41-
取消
41+
42+
取消
43+
4244
</wx-view>
4345
<wx-view
4446
class="t-picker__title t-class-title"
@@ -49,7 +51,9 @@ exports[`date-time-picker :base 1`] = `
4951
class="t-picker__confirm t-class-confirm"
5052
bind:tap="onConfirm"
5153
>
52-
确认
54+
55+
确定
56+
5357
</wx-view>
5458
</wx-view>
5559
<wx-view

packages/components/picker/__test__/__snapshots__/demo.test.js.snap

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ exports[`Picker Picker area demo works fine 1`] = `
1010
bind:click="onAreaPicker"
1111
/>
1212
<t-picker
13-
cancelBtn="取消"
14-
confirmBtn="确认"
1513
title="选择地区"
1614
usingCustomNavbar="{{true}}"
1715
value="{{Array []}}"
@@ -137,8 +135,6 @@ exports[`Picker Picker base demo works fine 1`] = `
137135
bind:click="onSeasonPicker"
138136
/>
139137
<t-picker
140-
cancelBtn="取消"
141-
confirmBtn="确认"
142138
data-key="city"
143139
title="选择城市"
144140
usingCustomNavbar="{{true}}"
@@ -203,8 +199,6 @@ exports[`Picker Picker base demo works fine 1`] = `
203199
</t-picker-item>
204200
</t-picker>
205201
<t-picker
206-
cancelBtn="取消"
207-
confirmBtn="确认"
208202
data-key="date"
209203
title="选择时间"
210204
usingCustomNavbar="{{true}}"
@@ -276,8 +270,6 @@ exports[`Picker Picker with-title demo works fine 1`] = `
276270
bind:click="onWithoutTitlePicker"
277271
/>
278272
<t-picker
279-
cancelBtn="取消"
280-
confirmBtn="确认"
281273
data-key="city"
282274
title=""
283275
usingCustomNavbar="{{true}}"
@@ -315,8 +307,6 @@ exports[`Picker Picker with-title demo works fine 1`] = `
315307
/>
316308
</t-picker>
317309
<t-picker
318-
cancelBtn="取消"
319-
confirmBtn="确认"
320310
data-key="city2"
321311
title=""
322312
usingCustomNavbar="{{true}}"
@@ -359,8 +349,6 @@ exports[`Picker Picker with-title demo works fine 1`] = `
359349
exports[`Picker Picker without-popup demo works fine 1`] = `
360350
<without-popup>
361351
<t-picker
362-
cancelBtn="取消"
363-
confirmBtn="确认"
364352
data-key="city"
365353
title=""
366354
usePopup="{{false}}"

packages/components/picker/__test__/__snapshots__/index.test.js.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ exports[`picker :base 1`] = `
3535
class="t-picker__cancel t-class-cancel"
3636
bind:tap="onCancel"
3737
>
38-
取消
38+
39+
取消
40+
3941
</wx-view>
4042
<wx-view
4143
class="t-picker__title t-class-title"
@@ -46,7 +48,9 @@ exports[`picker :base 1`] = `
4648
class="t-picker__confirm t-class-confirm"
4749
bind:tap="onConfirm"
4850
>
49-
确认
51+
52+
确认
53+
5054
</wx-view>
5155
</wx-view>
5256
<wx-view

packages/components/picker/__test__/index.test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,88 @@ describe('picker', () => {
4242
expect($city.toJSON()).toMatchSnapshot();
4343
});
4444

45+
it(': cancelBtn false', async () => {
46+
const comp = simulate.render(id);
47+
comp.attach(document.createElement('parent-wrapper'));
48+
49+
const $picker = comp.querySelector('#city');
50+
comp.setData({ cityVisible: true });
51+
$picker.instance.setData({ cancelBtn: false });
52+
await simulate.sleep();
53+
54+
expect($picker.querySelector('.t-picker__cancel')).toBeUndefined();
55+
expect($picker.querySelector('.t-picker__confirm')).toBeDefined();
56+
});
57+
58+
it(': cancelBtn true', async () => {
59+
const comp = simulate.render(id);
60+
comp.attach(document.createElement('parent-wrapper'));
61+
62+
const $picker = comp.querySelector('#city');
63+
comp.setData({ cityVisible: true });
64+
$picker.instance.setData({ cancelBtn: true });
65+
await simulate.sleep();
66+
67+
const $cancel = $picker.querySelector('.t-picker__cancel');
68+
expect($cancel).toBeDefined();
69+
expect($cancel.dom.textContent.trim()).toBe('取消');
70+
});
71+
72+
it(': cancelBtn custom text', async () => {
73+
const comp = simulate.render(id);
74+
comp.attach(document.createElement('parent-wrapper'));
75+
76+
const $picker = comp.querySelector('#city');
77+
comp.setData({ cityVisible: true });
78+
$picker.instance.setData({ cancelBtn: '返回' });
79+
await simulate.sleep();
80+
81+
const $cancel = $picker.querySelector('.t-picker__cancel');
82+
expect($cancel).toBeDefined();
83+
expect($cancel.dom.textContent.trim()).toBe('返回');
84+
});
85+
86+
it(': confirmBtn false', async () => {
87+
const comp = simulate.render(id);
88+
comp.attach(document.createElement('parent-wrapper'));
89+
90+
const $picker = comp.querySelector('#city');
91+
comp.setData({ cityVisible: true });
92+
$picker.instance.setData({ confirmBtn: false });
93+
await simulate.sleep();
94+
95+
expect($picker.querySelector('.t-picker__cancel')).toBeDefined();
96+
expect($picker.querySelector('.t-picker__confirm')).toBeUndefined();
97+
});
98+
99+
it(': confirmBtn true', async () => {
100+
const comp = simulate.render(id);
101+
comp.attach(document.createElement('parent-wrapper'));
102+
103+
const $picker = comp.querySelector('#city');
104+
comp.setData({ cityVisible: true });
105+
$picker.instance.setData({ confirmBtn: true });
106+
await simulate.sleep();
107+
108+
const $confirm = $picker.querySelector('.t-picker__confirm');
109+
expect($confirm).toBeDefined();
110+
expect($confirm.dom.textContent.trim()).toBe('确认');
111+
});
112+
113+
it(': confirmBtn custom text', async () => {
114+
const comp = simulate.render(id);
115+
comp.attach(document.createElement('parent-wrapper'));
116+
117+
const $picker = comp.querySelector('#city');
118+
comp.setData({ cityVisible: true });
119+
$picker.instance.setData({ confirmBtn: '完成' });
120+
await simulate.sleep();
121+
122+
const $confirm = $picker.querySelector('.t-picker__confirm');
123+
expect($confirm).toBeDefined();
124+
expect($confirm.dom.textContent.trim()).toBe('完成');
125+
});
126+
45127
it(':change', async () => {
46128
const comp = simulate.render(id);
47129
comp.attach(document.createElement('parent-wrapper'));

packages/components/picker/_example/area/index.wxml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
visible="{{areaVisible}}"
55
value="{{areaValue}}"
66
title="选择地区"
7-
cancelBtn="取消"
8-
confirmBtn="确认"
97
usingCustomNavbar
108
bindchange="onPickerChange"
119
bindpick="onColumnChange"

packages/components/picker/_example/base/index.wxml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
value="{{cityValue}}"
88
data-key="city"
99
title="选择城市"
10-
cancelBtn="取消"
11-
confirmBtn="确认"
1210
usingCustomNavbar
1311
bindchange="onPickerChange"
1412
bindpick="onColumnChange"
@@ -28,8 +26,6 @@
2826
value="{{dateValue}}"
2927
data-key="date"
3028
title="选择时间"
31-
cancelBtn="取消"
32-
confirmBtn="确认"
3329
usingCustomNavbar
3430
bindchange="onPickerChange"
3531
bindpick="onColumnChange"

packages/components/picker/_example/with-title/index.wxml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
value="{{cityValue}}"
88
data-key="city"
99
title="{{cityTitle}}"
10-
cancelBtn="取消"
11-
confirmBtn="确认"
1210
usingCustomNavbar
1311
bindchange="onPickerChange"
1412
bindpick="onColumnChange"
@@ -22,8 +20,6 @@
2220
value="{{city2Value}}"
2321
data-key="city2"
2422
title="{{city2Title}}"
25-
cancelBtn="取消"
26-
confirmBtn="确认"
2723
usingCustomNavbar
2824
bindchange="onPickerChange"
2925
bindpick="onColumnChange"

packages/components/picker/_example/without-popup/index.wxml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
usePopup="{{false}}"
55
data-key="city"
66
title="{{cityTitle}}"
7-
cancelBtn="取消"
8-
confirmBtn="确认"
97
usingCustomNavbar
108
bindchange="onPickerChange"
119
bindpick="onColumnChange"

packages/components/picker/template.wxml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<view slot="content" style="{{_._style([style, customStyle])}}" class="{{classPrefix}} {{prefix}}-class">
44
<view class="{{classPrefix}}__toolbar" wx:if="{{header}}">
5-
<view class="{{classPrefix}}__cancel {{prefix}}-class-cancel" wx:if="{{cancelBtn}}" bindtap="onCancel"
6-
>{{globalConfig.cancel}}</view
7-
>
5+
<view class="{{classPrefix}}__cancel {{prefix}}-class-cancel" wx:if="{{cancelBtn}}" bindtap="onCancel">
6+
{{cancelBtn === true ? globalConfig.cancel : cancelBtn}}
7+
</view>
88
<view class="{{classPrefix}}__title {{prefix}}-class-title">{{title}}</view>
9-
<view class="{{classPrefix}}__confirm {{prefix}}-class-confirm" wx:if="{{confirmBtn}}" bindtap="onConfirm"
10-
>{{globalConfig.confirm}}</view
11-
>
9+
<view class="{{classPrefix}}__confirm {{prefix}}-class-confirm" wx:if="{{confirmBtn}}" bindtap="onConfirm">
10+
{{confirmBtn === true ? globalConfig.confirm : confirmBtn}}
11+
</view>
1212
</view>
1313
<slot name="header" />
1414

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4480
3+
contributor: liweijie0812
4+
---
5+
6+
- fix(Picker): 修复按钮自定义文案无效 @liweijie0812 ([#4480](https://github.com/Tencent/tdesign-miniprogram/pull/4480))

0 commit comments

Comments
 (0)