From 30db8d814f6292adacc73bba344332f74b55d0e0 Mon Sep 17 00:00:00 2001 From: Robert Taylor Date: Tue, 18 Jul 2023 14:52:32 +0100 Subject: [PATCH] fix: add defensive checks --- src/Slider/Slider.jsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Slider/Slider.jsx b/src/Slider/Slider.jsx index ede01c6..560ff6a 100644 --- a/src/Slider/Slider.jsx +++ b/src/Slider/Slider.jsx @@ -201,9 +201,14 @@ const Slider = class Slider extends React.Component { getSliderRef(el) { this.sliderTrayElement = el; - // NOTE: we can't rely on the element itself to detect direction - // as the direction of the slider is currently flipped to ltr - this.rtl = window.getComputedStyle(el.closest('.carousel'), null).getPropertyValue('direction') === 'rtl'; + if (el && window) { + // NOTE: we can't rely on the element itself to detect direction + // as the direction of the slider is currently flipped to ltr + const carouselElement = el.closest('.carousel'); + if (carouselElement) { + this.rtl = window.getComputedStyle(carouselElement, null).getPropertyValue('direction') === 'rtl'; + } + } }