Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Oct 28, 2023
1 parent caee450 commit dcbba90
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
29 changes: 16 additions & 13 deletions src/components/Beacon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ export default class JoyrideBeacon extends React.Component<BeaconProps> {
constructor(props: BeaconProps) {
super(props);

if (!props.beaconComponent) {
const head = document.head || document.getElementsByTagName('head')[0];
const style = document.createElement('style');
const css = `
if (props.beaconComponent) {
return;
}

const head = document.head || document.getElementsByTagName('head')[0];
const style = document.createElement('style');

style.id = 'joyride-beacon-animation';

if (props.nonce) {
style.setAttribute('nonce', props.nonce);
}

const css = `
@keyframes joyride-beacon-inner {
20% {
opacity: 0.9;
Expand Down Expand Up @@ -41,16 +51,9 @@ export default class JoyrideBeacon extends React.Component<BeaconProps> {
}
`;

style.id = 'joyride-beacon-animation';

if (props.nonce) {
style.setAttribute('nonce', props.nonce);
}
style.appendChild(document.createTextNode(css));

style.appendChild(document.createTextNode(css));

head.appendChild(style);
}
head.appendChild(style);
}

componentDidMount() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export default class JoyrideOverlay extends React.Component<OverlayProps, State>
this.isActive = true;

/* istanbul ignore else */
if (!disableScrolling) {
if (process.env.NODE_ENV !== 'production') {
/* istanbul ignore else */
if (process.env.NODE_ENV === 'development' && hasCustomScrollParent(element, true)) {
if (!disableScrolling && hasCustomScrollParent(element, true)) {
log({
title: 'step has a custom scroll parent and can cause trouble with scrolling',
data: [{ key: 'parent', value: this.scrollParent }],
Expand Down
5 changes: 2 additions & 3 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ class Joyride extends React.Component<Props, State> {
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();
}
}
Expand Down Expand Up @@ -272,7 +271,7 @@ class Joyride extends React.Component<Props, State> {
} = 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,
Expand Down
8 changes: 8 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test';
}
}
}
export {};
2 changes: 1 addition & 1 deletion src/modules/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ShouldScrollOptions {
previousLifecycle: Lifecycle;
scrollToFirstStep: boolean;
step: Step;
target: HTMLElement;
target: HTMLElement | null;
}

export const isReact16 = createPortal !== undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};
}
1 change: 0 additions & 1 deletion test/modules/scope.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe('modules/scope', () => {
});

it('should not have created an instance', () => {
// expect(Scope).toHaveBeenCalledTimes(1);
expect(scope).toBeUndefined();
});
});
Expand Down

0 comments on commit dcbba90

Please sign in to comment.