@kiva/kv-components 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.4](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.0.3...@kiva/kv-components@3.0.4) (2022-05-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * remove usage of currentInstance, re-implement indicator count update mechanism ([21dae02](https://github.com/kiva/kv-ui-elements/commit/21dae029094bdeecd4d352eea70a116c08af504c))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [3.0.3](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.0.2...@kiva/kv-components@3.0.3) (2022-05-16)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -68,5 +68,5 @@
68
68
  "optional": true
69
69
  }
70
70
  },
71
- "gitHead": "bf6cb32b35ce31c41323b3733a7231708876987e"
71
+ "gitHead": "2bf5d2277e1537b150e396320d72ece46f746840"
72
72
  }
@@ -14,7 +14,7 @@
14
14
  :key="index"
15
15
  class="tw-flex-none tw-relative"
16
16
  role="group"
17
- :aria-label="`slide ${index} of ${componentSlotKeys.length}`"
17
+ :aria-label="`slide ${index + 1} of ${componentSlotKeys.length}`"
18
18
  :aria-current="true ? currentIndex + 1 === index : false"
19
19
  :aria-hidden="isAriaHidden(index)"
20
20
  :tab-index="isAriaHidden(index) ? '-1' : false"
@@ -48,8 +48,11 @@
48
48
  />
49
49
  <span class="tw-sr-only">Show previous slide</span>
50
50
  </button>
51
- <div class="tw-mx-2 md:tw-mx-3 lg:tw-mx-4 tw-invisible md:tw-visible">
52
- {{ currentIndex + 1 }}/{{ slideIndicatorListLength() }}
51
+ <div
52
+ :aria-label="`screen ${currentIndex + 1} of ${slideIndicatorCount}`"
53
+ class="tw-mx-2 md:tw-mx-3 lg:tw-mx-4 tw-invisible md:tw-visible"
54
+ >
55
+ {{ currentIndex + 1 }}/{{ slideIndicatorCount }}
53
56
  </div>
54
57
  <button
55
58
  class="tw-text-primary
@@ -79,7 +82,6 @@ import {
79
82
  ref,
80
83
  toRefs,
81
84
  nextTick,
82
- getCurrentInstance,
83
85
  } from 'vue-demi';
84
86
  import EmblaCarousel from 'embla-carousel';
85
87
  import { mdiChevronLeft, mdiChevronRight } from '@mdi/js';
@@ -144,11 +146,8 @@ export default {
144
146
  const embla = ref(null);
145
147
  const slides = ref([]);
146
148
  const currentIndex = ref(0);
147
-
148
- const forceUpdate = () => {
149
- const instance = getCurrentInstance();
150
- instance.proxy.$forceUpdate();
151
- };
149
+ // The indicator count may differ from the slide count when multiple slides are in view
150
+ const slideIndicatorCount = ref(0);
152
151
 
153
152
  const componentSlotKeys = computed(() => {
154
153
  const keys = Object.keys(slots);
@@ -193,6 +192,18 @@ export default {
193
192
  */
194
193
  emit('interact-carousel', interactionType);
195
194
  };
195
+
196
+ /**
197
+ * Returns number of slides in the carousel
198
+ *
199
+ * @returns {Number}
200
+ */
201
+ const slideIndicatorListLength = () => {
202
+ const indicator = embla.value ? embla.value.scrollSnapList().length : 0;
203
+ slideIndicatorCount.value = indicator;
204
+ return indicator;
205
+ };
206
+
196
207
  /**
197
208
  * Reinitialize the carousel.
198
209
  * Used after adding slides dynamically.
@@ -214,7 +225,7 @@ export default {
214
225
  reInitVisible();
215
226
  }
216
227
  slides.value = embla.value.slideNodes();
217
- forceUpdate(); // force a re-render so embla.canScrollNext() gets called in the template
228
+ slideIndicatorListLength();
218
229
  };
219
230
  const onCarouselContainerClick = (e) => {
220
231
  // If we're dragging, block click handlers within slides
@@ -238,18 +249,8 @@ export default {
238
249
  }
239
250
  return false;
240
251
  };
241
- /**
242
- * Returns number of slides in the carousel
243
- *
244
- * @returns {Number}
245
- */
246
- const slideIndicatorListLength = () => {
247
- const indicator = embla.value ? embla.value.scrollSnapList().length : 0;
248
- return indicator;
249
- };
250
252
 
251
253
  onMounted(async () => {
252
- getCurrentInstance();
253
254
  embla.value = EmblaCarousel(rootEl.value, {
254
255
  loop: true,
255
256
  containScroll: 'trimSnaps',
@@ -268,23 +269,26 @@ export default {
268
269
  slidesToScroll: embla.value.slidesInView(true).length,
269
270
  inViewThreshold: 0.9,
270
271
  });
271
- forceUpdate();
272
+ slides.value = embla.value.slideNodes();
273
+ slideIndicatorListLength();
272
274
  }, 250),
273
275
  );
274
276
  }
275
277
 
276
278
  // get slide components
277
279
  slides.value = embla.value.slideNodes();
280
+ slideIndicatorListLength();
278
281
 
279
282
  embla.value.on('select', () => {
280
283
  currentIndex.value = embla.value.selectedScrollSnap();
281
-
282
284
  /**
283
285
  * The index of the slide that the carousel has changed to
284
286
  * @event change
285
287
  * @type {Event}
286
288
  */
287
- emit('change', currentIndex);
289
+ nextTick(() => {
290
+ emit('change', currentIndex);
291
+ });
288
292
  });
289
293
  });
290
294
 
@@ -303,6 +307,7 @@ export default {
303
307
  componentSlotKeys,
304
308
  nextIndex,
305
309
  previousIndex,
310
+ slideIndicatorCount,
306
311
  handleUserInteraction,
307
312
  goToSlide,
308
313
  reInit,
@@ -164,6 +164,78 @@ export const MultipleLoanCards2 = () => ({
164
164
  `,
165
165
  });
166
166
 
167
+ export const MultipleLoanCardsReInit = () => ({
168
+ components: {
169
+ KvCarousel,
170
+ KvButton,
171
+ },
172
+ template: `
173
+ <div data-testid="carousel-container">
174
+ <kv-carousel
175
+ ref="myCarouselRef"
176
+ :multiple-slides-visible="true"
177
+ slides-to-scroll="visible"
178
+ style="max-width: 800px;"
179
+ >
180
+ <template #slide1>
181
+ ${generateLoanCardTemplate(1)}
182
+ </template>
183
+ <template #slide2>
184
+ ${generateLoanCardTemplate(2)}
185
+ </template>
186
+ <template #slide3>
187
+ ${generateLoanCardTemplate(3)}
188
+ </template>
189
+ <template #slide4>
190
+ ${generateLoanCardTemplate(4)}
191
+ </template>
192
+ <template #slide5>
193
+ ${generateLoanCardTemplate(5)}
194
+ </template>
195
+ <template #slide6>
196
+ ${generateLoanCardTemplate(6)}
197
+ </template>
198
+ <template #slide7>
199
+ ${generateLoanCardTemplate(7)}
200
+ </template>
201
+ <template #slide8>
202
+ ${generateLoanCardTemplate(8)}
203
+ </template>
204
+ </kv-carousel>
205
+ <kv-button @click.native.prevent="removeSlide()" role="removeSlideButton">Remove Slide</kv-button>
206
+ <p>Slide Count: {{ slideCount }} | Indicator Count: {{ slideIndicatorCount }} | Removed Slides: {{ removedSlides.length }}</p>
207
+ </div>
208
+ `,
209
+ data() {
210
+ return {
211
+ removedSlides: [],
212
+ slideCount: null,
213
+ slideIndicatorCount: null,
214
+ };
215
+ },
216
+ mounted() {
217
+ this.$nextTick(() => {
218
+ this.slideCount = this.$refs?.myCarouselRef?.slides?.length;
219
+ this.slideIndicatorCount = this.$refs?.myCarouselRef?.slideIndicatorCount;
220
+ });
221
+ },
222
+ methods: {
223
+ removeSlide() {
224
+ // Fetch slides + remove one
225
+ const slides = this.$refs?.myCarouselRef?.embla?.slideNodes();
226
+ const slideToRemove = slides.pop();
227
+ this.removedSlides.push(slideToRemove);
228
+ this.$refs?.myCarouselRef?.embla?.containerNode()?.removeChild(slideToRemove);
229
+ // Call our component reInit method
230
+ this.$refs?.myCarouselRef?.reInit();
231
+ // Update values for reflection in story
232
+ this.slideCount = this.$refs?.myCarouselRef?.slides?.length;
233
+ this.selectedIndexCheck = this.$refs?.myCarouselRef?.currentIndex;
234
+ this.slideIndicatorCount = this.$refs?.myCarouselRef?.slideIndicatorCount;
235
+ },
236
+ },
237
+ });
238
+
167
239
  export const loadingLoanCardExample = () => ({
168
240
  components: {
169
241
  KvCarousel,