Skip to content

Commit 7ab0581

Browse files
committed
feat(picker): 支持点击选择, 无障碍适配. (#1051)
1 parent ee5a148 commit 7ab0581

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

src/picker-item/picker-item.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ export default class PickerItem extends SuperComponent {
9191
});
9292
});
9393
},
94+
onTap(e) {
95+
const { index } = e.currentTarget.dataset;
96+
const {
97+
itemHeight,
98+
data: { options, classPrefix },
99+
} = this;
100+
wx.createSelectorQuery()
101+
.in(this)
102+
.select(`#${classPrefix}__group`)
103+
.node()
104+
.exec((res) => {
105+
const scrollView = res[0].node;
106+
scrollView.scrollTo({
107+
top: 0,
108+
});
109+
});
110+
this.setData({
111+
duration: DefaultDuration,
112+
offset: -index * itemHeight,
113+
});
114+
wx.nextTick(() => {
115+
this._selectedIndex = index;
116+
this._selectedValue = options[index]?.value;
117+
this._selectedLabel = options[index]?.label;
118+
this.parent?.triggerColumnChange({
119+
index,
120+
column: this.columnIndex || 0,
121+
});
122+
});
123+
},
94124

95125
// 刷新选中状态
96126
update() {

src/picker-item/picker-item.wxml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<wxs src="../common/utils.wxs" module="_" />
22
<view
3+
id="{{classPrefix}}__group"
34
style="{{ style }}"
45
class="{{_.cls(classPrefix + '__group', [])}} class {{prefix}}-class"
6+
enhanced="true"
57
bind:touchstart="onTouchStart"
68
catch:touchmove="onTouchMove"
79
bind:touchend="onTouchEnd"
@@ -17,8 +19,9 @@
1719
wx:key="index"
1820
wx:for-item="option"
1921
data-index="{{ index }}"
22+
bind:tap="onTap"
2023
>
2124
{{option.label}}
2225
</view>
2326
</view>
24-
</view>
27+
</scroll-view>

src/picker/picker.wxml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
<wxs src="../common/utils.wxs" module="_" />
22

33
<t-popup visible="{{visible}}" placement="bottom" bind:visible-change="onPopupChange">
4-
<view slot="content" style="{{ style }}" class="{{classPrefix}} {{prefix}}-class">
4+
<view
5+
slot="content"
6+
style="{{ style }}"
7+
class="{{classPrefix}} {{prefix}}-class"
8+
tabindex="-1"
9+
focus="{{true}}"
10+
>
511
<view class="{{classPrefix}}__toolbar" wx:if="{{header}}">
6-
<view class="{{classPrefix}}__cancel {{prefix}}-class-cancel" wx:if="{{cancelBtn}}" bindtap="onCancel"
12+
<view
13+
class="{{classPrefix}}__cancel {{prefix}}-class-cancel"
14+
wx:if="{{cancelBtn}}"
15+
bindtap="onCancel"
16+
aria-role="button"
717
>{{cancelBtn}}</view
818
>
9-
<view class="{{classPrefix}}__title {{prefix}}-class-title">{{title}}</view>
10-
<view class="{{classPrefix}}__confirm {{prefix}}-class-confirm" wx:if="{{confirmBtn}}" bindtap="onConfirm"
19+
<view class="{{classPrefix}}__title {{prefix}}-class-title" focus="{{true}}" aria-label="{{title}}选择框"
20+
>{{title}}</view
21+
>
22+
<view
23+
class="{{classPrefix}}__confirm {{prefix}}-class-confirm"
24+
wx:if="{{confirmBtn}}"
25+
bindtap="onConfirm"
26+
aria-role="button"
1127
>{{confirmBtn}}</view
1228
>
1329
</view>

0 commit comments

Comments
 (0)