From 9eb4b1cab7d6797927cfcf0d1c98f3c26a3ec24e Mon Sep 17 00:00:00 2001 From: Gil Barbara Date: Fri, 27 Oct 2023 19:06:28 -0300 Subject: [PATCH] Minor fixes --- src/components/index.tsx | 5 ++--- src/modules/dom.ts | 2 +- src/modules/helpers.ts | 2 +- src/modules/scope.ts | 4 ++-- test/modules/scope.spec.tsx | 1 - 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/index.tsx b/src/components/index.tsx index cba922ff..5dd924a0 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -236,10 +236,9 @@ class Joyride extends React.Component { const { index, lifecycle } = this.state; const { steps } = this.props; const step = steps[index]; - const intKey = window.Event ? event.which : event.keyCode; if (lifecycle === LIFECYCLE.TOOLTIP) { - if (intKey === 27 && step && !step.disableCloseOnEsc) { + if (event.code === 'Escape' && step && !step.disableCloseOnEsc) { this.store.close(); } } @@ -272,7 +271,7 @@ class Joyride extends React.Component { } = this.props; const step = getMergedStep(steps[index], this.props); - const target = getElement(step.target) as HTMLElement; + const target = getElement(step.target); const shouldScrollToStep = shouldScroll({ isFirstStep: index === 0, lifecycle, diff --git a/src/modules/dom.ts b/src/modules/dom.ts index ddb0ceb4..486825d8 100644 --- a/src/modules/dom.ts +++ b/src/modules/dom.ts @@ -196,7 +196,7 @@ export function getElementPosition( /** * Get the scrollTop position */ -export function getScrollTo(element: HTMLElement, offset: number, skipFix: boolean): number { +export function getScrollTo(element: HTMLElement | null, offset: number, skipFix: boolean): number { if (!element) { return 0; } diff --git a/src/modules/helpers.ts b/src/modules/helpers.ts index 7b10ea2c..5ebc92ce 100644 --- a/src/modules/helpers.ts +++ b/src/modules/helpers.ts @@ -25,7 +25,7 @@ interface ShouldScrollOptions { previousLifecycle: Lifecycle; scrollToFirstStep: boolean; step: Step; - target: HTMLElement; + target: HTMLElement | null; } export const isReact16 = createPortal !== undefined; diff --git a/src/modules/scope.ts b/src/modules/scope.ts index 1659e720..0c46c308 100644 --- a/src/modules/scope.ts +++ b/src/modules/scope.ts @@ -128,11 +128,11 @@ export default class Scope { return; } - const target = this.element.querySelector(selector) as HTMLElement; + const target = this.element.querySelector(selector); /* istanbul ignore else */ if (target) { - window.requestAnimationFrame(() => this.checkFocus(target)); + window.requestAnimationFrame(() => this.checkFocus(target as HTMLElement)); } }; } diff --git a/test/modules/scope.spec.tsx b/test/modules/scope.spec.tsx index 6987687a..baeb16ed 100644 --- a/test/modules/scope.spec.tsx +++ b/test/modules/scope.spec.tsx @@ -51,7 +51,6 @@ describe('modules/scope', () => { }); it('should not have created an instance', () => { - // expect(Scope).toHaveBeenCalledTimes(1); expect(scope).toBeUndefined(); }); });