Skip to content
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

fix(rate): 评分组件支持无障碍滑动 #1574

Merged
merged 10 commits into from
Apr 18, 2023
14 changes: 14 additions & 0 deletions src/common/style/utilities/_index.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@
transform: scaleX(0.5);
}
}

.sr-only() {
LeeJim marked this conversation as resolved.
Show resolved Hide resolved
&--sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
clip-path: inset(50%);
border: 0;
}
}
2 changes: 1 addition & 1 deletion src/rate/_example/special/index.wxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<view class="demo-rate">
<view class="rate-wrapper">
<t-rate value="{{value}}" size="30" bind:change="onChange" />
<t-rate value="{{value}}" size="30" bind:change="onChange" texts="{{texts}}" />
</view>
<view class="desc desc--{{value > 3 ? 'active' : ''}}">{{texts[value - 1]}}</view>
</view>
1 change: 1 addition & 0 deletions src/rate/rate.less
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
color: @rate-text-active-color;
font-weight: @rate-text-active-font-weight;
}
.sr-only();
}

&__tips {
Expand Down
9 changes: 9 additions & 0 deletions src/rate/rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Rate extends SuperComponent {
tipsLeft: 0,
actionType: '',
scaleIndex: -1,
isVisibleToScreenReader: false,
};

methods = {
Expand Down Expand Up @@ -69,6 +70,14 @@ export default class Rate extends SuperComponent {
},
onTouchMove(e: WechatMiniprogram.TouchEvent) {
this.onTouch(e, 'move');
this.setData({
isVisibleToScreenReader: true,
});
setTimeout(() => {
this.setData({
isVisibleToScreenReader: false,
});
}, 2e3);
},
onTouchEnd() {
if (this.data.actionType === 'move') {
Expand Down
21 changes: 18 additions & 3 deletions src/rate/rate.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,36 @@
catch:tap="{{ !disabled ? 'onTap' : '' }}"
catch:touchend="{{ !disabled ? 'onTouchEnd' : ''}}"
catch:touchcancel="{{ !disabled ? 'onTouchEnd' : ''}}"
aria-role="slider"
aria-valuemax="{{count}}"
aria-valuemin="{{0}}"
syxysszyw marked this conversation as resolved.
Show resolved Hide resolved
aria-valuenow="{{value}}"
aria-valuetext="{{utils.getText(texts,value,defaultTexts)}}"
>
<t-icon
wx:for="{{ count }}"
wx:key="*this"
class="{{classPrefix }}__icon {{utils.getIconClass(classPrefix + '__icon', defaultValue, value, index, allowHalf, disabled, scaleIndex)}}"
style="margin-right:{{ count - index > 1 ? gap : 0 }}px; {{utils.getColor(color)}}"
t-class="{{prefix}}-class-icon"
name="{{utils.getIconName(defaultValue, value, index, variant, icon)}}"
size="{{ size }}"
style="margin-right:{{ count - index > 1 ? gap : 0 }}px; {{utils.getColor(color)}}"
/>
</view>
<text wx:if="{{showText}}" class="{{_.cls(classPrefix + '__text', [['active', value > 0]])}} {{prefix}}-class-text"
<text
wx:if="{{showText}}"
class="{{_.cls(classPrefix + '__text', [['active', value > 0]])}} {{prefix}}-class-text"
aria-hidden="{{true}}"
>{{utils.getText(texts,value,defaultTexts)}}</text
>
<view wx:if="{{tipsVisible}}" class="{{classPrefix}}__tips" style="left: {{tipsLeft}}px">
<text
wx:if="{{isVisibleToScreenReader}}"
class="{{_.cls(classPrefix + '__text', [['active', value > 0], ['sr-only', isVisibleToScreenReader]])}} {{prefix}}-class-text"
aria-role="alert"
aria-live="assertive"
>{{value+'星'}} {{utils.getText(texts,value,defaultTexts)}}</text
LeeJim marked this conversation as resolved.
Show resolved Hide resolved
>
<view wx:if="{{tipsVisible}}" class="{{classPrefix}}__tips" style="left: {{tipsLeft}}px" aria-hidden="{{true}}">
<block wx:if="{{actionType == 'tap'}}">
<view
wx:if="{{allowHalf}}"
Expand Down