@obosbbl/grunnmuren-react 3.3.3 → 3.3.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/dist/index.mjs +11 -5
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1041,11 +1041,17 @@ const Carousel = ({ className, children, onChange, ...rest })=>{
|
|
|
1041
1041
|
}
|
|
1042
1042
|
isScrollingProgrammatically.current = true;
|
|
1043
1043
|
const elementWithFocusVisible = carouselRef.current?.querySelector(':focus-visible');
|
|
1044
|
-
carouselItemsRef.current.children[scrollTargetIndex]
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1044
|
+
const targetElement = carouselItemsRef.current.children[scrollTargetIndex];
|
|
1045
|
+
if (targetElement) {
|
|
1046
|
+
// Calculate the scroll position to scroll the target element into view
|
|
1047
|
+
const containerRect = carouselItemsRef.current.getBoundingClientRect();
|
|
1048
|
+
const targetRect = targetElement.getBoundingClientRect();
|
|
1049
|
+
const scrollLeft = carouselItemsRef.current.scrollLeft + (targetRect.left - containerRect.left);
|
|
1050
|
+
carouselItemsRef.current.scrollTo({
|
|
1051
|
+
left: Math.round(scrollLeft),
|
|
1052
|
+
behavior: prefersReducedMotion ? 'instant' : 'smooth'
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1049
1055
|
if (prevIndex.current !== scrollTargetIndex && onChange) {
|
|
1050
1056
|
onChange({
|
|
1051
1057
|
index: scrollTargetIndex,
|