Your modal already knows how to trap focus
On this page
Here's what nobody tells you about your design system's modal: the browser wrote most of it already.
Open the source of almost any <ds-modal> and you'll find a focus trap, something that marks the rest of the page inert, an Esc listener, a scroll lock, and code that puts focus back on the button that opened it. Now open a plain <dialog> and call showModal(). Everything but the scroll lock happens with no code of your own, and the scroll lock is one line of CSS. (Strictly, the browser doesn't trap Tab. It makes everything outside the dialog inert, so focus can reach the browser's own toolbar but never the page behind.) As of last December, you don't even need the showModal() call. A button with command="show-modal" does it.
The person who wrote <ds-modal> probably knows this. The person using it probably doesn't.
The companion guide, Native first: twelve UI patterns HTML and CSS already handle, has a working demo, the spec history and live browser support for each one. This post is the why.
I'm not here to take your components away #
I've spent more than a decade on the other side of this. I led Spectrum Web Components at Adobe and started PatternFly Elements at Red Hat. There are plenty of good reasons to wrap a pattern in a component:
- One API across a big team, so forty engineers don't make forty accordions.
- Theming and tokens that stay consistent without anyone copying CSS around.
- Framework bindings for teams who live in React, Angular or Vue.
- Analytics and instrumentation hooks that product teams actually need.
- Older browsers you're contractually stuck supporting.
None of that goes away because the platform got better. The best components were already doing the right thing. Spectrum's <sp-switch> is, by its own docs, an <input type="checkbox"> with role="switch", which is exactly what I'd write by hand. Red Hat's <rh-dialog> is a native <dialog> underneath.
The trouble starts after the wrapping is done, with everyone downstream of it.
Builders learn the platform. Users learn the API. #
Building a component library forces you to learn the platform in uncomfortable detail. You find out that <summary> is exposed as a button, that a modal dialog lives in the top layer, that aria-expanded on a popover invoker is set in the accessibility tree and not the DOM. You learn it because the bugs make you.
The people using the library learn something else: the component's props. isOpen, onOpenChange, allowMultiple, trapFocus. Those names are the whole mental model, and they're fine, right up until one of these happens:
- The component breaks, and the fix lives in a layer they've never looked at.
- The team changes frameworks, and nothing they knew about
<Modal isOpen>transfers. - They need something the API didn't anticipate, and the only option is a feature request.
- They build the next thing from scratch and rebuild the focus trap, because they've never seen
<dialog>do it.
The last one worries me most. Knowledge of what the browser does is concentrating in the small group of people who maintain libraries, and the much larger group building with them is losing touch with the HTML underneath. Every library is reasonable on its own. Taken together, they've made the platform's own behavior invisible to most of the people relying on it.
The excuses ran out somewhere around 2024 #
For a long time, the honest answer to "why is this a component?" was "because the platform couldn't do it." That answer has been expiring one feature at a time:
| Pattern | What used to need script | What closed the gap | Baseline |
|---|---|---|---|
| Validation states | "touched" and "dirty" tracking | :user-invalid, :user-valid | November 2023 |
| Flyouts, toggletips | top layer, light dismiss | popover | 2024–2025 |
| Exclusive accordion | closing the other panels | <details name> | September 2024 |
| Animated panels | measuring content height | ::details-content | September 2025 |
| Modal dialog | calling showModal() | invoker commands | December 2025 |
| Anchored panels | Floating UI, Popper | anchor positioning | January 2026, core properties |
| Auto-growing textarea | resize listeners | field-sizing: content | June 2026 |
And some patterns never had a good excuse. <progress>, <meter>, position: sticky, breadcrumbs as an <ol> with aria-current, a card whose whole surface is a link: all of these have worked natively for years, and they still get shipped as components that re-add the semantics with ARIA.
Keep your library. Just make sure each component exists for one of the good reasons above. "Nobody on the team knew the browser did this" isn't one of them.
What I'd ask instead #
If you build components #
- Wrap the native element instead of reimplementing it. Render the
<dialog>, the<details>, the<input type="checkbox">. Let the browser own focus, state and semantics. Add only what's actually missing. - Say what the platform is doing in your docs. One line like "this renders a native
<dialog>, so focus trapping and Esc come from the browser" teaches more than a props table. - Keep the escape hatch obvious. If someone can drop down to the HTML, they'll learn it. If they can't, they won't.
If you use components #
- Read the HTML it renders. Open devtools, look at the accessibility tree. (That's how I learned front-end in the first place: view-source, and a lot of it.)
- Build the native version once. Not for production, just to know. The guide has twelve to start from, and none of them has a line of JavaScript.
- Ask why it's a component. Sometimes the answer will be good. Sometimes the answer will be 2019.
Dos and don'ts #
| Do | Don't |
|---|---|
| Start from the element that already has the behavior | Start from a <div> and add ARIA until it passes an audit |
| Use JavaScript for what HTML can't do yet | Use JavaScript to recreate what HTML already does |
| Treat the component as a convenience layer | Treat the component as the only way the pattern exists |
Learn command, popover, name, field-sizing | Assume the browser can't do it because your library doesn't |