Royal-Navy / design-system

Build web applications that meet the Royal Navy service standards
https://storybook.design-system.navy.digital.mod.uk
Apache License 2.0
104 stars 32 forks source link

fix(Modal): Apply focus trap and expose imperative handle #3785

Closed m7kvqbe1 closed 1 month ago

m7kvqbe1 commented 1 month ago

Related issue

Closes #3757

Overview

Apply focus trap to Modal and Dialog components (use native Dialog).

Expose show and close methods via forwardedRef and imperative handle.

Reason

Modal and Dialog were not correctly applying a focus trap.

Work carried out

Screenshot

2024-05-07 09 24 21

Developer notes

When a dialog opens, the browser, by default, gives focus to the first element that can be focused within the dialog (always the close button if it is specified).

The Escape key can also now be used to close the modal.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog

netlify[bot] commented 1 month ago

Deploy Preview for storybook-navy-digital-mod-uk ready!

Name Link
Latest commit a0bc59724b5ab8809d20c48c25d794f5a7d10e8e
Latest deploy log https://app.netlify.com/sites/storybook-navy-digital-mod-uk/deploys/663b2adfd4744800074b525a
Deploy Preview https://deploy-preview-3785--storybook-navy-digital-mod-uk.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

m7kvqbe1 commented 1 month ago

Maybe some duplication between Modal and Dialog. Perhaps add a ticket to refactor

Dialog is just a wrapper around Modal really - it's being prescriptive about how Modal is composed.

It exposes an isDanger prop, onCancel and onConfirm handler.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
80.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud