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(swiper): navigation support minShowNum #197

Merged
merged 1 commit into from
Jun 23, 2022
Merged
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
8 changes: 7 additions & 1 deletion src/swiper/swiper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>
<slot></slot>
</div>
<template v-if="navigation">
<template v-if="navigation && state.showNavigation">
<span v-if="direction === 'horizontal' && 'showSlideBtn' in navigation && navigation.showSlideBtn">
<span :class="`${name}__btn btn-prev`" @click="prev(1)">
<chevron-left-icon size="20px" />
Expand Down Expand Up @@ -80,13 +80,15 @@ export default defineComponent({
// const { height = 180, current = null } = props;
const height = props.height || 180;
const state: {
showNavigation: boolean;
activeIndex: number;
itemLength: number;
itemWidth: number;
isControl: boolean;
btnDisabled: boolean;
children: ComponentPublicInstance[];
} = reactive({
showNavigation: true,
activeIndex: 0,
itemLength: 0,
itemWidth: 0,
Expand All @@ -102,6 +104,7 @@ export default defineComponent({
return activeIndex + 1;
});
const childCount = computed(() => state.children.length);

const getContainer = (): HTMLDivElement => self?.proxy?.$el.querySelector('.t-swiper__container');
// const getContainer = (): HTMLDivElement => swiperContainer.value as any;
const initSwiper = () => {
Expand All @@ -114,6 +117,9 @@ export default defineComponent({
const itemWidth = _swiperContainer.querySelector('.t-swiper-item')?.getBoundingClientRect().width || 0;
state.itemWidth = itemWidth;
if (items.length <= 0) return false;
if ('minShowNum' in computedNavigation.value && items.length < computedNavigation.value.minShowNum) {
state.showNavigation = false;
}
if (props?.loop) {
const first = items[0].cloneNode(true) as HTMLDivElement;
first.classList.add('copy-item');
Expand Down