@@ -214,6 +214,37 @@ export class TPSliderElement extends HTMLElement {
214214 }
215215 }
216216
217+ /**
218+ * Get the arrow element by selector.
219+ *
220+ * In case of nested sliders, it difficult to find the correct arrow
221+ * because arrows can be placed anywhere.
222+ * This function checks if the parent tp-slider belongs to this component,
223+ * then return that arrow element, using 'this'.
224+ *
225+ * @param {string } selector Selector.
226+ */
227+ getArrow ( selector : string ) {
228+ // Get all arrows.
229+ const arrows : NodeListOf < TPSliderArrowElement > | null = this . querySelectorAll ( selector ) ;
230+ const parentSliderElement : TPSliderElement = this ;
231+ let theArrow : TPSliderArrowElement | null = this . querySelector ( selector ) ;
232+
233+ // Loop through all the arrows including the one's inside nested slider.
234+ arrows . forEach ( ( arrow ) => {
235+ /**
236+ * If the closest tp-slider is the same as the parentSliderElement, that means we have found
237+ * the correct arrow.
238+ */
239+ if ( parentSliderElement === arrow . closest ( 'tp-slider' ) ) {
240+ theArrow = arrow ;
241+ }
242+ } ) ;
243+
244+ // Return arrow.
245+ return theArrow ;
246+ }
247+
217248 /**
218249 * Update stuff when any attribute has changed.
219250 * Example: Update subcomponents.
@@ -222,8 +253,8 @@ export class TPSliderElement extends HTMLElement {
222253 // Get subcomponents.
223254 const sliderNavItems : NodeListOf < TPSliderNavItemElement > | null = this . querySelectorAll ( 'tp-slider-nav-item' ) ;
224255 const sliderCounts : NodeListOf < TPSliderCountElement > | null = this . querySelectorAll ( 'tp-slider-count' ) ;
225- const leftArrow : TPSliderArrowElement | null = this . querySelector ( 'tp-slider-arrow[direction="previous"]' ) ;
226- const rightArrow : TPSliderArrowElement | null = this . querySelector ( 'tp-slider-arrow[direction="next"]' ) ;
256+ const leftArrow : TPSliderArrowElement | null = this . getArrow ( 'tp-slider-arrow[direction="previous"]' ) ;
257+ const rightArrow : TPSliderArrowElement | null = this . getArrow ( 'tp-slider-arrow[direction="next"]' ) ;
227258
228259 // Set active slide.
229260 const slides : NodeListOf < TPSliderSlideElement > | null | undefined = this . getSlideElements ( ) ;
0 commit comments