Skip to content

Commit 6b1a20d

Browse files
committed
fix(esl-carousel): clear error response and validation for goTo carousel method
1 parent 7ba1e6e commit 6b1a20d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/esl/src/esl-carousel/core/esl-carousel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,12 @@ export class ESLCarousel extends ESLBaseElement {
297297
}
298298

299299
/** Goes to the target according to passed params */
300-
public goTo(target: HTMLElement | ESLCarouselSlideTarget, params: Partial<ESLCarouselActionParams> = {}): Promise<void> {
300+
public async goTo(target: HTMLElement | ESLCarouselSlideTarget, params: Partial<ESLCarouselActionParams> = {}): Promise<void> {
301301
if (target instanceof HTMLElement) return this.goTo(this.indexOf(target), params);
302-
if (!this.renderer) return Promise.reject();
303-
return this.renderer.navigate(toIndex(target, this.state), this.mergeParams(params));
302+
if (!this.renderer) throw new Error('Renderer is not available');
303+
const index = toIndex(target, this.state);
304+
if (isNaN(index.index)) throw new Error(`Invalid target index passed ${target}`);
305+
return this.renderer.navigate(index, this.mergeParams(params));
304306
}
305307

306308
/** Moves slides by the passed offset */

0 commit comments

Comments
 (0)