Repository navigation
Commit 2651fd0
fix(rewards): keep referral dialogs above destination modals (#47682)
## **Description**
Referral invitations can compete with destination dialogs for focus and
dismissal events. Keep Terms of Use first, then show the invite and
activation sheets above ordinary destination dialogs using a small
native `<dialog>` wrapper. Other dialogs remain mounted underneath.
The wrapper owns the shared sheet container and preserves MMDS styling,
isolates Escape and mouse events, and only dismisses backdrop gestures
that also started on the backdrop. The documented `data-no-focus-lock`
marker prevents background focus locks with `autoFocus={false}` from
blurring native-dialog inputs.
Two narrow integration guards cover the existing exceptions: Token
Insights leaves clicks in another native dialog untouched, and the
global drawer waits through native-dialog handoffs. The header also
holds drawer requests while Terms is displayed. Background menus may
close during referral interactions.
Both referral dialogs use visible titles as accessible names, with an
existing localized label as the invite-title fallback when server copy
is missing. Native-dialog lifecycle shims live in setup shared by unit
and integration tests.
**Scope: six production files and six test/setup files; 83 net
production lines.** Stacked on #47665. MMDS does not expose priority
focus handling, so [native
modality](https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element)
is an intentional local adapter. No dependency changes.
Validation: **71 unit tests across seven suites and 101 integration
tests across 26 suites passed** (one existing integration test remains
skipped). Changed-file lint, full TypeScript checking, and circular
dependency checks passed. The invite's accessible-name assertion failed
before the naming fix and passed afterward, including the
missing-server-copy fallback. The previously failing notification
integration suites pass with the shared native-dialog setup.
Earlier Chromium and Firefox harness checks covered focus, backdrop
gestures, Escape, queued opening, cancellation, and invite-to-activation
handoff. Full Extension flow verification remains pending.
## **Changelog**
CHANGELOG entry: Fixed referral dialogs losing focus behind destination
dialogs while preserving Terms of Use priority.
## **Related issues**
Related: #47665
## **Manual testing steps**
1. With an eligible wallet, enable the referral feature and leave
Terms-of-Use acceptance pending. Open a supported deep link to Home with
one valid `ref` code. Verify Terms appears first, with the invite
waiting until acceptance. A drawer requested through `drawerOpen=true`
must also wait.
2. Open a referral over a destination dialog, including Token Insights
and a dialog that appears after data loads. Edit the code and use Tab to
verify focus stays in the referral. Selecting text and releasing over
the backdrop must keep the invite open.
3. Press Escape or click the backdrop. Verify only the referral closes
and the destination dialog remains open. Background menus are allowed to
close.
4. Accept an invite. Verify the activation sheet stays above the
destination dialog and focuses its primary action. A queued global
drawer must wait until the activation sheet closes, then receive focus.
5. Repeat the deferred install/onboarding path and check the behavior in
both Chrome and Firefox.
## **Screenshots/Recordings**
ToS working:
[terms-before-referral.webm](https://github.com/user-attachments/assets/78e9ac45-e4c3-4b15-88d1-0b1b4a3f9b87)
Referral modal stays on top of others:
[697762543-7e7eabbb-ce32-4be9-9842-ad9c89616865.webm](https://github.com/user-attachments/assets/0ea07a3a-c7e3-437f-b1d1-f74ea7b95f28)
<!--
Full Extension flow verification pending. Component behavior was checked
in isolated Chromium and Firefox harnesses.
### **Before**
### **After**
-->
## **Pre-merge author checklist**
- [x] I've followed MetaMask Contributor Docs and MetaMask Extension
Coding Standards.
- [x] I've completed the PR template to the best of my ability.
- [x] I've included tests where applicable.
- [x] I've documented the native-dialog rationale and focus-lock
interaction.
- [x] I've applied the right labels on the PR.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR.
- [ ] I confirm that this PR addresses the described behavior and
includes the necessary testing evidence.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches overlay stacking, focus, and dismissal across referral flows,
global drawer, and Token Insights—behavior-sensitive UI with moderate
integration surface but well-tested.
>
> **Overview**
> Introduces a shared **`ReferralDialog`** native `<dialog>` wrapper so
money-referral invite and activation sheets sit above ordinary MMDS
modals without losing focus or leaking Escape/backdrop events to the UI
underneath. Invite and activated flows keep MMDS header/body/footer
inside the wrapper, add **`aria-labelledby`** headings, and fall back
the invite title to the localized referral-code label when server copy
is missing.
>
> **Global menu drawer** now defers `showModal()` until no other open
native dialog remains (and cancels deferred opens on unmount), marks
**`data-no-focus-lock`**, and the app header withholds drawer open
requests on home while **Terms of Use** is up. **Token Insights**
ignores document outside-click handling when the press targets another
open native dialog.
>
> Jest gets shared **`HTMLDialogElement.showModal`/`close`** shims; unit
tests cover dialog focus/isolation, drawer queuing, Terms gating, and
referral a11y assertions.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
94bf01c. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Baptiste Marchand <75846779+baptiste-marchand@users.noreply.github.com>1 parent 6870129 commit 2651fd0
12 files changed
Lines changed: 465 additions & 205 deletions
File tree
- test/helpers
- ui
- components
- app/rewards/money-referral
- multichain
- app-header
- pages/bridge/token-insights-modal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
6 | 19 | | |
7 | 20 | | |
8 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
| |||
256 | 260 | | |
257 | 261 | | |
258 | 262 | | |
259 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | | - | |
15 | | - | |
16 | 13 | | |
17 | 14 | | |
18 | | - | |
19 | 15 | | |
| 16 | + | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
| |||
48 | 45 | | |
49 | 46 | | |
50 | 47 | | |
| 48 | + | |
51 | 49 | | |
52 | 50 | | |
53 | 51 | | |
| |||
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
60 | | - | |
61 | | - | |
| 58 | + | |
| 59 | + | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
| |||
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
75 | | - | |
| 73 | + | |
76 | 74 | | |
77 | 75 | | |
78 | 76 | | |
| |||
98 | 96 | | |
99 | 97 | | |
100 | 98 | | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
| |||
319 | 318 | | |
320 | 319 | | |
321 | 320 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
328 | 334 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
389 | 344 | | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
400 | 352 | | |
401 | | - | |
402 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
403 | 380 | | |
404 | | - | |
405 | | - | |
406 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
407 | 409 | | |
408 | 410 | | |
409 | 411 | | |
| |||
0 commit comments