Skip to content

Commit

Permalink
fix(components): [carousel] improve a11y (element-plus#15579)
Browse files Browse the repository at this point in the history
* fix(a11y): carousel buttons do not have an accessible name

* fix: eslint warnings

* chore: change the label content

* feat: improve i18n
  • Loading branch information
cloydlau authored Feb 3, 2024
1 parent c46fe7f commit 73f4d0f
Show file tree
Hide file tree
Showing 60 changed files with 304 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/components/carousel/src/carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"
type="button"
:class="[ns.e('arrow'), ns.em('arrow', 'left')]"
:aria-label="t('el.carousel.leftArrow')"
@mouseenter="handleButtonEnter('left')"
@mouseleave="handleButtonLeave"
@click.stop="throttledArrowClick(activeIndex - 1)"
Expand All @@ -30,6 +31,7 @@
"
type="button"
:class="[ns.e('arrow'), ns.em('arrow', 'right')]"
:aria-label="t('el.carousel.rightArrow')"
@mouseenter="handleButtonEnter('right')"
@mouseleave="handleButtonLeave"
@click.stop="throttledArrowClick(activeIndex + 1)"
Expand All @@ -55,7 +57,10 @@
@mouseenter="throttledIndicatorHover(index)"
@click.stop="handleIndicatorClick(index)"
>
<button :class="ns.e('button')">
<button
:class="ns.e('button')"
:aria-label="t('el.carousel.indicator', { index: index + 1 })"
>
<span v-if="hasLabel">{{ item.props.label }}</span>
</button>
</li>
Expand All @@ -67,7 +72,7 @@
import { computed, unref } from 'vue'
import { ElIcon } from '@element-plus/components/icon'
import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
import { useNamespace } from '@element-plus/hooks'
import { useLocale, useNamespace } from '@element-plus/hooks'
import { carouselEmits, carouselProps } from './carousel'
import { useCarousel } from './use-carousel'
Expand Down Expand Up @@ -103,6 +108,8 @@ const {
} = useCarousel(props, emit, COMPONENT_NAME)
const ns = useNamespace('carousel')
const { t } = useLocale()
const carouselClasses = computed(() => {
const classes = [ns.b(), ns.m(props.direction)]
if (unref(isCardType)) {
Expand Down
5 changes: 5 additions & 0 deletions packages/locale/lang/af.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ar-eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,10 @@ export default {
confirmButtonText: 'نعم',
cancelButtonText: 'لا',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/az.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,10 @@ export default {
empty: {
description: 'Məlumat yoxdur',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/bn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ export default {
confirmButtonText: 'হ্যা',
cancelButtonText: 'না',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ export default {
confirmButtonText: 'Sí',
cancelButtonText: 'No',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ckb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,10 @@ export default {
confirmButtonText: 'بەڵێ',
cancelButtonText: 'نەخێر',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,10 @@ export default {
confirmButtonText: 'Ja',
cancelButtonText: 'Nein',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,10 @@ export default {
confirmButtonText: 'Yes',
cancelButtonText: 'No',
},
carousel: {
leftArrow: 'Carousel arrow left',
rightArrow: 'Carousel arrow right',
indicator: 'Carousel switch to index {index}',
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/eo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ export default {
confirmButtonText: 'Si',
cancelButtonText: 'No',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Jah',
cancelButtonText: 'Ei',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/eu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,10 @@ export default {
confirmButtonText: 'بله',
cancelButtonText: 'خیر',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,10 @@ export default {
confirmButtonText: 'Oui',
cancelButtonText: 'Non',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/he.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'כן',
cancelButtonText: 'לא',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/hr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/hu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/hy-am.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ export default {
confirmButtonText: 'Ya',
cancelButtonText: 'Tidak',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,10 @@ export default {
confirmButtonText: 'はい',
cancelButtonText: 'いいえ',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/kk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/km.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'យល់ព្រម',
cancelButtonText: 'មិនព្រម',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,10 @@ export default {
confirmButtonText: '예',
cancelButtonText: '아니오',
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
5 changes: 5 additions & 0 deletions packages/locale/lang/ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ export default {
confirmButtonText: 'Yes', // to be translated
cancelButtonText: 'No', // to be translated
},
carousel: {
leftArrow: 'Carousel arrow left', // to be translated
rightArrow: 'Carousel arrow right', // to be translated
indicator: 'Carousel switch to index {index}', // to be translated
},
},
}
Loading

0 comments on commit 73f4d0f

Please sign in to comment.