Skip to content

Commit f2b5c35

Browse files
author
hoanguyen
committed
🎉🚀 version 2.1.6
1 parent bb7dbad commit f2b5c35

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default {
9999
| value | Number | | Support for v-model functionality. Setting this value will change the current page to the number inputted (if between 0 and pageCount). |
100100
| maxPaginationDotCount | Number | -1 | Support Max pagination dot amount |
101101
| rtl | Boolean | false | Support right to left |
102+
| keyboard | Boolean | false | Navigate slide using keyboard |
102103

103104

104105
## Events

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jambonn/vue-concise-carousel",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "Vue Concise Carousel is SSR and CSR friendly",
55
"keywords": [
66
"vue",

src/Carousel.vue

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ export default {
376376
type: String,
377377
default: 'forward',
378378
},
379+
/**
380+
* Flag to navigate slide using keyboard
381+
*/
382+
keyboard: {
383+
type: Boolean,
384+
default: false,
385+
},
379386
},
380387
setup(props, ctx) {
381388
const browserWidth = ref(null)
@@ -909,6 +916,16 @@ export default {
909916
const handleTransitionEnd = () => {
910917
ctx.emit('transition-end')
911918
}
919+
const keyboardEventHandler = ({ keyCode }) => {
920+
const isArrowLeft = keyCode === 37
921+
const isArrowRight = keyCode === 39
922+
if (canAdvanceBackward.value && isArrowLeft) {
923+
advancePage('backward')
924+
}
925+
if (canAdvanceForward.value && isArrowRight) {
926+
advancePage('forward')
927+
}
928+
}
912929
913930
provide('carousel', {
914931
isTouch,
@@ -959,13 +976,29 @@ export default {
959976
ctx.emit('input', val)
960977
})
961978
onMounted(() => {
962-
if (!isServer && props.autoplayHoverPause) {
963-
vueConciseCarousel.value.addEventListener('mouseenter', pauseAutoplay, {
964-
passive: true,
965-
})
966-
vueConciseCarousel.value.addEventListener('mouseleave', startAutoplay, {
967-
passive: true,
968-
})
979+
if (!isServer) {
980+
if (props.autoplayHoverPause) {
981+
vueConciseCarousel.value.addEventListener(
982+
'mouseenter',
983+
pauseAutoplay,
984+
{
985+
passive: true,
986+
},
987+
)
988+
vueConciseCarousel.value.addEventListener(
989+
'mouseleave',
990+
startAutoplay,
991+
{
992+
passive: true,
993+
},
994+
)
995+
}
996+
997+
if (props.keyboard) {
998+
document.addEventListener('keydown', keyboardEventHandler, {
999+
passive: true,
1000+
})
1001+
}
9691002
}
9701003
9711004
startAutoplay()
@@ -1011,15 +1044,21 @@ export default {
10111044
computeCarouselWidth()
10121045
})
10131046
onBeforeUnmount(() => {
1014-
if (!isServer && props.autoplayHoverPause) {
1015-
vueConciseCarousel.value.removeEventListener(
1016-
'mouseenter',
1017-
pauseAutoplay,
1018-
)
1019-
vueConciseCarousel.value.removeEventListener(
1020-
'mouseleave',
1021-
startAutoplay,
1022-
)
1047+
if (!isServer) {
1048+
if (props.autoplayHoverPause) {
1049+
vueConciseCarousel.value.removeEventListener(
1050+
'mouseenter',
1051+
pauseAutoplay,
1052+
)
1053+
vueConciseCarousel.value.removeEventListener(
1054+
'mouseleave',
1055+
startAutoplay,
1056+
)
1057+
}
1058+
1059+
if (props.keyboard) {
1060+
document.removeEventListener('keydown', keyboardEventHandler)
1061+
}
10231062
}
10241063
10251064
detachMutationObserver()

0 commit comments

Comments
 (0)