diff --git a/src/Context.ts b/src/Context.ts index 382da12..05ccecd 100644 --- a/src/Context.ts +++ b/src/Context.ts @@ -5,7 +5,7 @@ const ReactGrandTourContext = createContext({ open: () => {}, openWith: () => {}, steps: [], - close: () => {}, + close: () => true, isOpen: false, goToStep: () => {}, goBack: () => {}, diff --git a/src/ReactGrandTour.tsx b/src/ReactGrandTour.tsx index f4785b8..bf01cf6 100644 --- a/src/ReactGrandTour.tsx +++ b/src/ReactGrandTour.tsx @@ -79,12 +79,13 @@ const ReactGrandTour: React.FC = ({ 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, diff --git a/src/types.ts b/src/types.ts index 7d8bbbb..0cbb506 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,7 +4,8 @@ export type ReactGrandTourProps = ComponentVisibility & Partial & { 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[];