Repository navigation
fix(ui): make the SDK dialog keyboard and screen-reader accessible - #1944
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The dialog the SDK injects when the wallet popup is blocked could only be dismissed with a pointer, and assistive technology had no way to tell it was a dialog: - The header close control was a clickable <div> wrapping an <img> with no alt text, so it was not focusable, not keyboard operable, and had no accessible name. - The dialog had no role, no aria-modal, and no accessible name or description, so screen readers announced it as loose text. - Opening it left focus on the page underneath, Tab walked out of it into content hidden behind the backdrop, and Escape did nothing. DialogInstance now: - renders with role="dialog" and aria-modal="true", labelled by its title and described by its message (ids are prefixed so they cannot collide with a host page's own Preact useId values); - renders the close control as <button type="button" aria-label="Close"> with a decorative image, and marks action buttons type="button"; - moves focus to the first action (or the close button when there are none), keeps Tab and Shift+Tab inside the dialog, pulls focus back in if it has left, and closes on Escape through the same handleClose path as the close button, unless the page already handled the key; - restores focus to the element the page had focused once it unmounts. The SCSS resets the native button padding, border and background so the close button looks the same as before. The drag-to-dismiss gesture still finds the close control by its class. The "renders hidden initially" test asserted setTimeout was called exactly once. Moving focus makes jsdom queue its own selectionchange timer, so the test now asserts the 1 ms reveal timer is scheduled instead of counting jsdom internals. Fixes coinbase#1909
Collaborator
🟡 Heimdall Review Status
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1909
The WalletLink snackbar and redirect dialog named in #1909 were removed in the v5 SDK, but the one piece of UI the SDK still injects, the "{app} wants to continue in Coinbase Wallet" dialog shown when the popup is blocked, has the same problems:
<div>around an<img>with noalt. You can't focus it or operate it from the keyboard, and it has no accessible name.role, noaria-modal, and no accessible name or description.This PR changes
DialogInstanceso that it:role="dialog"andaria-modal="true", usingaria-labelledbyfor the title andaria-describedbyfor the message. The ids are prefixed so they can't collide with a host page's own PreactuseIdvalues.<button type="button" aria-label="Close">with a decorative icon (alt=""). Action buttons gettype="button".handleClosepath, so the request is rejected and telemetry is logged exactly as when Close is clicked. Escape is ignored if the page already calledpreventDefault()on it.Dialog.scssresets the native button padding, border and background, so the close button looks the same as before. Drag-to-dismiss still finds the close control by its class.How did you test your changes?
Dialog.test.tsxfor: dialog role, name and description; the labelled Close button; Escape, including the case where the page already handled it; initial focus with and without actions; Tab and Shift+Tab wrapping; pulling focus back in; and focus restore on unmount. Without the component change, the 8 positive tests fail.renders hidden initiallyused to assert thatsetTimeoutwas called exactly once. Moving focus makes jsdom queue its ownselectionchangetimer, so the test now checks that the 1 ms reveal timer is scheduled.yarn test --run(530 tests),tsc --noEmit,biome lintand theformat:checkcommand all pass.dist/coinbase-wallet-sdk.min.jsin headless Chromium withwindow.openstubbed to returnnull, then calledeth_requestAccounts. The dialog was exposed as a modal named "E2E wants to continue in Coinbase Wallet" and described by its message, and Close was aBUTTON. Focus started on "Try again", and Tab and Shift+Tab wrapped between Close and Cancel. Escape removed the dialog, rejected the request with "Popup window was blocked", and returned focus to the page's Connect button.