Skip to content

Commit 992379c

Browse files
committed
Fix overlay not rendering on tour restart
1 parent 307dc4e commit 992379c

File tree

3 files changed

+148
-2
lines changed

3 files changed

+148
-2
lines changed

src/components/Step.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ export default class JoyrideStep extends React.Component<StepProps> {
184184
};
185185

186186
setPopper: FloaterProps['getPopper'] = (popper, type) => {
187-
const { action, step, store } = this.props;
187+
const { action, lifecycle, step, store } = this.props;
188188

189189
if (type === 'wrapper') {
190190
store.setPopper('beacon', popper);
191191
} else {
192192
store.setPopper('tooltip', popper);
193193
}
194194

195-
if (store.getPopper('beacon') && store.getPopper('tooltip')) {
195+
if (store.getPopper('beacon') && store.getPopper('tooltip') && lifecycle === LIFECYCLE.INIT) {
196196
store.update({
197197
action,
198198
lifecycle: LIFECYCLE.READY,

test/tours/__snapshots__/standard.spec.tsx.snap

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,130 @@ exports[`Joyride > Standard should render the content 1`] = `
106106
</div>
107107
`;
108108

109+
exports[`Joyride > Standard should restart the tour: beacon 1`] = `
110+
<button
111+
aria-label="Open the dialog"
112+
class="react-joyride__beacon"
113+
data-test-id="button-beacon"
114+
style="background-color: transparent; border: 0px; border-radius: 0; color: rgb(85, 85, 85); cursor: pointer; font-size: 16px; line-height: 1; padding: 8px; display: inline-block; height: 36px; position: relative; width: 36px; z-index: 100;"
115+
title="Open the dialog"
116+
type="button"
117+
>
118+
<span
119+
style="animation: joyride-beacon-inner 1.2s infinite ease-in-out; background-color: rgb(255, 0, 68); border-radius: 50%; display: block; height: 50%; left: 50%; opacity: 0.7; position: absolute; top: 50%; transform: translate(-50%, -50%); width: 50%;"
120+
/>
121+
<span
122+
style="animation: joyride-beacon-outer 1.2s infinite ease-in-out; background-color: rgba(255, 0, 68, 0.2); border: 2px solid #f04; border-radius: 50%; box-sizing: border-box; display: block; height: 100%; left: 0px; opacity: 0.9; position: absolute; top: 0px; transform-origin: center; width: 100%;"
123+
/>
124+
</button>
125+
`;
126+
127+
exports[`Joyride > Standard should restart the tour: tooltip 1`] = `
128+
<div
129+
class="__floater"
130+
style="display: inline-block; filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.3)); max-width: 100%; opacity: 1; position: absolute; transition: opacity 0.3s; visibility: visible; z-index: 200; padding: 16px 0px 0px; will-change: transform; top: 0px; left: 0px; transform: translate3d(NaNpx, NaNpx, 0);"
131+
x-placement="bottom"
132+
>
133+
<div
134+
class="__floater__body"
135+
>
136+
<div
137+
aria-label="The first step of many! Keep walking!"
138+
aria-modal="true"
139+
class="react-joyride__tooltip"
140+
role="alertdialog"
141+
style="background-color: rgb(255, 255, 255); border-radius: 5px; box-sizing: border-box; color: rgb(51, 51, 51); font-size: 16px; max-width: 100%; padding: 15px; position: relative; width: 380px;"
142+
>
143+
<div
144+
style="line-height: 1.4; text-align: center;"
145+
>
146+
<div
147+
style="padding: 20px 10px;"
148+
>
149+
The first step of many! Keep walking!
150+
</div>
151+
</div>
152+
<div
153+
style="align-items: center; display: flex; justify-content: flex-end; margin-top: 15px;"
154+
>
155+
<div
156+
style="flex: 1;"
157+
>
158+
<button
159+
aria-label="Skip"
160+
aria-live="off"
161+
data-action="skip"
162+
data-test-id="button-skip"
163+
role="button"
164+
style="background-color: transparent; border: 0px; border-radius: 0; color: rgb(51, 51, 51); cursor: pointer; font-size: 14px; line-height: 1; padding: 8px;"
165+
title="Skip"
166+
type="button"
167+
>
168+
Skip
169+
</button>
170+
</div>
171+
<button
172+
aria-label="Next"
173+
data-action="primary"
174+
data-test-id="button-primary"
175+
role="button"
176+
style="background-color: rgb(255, 0, 68); border: 0px; border-radius: 4px; color: rgb(255, 255, 255); cursor: pointer; font-size: 16px; line-height: 1; padding: 8px;"
177+
title="Next"
178+
type="button"
179+
>
180+
Next
181+
</button>
182+
</div>
183+
<button
184+
aria-label="Close"
185+
data-action="close"
186+
data-test-id="button-close"
187+
role="button"
188+
style="background-color: transparent; border: 0px; border-radius: 0; cursor: pointer; font-size: 16px; line-height: 1; padding: 15px; position: absolute; right: 0px; top: 0px;"
189+
title="Close"
190+
type="button"
191+
>
192+
<svg
193+
height="14px"
194+
preserveAspectRatio="xMidYMid"
195+
version="1.1"
196+
viewBox="0 0 18 18"
197+
width="14px"
198+
xmlns="http://www.w3.org/2000/svg"
199+
>
200+
<g>
201+
<path
202+
d="M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z"
203+
fill="#333"
204+
/>
205+
</g>
206+
</svg>
207+
</button>
208+
</div>
209+
<div
210+
class="__floater__arrow"
211+
style="pointer-events: none; position: absolute; width: 100%; left: 0px; right: 0px; top: 0px; height: 16px;"
212+
>
213+
<span
214+
style="display: inline-flex; position: absolute; margin-left: 8px; margin-right: 8px;"
215+
>
216+
<svg
217+
height="16"
218+
version="1.1"
219+
width="32"
220+
xmlns="http://www.w3.org/2000/svg"
221+
>
222+
<polygon
223+
fill="#fff"
224+
points="32,16 16,0 0,16"
225+
/>
226+
</svg>
227+
</span>
228+
</div>
229+
</div>
230+
</div>
231+
`;
232+
109233
exports[`Joyride > Standard should start the tour 1`] = `
110234
<div
111235
id="react-joyride-step-0"

test/tours/standard.spec.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,26 @@ describe('Joyride > Standard', () => {
430430

431431
expect(mockGetPopper).toHaveBeenCalledTimes(13);
432432
});
433+
434+
it('should restart the tour', async () => {
435+
mockCallback.mockClear();
436+
mockGetPopper.mockClear();
437+
438+
fireEvent.click(screen.getByTestId('start'));
439+
440+
await waitFor(() => {
441+
expect(mockCallback).toHaveBeenCalledTimes(3);
442+
});
443+
444+
expect(screen.getByTestId('button-beacon')).toMatchSnapshot('beacon');
445+
446+
fireEvent.click(screen.getByTestId('button-beacon'));
447+
448+
await waitFor(() => {
449+
expect(mockCallback).toHaveBeenCalledTimes(4);
450+
});
451+
452+
expect(screen.getById('react-joyride-step-0').querySelector('div')).toMatchSnapshot('tooltip');
453+
expect(screen.getByTestId('overlay')).toBeInTheDocument();
454+
});
433455
});

0 commit comments

Comments
 (0)