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
15 changes: 15 additions & 0 deletions src/common/style/utilities/_index.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@
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;
}
}
9 changes: 9 additions & 0 deletions src/rate/__test__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ exports[`Rate Rate special demo works fine 1`] = `
>
<t-rate
size="30"
texts="{{
Array [
"非常糟糕",
"有些糟糕",
"可以尝试",
"可以前往",
"推荐前往",
]
}}"
value="{{4}}"
bind:change="onChange"
/>
Expand Down
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
14 changes: 14 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,7 @@ export default class Rate extends SuperComponent {
},
onTouchMove(e: WechatMiniprogram.TouchEvent) {
this.onTouch(e, 'move');
this.showAlertText()
},
onTouchEnd() {
if (this.data.actionType === 'move') {
Expand All @@ -86,5 +88,17 @@ export default class Rate extends SuperComponent {
this._trigger('change', { value });
setTimeout(() => this.setData({ tipsVisible: false, scaleIndex: -1 }), 300);
},
// 旁白模式: 变更数值时显示告警文案
showAlertText() {
if (this.data.isVisibleToScreenReader === true) return;
this.setData({
isVisibleToScreenReader: true,
});
setTimeout(() => {
this.setData({
isVisibleToScreenReader: false,
});
}, 2e3);
},
};
}
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