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

为 Carousel 组件添加 ARIA 支持 #282

Merged
merged 2 commits into from
Apr 12, 2018
Merged
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
25 changes: 16 additions & 9 deletions packages/veui-theme-one/components/carousel.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@

&:hover,
&.focus-visible {
background-color: fadeout(#000, 60%);
&:not(:disabled) {
background-color: fadeout(#000, 60%);
}
}

&:active:not(:disabled) {
background-color: fadeout(#000, 40%);
}
}

Expand All @@ -63,10 +69,7 @@
overflow: hidden;
background: no-repeat center/cover;
transition: opacity .3s;

img {
visibility: hidden;
}
outline: none;

&-enter,
&-leave-to {
Expand All @@ -88,10 +91,6 @@
&:disabled {
opacity: .5;
cursor: default;

&:hover {
background-color: fadeout(#000, 80%);
}
}

&-prev {
Expand Down Expand Up @@ -131,6 +130,10 @@
background-color: #fff;
box-shadow: 0 0 4px fadeout(#000, 80%);
}

&:active {
background-color: @veui-gray-color-7;
}
}
}

Expand Down Expand Up @@ -218,6 +221,10 @@
&.focus-visible {
background-color: @veui-gray-color-1;
}

&:active {
background-color: #fff;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/veui/demo/cases/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<p><veui-checkbox v-model="autoplay"><code>autoplay</code></veui-checkbox></p>
<p><veui-checkbox v-model="wrap"><code>wrap</code></veui-checkbox></p>
<p><veui-checkbox v-model="pauseOnHover"><code>pause-on-hover</code></veui-checkbox></p>
<p><veui-radio-group v-model="trigger" :items="triggers"></veui-radio-group></p>
<p><veui-radio-group v-model="size" :items="sizes"></veui-radio-group></p>
<p><veui-radio-group v-model="indicator" :items="indicators"></veui-radio-group></p>
<p><veui-radio-group v-model="trigger" :items="triggers"/></p>
<p><veui-radio-group v-model="size" :items="sizes"/></p>
<p><veui-radio-group v-model="indicator" :items="indicators"/></p>
<section>
<veui-carousel :datasource="items" :index.sync="index" :ui="ui" :interval="interval" :pause-on-hover="pauseOnHover"
:switch-trigger="trigger" :wrap="wrap" :indicator="indicator" :autoplay="autoplay"></veui-carousel>
Expand Down
84 changes: 48 additions & 36 deletions packages/veui/src/components/Carousel.vue
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
<template>
<div class="veui-carousel" :ui="ui">
<div class="veui-carousel-viewport" @mouseenter="handleEnter" @mouseleave="handleLeave">
<transition-group name="veui-carousel-item" class="veui-carousel-items" tag="ol">
<li v-for="(item, i) in datasource" v-show="localIndex === i" :key="i"
:class="{
'veui-carousel-item': true,
'veui-carousel-item-current': localIndex === i
}"
:style="{
'background-image': `url(${item.src})`
<transition-group name="veui-carousel-item" class="veui-carousel-items" tag="ol">
<li
v-for="(item, i) in datasource"
v-show="localIndex === i"
ref="item"
:key="i"
:class="{
'veui-carousel-item': true,
'veui-carousel-item-current': localIndex === i
}"
:style="{
'background-image': `url(${item.src})`
}"
tabindex="0">
<slot v-bind="item" :index="i">
<img class="veui-sr-only" :src="item.src" :alt="item.alt">
</slot>
</li>
</transition-group>
<div v-if="indicator === 'number'" class="veui-carousel-indicator-numbers">{{ localIndex + 1 }}<span class="veui-carousel-indicator-numbers-separator"></span>{{ count }}</div>
<nav v-else-if="indicator !== 'none'" :class="{
[`veui-carousel-indicator-${indicator}s`]: true
}">
<slot v-bind="item" :index="i">
<img :src="item.src" :alt="item.alt">
</slot>
</li>
</transition-group>
<div v-if="indicator === 'number'" class="veui-carousel-indicator-numbers">{{ localIndex + 1 }}<span class="veui-carousel-indicator-numbers-separator"></span>{{ count }}</div>
<nav v-else-if="indicator !== 'none'" :class="{
[`veui-carousel-indicator-${indicator}s`]: true
}">
<button type="button" v-for="(item, i) in datasource" :key="i"
:class="{
'veui-carousel-indicator-item': true,
'veui-carousel-indicator-item-current': localIndex === i
}"
@click="select(i, 'click')"
@mouseenter="select(i, 'hover')"
>{{ item.label || `第 ${i + 1} 页` }}</button>
</nav>
<button type="button" class="veui-carousel-control veui-carousel-control-prev"
@click="step(-1)"
:disabled="!wrap && localIndex === 0">
<veui-icon :name="icons.prev"/>
</button>
<button type="button" class="veui-carousel-control veui-carousel-control-next"
@click="step(1)"
:disabled="!wrap && localIndex === count - 1">
<veui-icon :name="icons.next"/>
</button>
<button type="button" v-for="(item, i) in datasource" :key="i"
:class="{
'veui-carousel-indicator-item': true,
'veui-carousel-indicator-item-current': localIndex === i
}"
@click="select(i, 'click')"
@mouseenter="select(i, 'hover')"
>{{ item.label || `第 ${i + 1} 页` }}</button>
</nav>
<button type="button" class="veui-carousel-control veui-carousel-control-prev"
@click="step(-1)"
:disabled="!wrap && localIndex === 0">
<veui-icon :name="icons.prev" label="上一页"/>
</button>
<button type="button" class="veui-carousel-control veui-carousel-control-next"
@click="step(1)"
:disabled="!wrap && localIndex === count - 1">
<veui-icon :name="icons.next" label="下一页"/>
</button>
</div>
<div class="veui-sr-only" aria-live="polite" aria-atomic="true">当前是第 {{ localIndex + 1 }} 页,共 {{ datasource.length }} 页</div>
</div>
</template>

Expand Down Expand Up @@ -124,6 +130,12 @@ export default {
return
}

if (event === 'click') {
setTimeout(() => {
this.$refs.item[this.localIndex].focus()
}, 0)
}

this.localIndex = index
},
initPlay () {
Expand Down
2 changes: 1 addition & 1 deletion packages/veui/src/components/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
},
data () {
return {
localChecked: this.checked
localChecked: this.model === this.value ? true : this.checked
}
},
computed: {
Expand Down
6 changes: 4 additions & 2 deletions packages/veui/src/components/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
v-for="(item, index) in items"
:key="index"
:value="item.value"
:model="value"
:disabled="item.disabled || realDisabled || realReadonly"
:checked="item.value === value"
@change="checked => handleChange(item.value, checked)"
@change="model => handleChange(item.value, model)"
:aria-posinset="index + 1"
:aria-setsize="items.length">
<slot v-bind="item">{{ item.label }}</slot>
Expand Down Expand Up @@ -46,7 +47,8 @@ export default {
}
},
methods: {
handleChange (value, checked) {
handleChange (value, model) {
let checked = value === model
if (checked) {
this.$emit('change', value)
}
Expand Down