Skip to content

Commit

Permalink
fixed the tour now closing when a custom onClose function is provid…
Browse files Browse the repository at this point in the history
…ed. `onClose` now allows you to return a boolean to prevent the tour from closing if you wish.
  • Loading branch information
Eitan Elbaz committed Jul 6, 2023
1 parent 729a53a commit ad9c125
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ReactGrandTourContext = createContext<ReactGrandTourContextType>({
open: () => {},
openWith: () => {},
steps: [],
close: () => {},
close: () => true,
isOpen: false,
goToStep: () => {},
goBack: () => {},
Expand Down
9 changes: 5 additions & 4 deletions src/ReactGrandTour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ const ReactGrandTour: React.FC<Props> = ({
if (reason === 'escape' && disableCloseOnEscape) return;
if (reason === 'backdrop' && disableCloseOnBackdropClick) return;

if (onClose) {
onClose(reason);
} else {
const shouldClose = onClose ? onClose(reason) : true;
if (shouldClose) {
setOpen(false);
setSteps(defaultSteps);
}
setSteps(defaultSteps);

return true;
},
[
onClose,
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export type ReactGrandTourProps = ComponentVisibility &
Partial<ComponentOverrides> & {
open?: boolean;
onOpen?: () => void;
onClose?: (reason?: ReactGrandTourCloseReason) => void;
// returning false will prevent the tour from closing
onClose?: (reason?: ReactGrandTourCloseReason) => boolean;
onStepChange?: (props: OnStepChangeProps) => void;
openAt?: number;
steps?: ReactGrandTourStep[];
Expand Down

0 comments on commit ad9c125

Please sign in to comment.