Rebuilding a native <button> from scratch: a lesson in why you shouldn't
Original source
If you want to create a button from scratch, you must first create the universe
Hacker News →Web accessibility advice usually starts with two rules: don’t use ARIA if you can avoid it, and always prefer a native HTML element over a hand-rolled one. This piece justifies that advice by walking through what it actually takes to reconstruct something as mundane as a button. Native elements ship with a long list of built-in guarantees, and a custom replacement has to reproduce every one to satisfy WCAG 2.2 — a proper button role and accessible label, keyboard focusability, activation via mouse, touch, stylus, Space and Enter, form participation (type, name, value, validation, reset/submit), disabled and other states, plus hooks for newer platform features like the Popover and Invoker Commands APIs.
The author builds a
The takeaway is that even after all this scaffolding, the reimplementation only reaches parity with what
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.