Skip to content

Commit a895b28

Browse files
ashtonmeuserquinnlangille
authored andcommitted
feat(carousel): Count slides by custom tag name (#322)
* feat(carousel): Count slides by custom tag name * fix(carousel): flush the slides left when they don't fill the width (#323) * fix(carousel): Flush the slides left when they don't fill the width (#323) When there are too few slides to fill the row, with scrollPerPage, the slides were flushed right instead of left. By bounding maxOffest to a minimum of 0, the slides are aligned on the left-hand-side Fix #323 * style(play): Use capitals in tests for consistency * v0.16.1 * chore: build * Rebuild * Use Vue Test Utils, rebuild * Discard change to package version
1 parent 7d5cb5c commit a895b28

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default {
9191
| spacePadding | Number | 0 | Stage padding option adds left and right padding style (in pixels) onto VueCarousel-inner. |
9292
| spacePaddingMaxOffsetFactor | Number | 0 | Specify by how much should the space padding value be multiplied of, to re-arange the final slide padding. |
9393
| speed | Number | 500 | Slide transition speed. Number of milliseconds accepted. |
94+
| tagName | String | slide | Name (tag) of slide component. Overwrite with coponent name when extending slide component. |
9495
| value | Number | | Support for v-model functionality. Setting this value will change the current page to the number inputted (if between 0 and pageCount). |
9596

9697

dist/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/themes/vue/source/js/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Carousel.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ export default {
310310
type: Number,
311311
default: 500
312312
},
313+
/**
314+
* Name (tag) of slide component
315+
* Overwrite when extending slide component
316+
*/
317+
tagName: {
318+
type: String,
319+
default: "slide"
320+
},
313321
/**
314322
* Support for v-model functionality
315323
*/
@@ -634,7 +642,9 @@ export default {
634642
(this.$slots &&
635643
this.$slots.default &&
636644
this.$slots.default.filter(
637-
slot => slot.tag && slot.tag.indexOf("slide") > -1
645+
slot =>
646+
slot.tag &&
647+
slot.tag.match(`^vue-component-\\d+-${this.tagName}$`) !== null
638648
).length) ||
639649
0;
640650
},
@@ -644,7 +654,9 @@ export default {
644654
*/
645655
getSlide(index) {
646656
const slides = this.$children.filter(
647-
child => child.$vnode.tag.indexOf("slide") > -1
657+
child =>
658+
child.$vnode.tag.match(`^vue-component-\\d+-${this.tagName}$`) !==
659+
null
648660
);
649661
return slides[index];
650662
},

tests/client/components/__snapshots__/carousel.spec.js.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,21 @@ exports[`Carousel should not reset autoplay when switching slide with autoplayHo
213213
"
214214
`;
215215

216+
exports[`Carousel should only count slides matching tagName 1`] = `
217+
".VueCarousel-wrapper
218+
.VueCarousel-inner(role='listbox', style='transform: translate(0px, 0); visibility: hidden; height: auto;')
219+
.VueCarousel-slide(tabindex='-1')
220+
.VueCarousel-slide(tabindex='-1')
221+
.VueCarousel-slide(tabindex='-1')
222+
|
223+
.VueCarousel-pagination(style='display: none;')
224+
ul.VueCarousel-dot-container(role='tablist')
225+
li.VueCarousel-dot.VueCarousel-dot--active(aria-hidden='false', role='presentation', aria-selected='true', style='margin-top: 20px; padding: 10px;')
226+
button.VueCarousel-dot-button(type='button', role='button', aria-label='\`Item \${index}\`', title='Item 0', tabindex='0', style='width: 10px; height: 10px; background: rgb(0, 0, 0);')
227+
//
228+
"
229+
`;
230+
216231
exports[`Carousel should register 0 slides when 0 slides are added to the slots 1`] = `
217232
".VueCarousel-wrapper
218233
.VueCarousel-inner(role='listbox', style='transform: translate(0px, 0); visibility: hidden; height: auto;')

tests/client/components/carousel.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,24 @@ describe('Carousel', () => {
292292
return utils.expectToMatchSnapshot(wrapper.vm);
293293
});
294294

295+
it('should only count slides matching tagName', () => {
296+
const CustomSlide = {
297+
extends: Slide,
298+
name: 'CustomSlide',
299+
};
300+
const wrapper = mount(Carousel, {
301+
propsData: {
302+
tagName: 'CustomSlide'
303+
},
304+
slots: {
305+
default: [CustomSlide, CustomSlide, Slide]
306+
}
307+
});
308+
expect(wrapper.vm.tagName).toBe('CustomSlide');
309+
expect(wrapper.vm.slideCount).toBe(2);
310+
return utils.expectToMatchSnapshot(wrapper.vm);
311+
});
312+
295313
it('should set carousel height to slide height', done => {
296314
const wrapper = mount(Carousel, {
297315
propsData: {

0 commit comments

Comments
 (0)