Skip to content

feat(datetimepicker): support aria #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions src/date-time-picker/__test__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,27 @@ exports[`date-time-picker :base 1`] = `
class="t-picker__toolbar"
>
<wx-view
ariaRole="button"
class="t-picker__cancel t-class-cancel"
bind:tap="onCancel"
>
取消

取消

</wx-view>
<wx-view
class="t-picker__title t-class-title"
>
选择日期
</wx-view>
<wx-view
ariaRole="button"
class="t-picker__confirm t-class-confirm"
bind:tap="onConfirm"
>
确定

确定

</wx-view>
</wx-view>
<wx-view
Expand All @@ -67,6 +73,7 @@ exports[`date-time-picker :base 1`] = `
bind:touchstart="onTouchStart"
>
<wx-view
ariaHidden="{{true}}"
class="t-picker-item__wrapper"
style="transition: transform 0ms cubic-bezier(0.215, 0.61, 0.355, 1); transform: translate3d(0, -924px, 0)"
>
Expand Down Expand Up @@ -317,6 +324,39 @@ exports[`date-time-picker :base 1`] = `

2030年

</wx-view>
</wx-view>
<wx-view
class="t-picker-item__accessible"
>
<wx-view
ariaLabel="选择上一项:2020年"
ariaRole="button"
class="t-picker-item__accessible--button"
bind:tap="onClickPrev"
>

-

</wx-view>
<wx-view
ariaLabel="当前选择的是:2021年"
ariaRole="text"
class="t-picker-item__accessible--current"
>

-

</wx-view>
<wx-view
ariaLabel="选择下一项:2022年"
ariaRole="button"
class="t-picker-item__accessible--button"
bind:tap="onClickNext"
>

-

</wx-view>
</wx-view>
</wx-view>
Expand All @@ -334,6 +374,7 @@ exports[`date-time-picker :base 1`] = `
bind:touchstart="onTouchStart"
>
<wx-view
ariaHidden="{{true}}"
class="t-picker-item__wrapper"
style="transition: transform 0ms cubic-bezier(0.215, 0.61, 0.355, 1); transform: translate3d(0, -352px, 0)"
>
Expand Down Expand Up @@ -432,6 +473,39 @@ exports[`date-time-picker :base 1`] = `

12月

</wx-view>
</wx-view>
<wx-view
class="t-picker-item__accessible"
>
<wx-view
ariaLabel="选择上一项:8月"
ariaRole="button"
class="t-picker-item__accessible--button"
bind:tap="onClickPrev"
>

-

</wx-view>
<wx-view
ariaLabel="当前选择的是:9月"
ariaRole="text"
class="t-picker-item__accessible--current"
>

-

</wx-view>
<wx-view
ariaLabel="选择下一项:10月"
ariaRole="button"
class="t-picker-item__accessible--button"
bind:tap="onClickNext"
>

-

</wx-view>
</wx-view>
</wx-view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,38 @@ exports[`date-time-picker :base 1`] = `
</wx-view>
</wx-view>
<wx-view
class="t-popup__close"
bind:tap="handleClose"
/>
class="t-picker-item__accessible"
>
<wx-view
ariaLabel="选择上一项:8月"
ariaRole="button"
class="t-picker-item__accessible--button"
bind:tap="onClickPrev"
>

-

</wx-view>
<wx-view
ariaLabel="当前选择的是:9月"
ariaRole="text"
class="t-picker-item__accessible--current"
>

-

</wx-view>
<wx-view
ariaLabel="选择下一项:10月"
ariaRole="button"
class="t-picker-item__accessible--button"
bind:tap="onClickNext"
>

-

</wx-view>
</wx-view>
</wx-view>
</wx-view>
<t-overlay
Expand Down
32 changes: 32 additions & 0 deletions src/picker-item/picker-item.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,42 @@
overflow: hidden;
flex: 1;
z-index: 1;
position: relative;
}

&__wrapper {
padding: 144rpx 0;
position: absolute;
z-index: 1;
width: 100%;
left: 0;
}

&__accessible {
position: relative;
// top: calc(@picker-item-height * -1);
top: 0;
width: 100%;
height: 100%;
// pointer-events: none;
opacity: 0;
display: flex;
flex-direction: column;
z-index: 1;
padding-bottom: 1px;

&--current {
width: 100%;
height: 100%;
flex: 1;
text-overflow: ellipsis;
}
&--button {
width: 100%;
height: 100%;
flex: 2;
text-overflow: ellipsis;
}
}

&__item {
Expand Down
26 changes: 22 additions & 4 deletions src/picker-item/picker-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,23 @@ export default class PickerItem extends SuperComponent {
});
},

onTouchEnd() {
onTouchEnd(_, nowIndex) {
const { offset, labelAlias, valueAlias } = this.data;
const { options } = this.properties;

if (offset === this.StartOffset) {
let index = nowIndex;
if (index !== undefined && (index < 0 || index > options.length - 1)) {
return;
}
// 调整偏移量
const index = range(Math.round(-offset / this.itemHeight), 0, this.getCount() - 1);

if (index === undefined) {
if (offset === this.StartOffset) {
return;
}
// 调整偏移量
index = range(Math.round(-offset / this.itemHeight), 0, this.getCount() - 1);
}

this.setData({
curIndex: index,
offset: -index * this.itemHeight,
Expand All @@ -104,6 +112,16 @@ export default class PickerItem extends SuperComponent {
});
},

onClickPrev() {
const { curIndex } = this.data;
this.onTouchEnd(null, curIndex - 1);
},

onClickNext() {
const { curIndex } = this.data;
this.onTouchEnd(null, curIndex + 1);
},

// 刷新选中状态
update() {
const { options, value, labelAlias, valueAlias } = this.data;
Expand Down
27 changes: 27 additions & 0 deletions src/picker-item/picker-item.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
>
<view
class="{{classPrefix}}__wrapper"
aria-hidden="{{true}}"
style="transition: transform {{ duration }}ms cubic-bezier(0.215, 0.61, 0.355, 1); transform: translate3d(0, {{ offset }}px, 0)"
>
<view
Expand All @@ -22,4 +23,30 @@
{{option[labelAlias]}}
</view>
</view>

<view class="{{classPrefix}}__accessible">
<view
class="{{classPrefix}}__accessible--button"
aria-role="{{options[curIndex-1] ? 'button' : 'text'}}"
aria-label="{{ !options[curIndex-1] ? '没有上一项' : '选择上一项:'+ options[curIndex-1].label}}"
bind:tap="onClickPrev"
>
-
</view>
<view
class="{{classPrefix}}__accessible--current"
aria-role="text"
aria-label="{{ options[curIndex] ? '当前选择的是:' + options[curIndex].label : '当前未选择' }}"
>
-
</view>
<view
class="{{classPrefix}}__accessible--button"
aria-role="{{options[curIndex+1] ? 'button' : 'text'}}"
aria-label="{{!options[curIndex+1] ? '没有下一项' : '选择下一项:' + options[curIndex+1].label}}"
bind:tap="onClickNext"
>
-
</view>
</view>
</view>
Loading