Tech
You built your modal with a `<div>` and a focus trap library. The native `<dialog>` does all of that.
Building a modal from scratch means writing the same boilerplate every time: a <div> with role="dialog" , an aria-modal attribute, a tabindex="-1" to steal focus, a keydown listener to catch Escape, a focus-trap library to keep Tab cycling inside the dialog, and a click listener on the backdrop overlay you rendered yourself. It works, but you're doing the browser's job.
The <dialog> element exists to take that job back.
The baseline API
<dialo...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to