Saltar al contenido principal

Worked Example: Refactor a Div Button Without Losing Behavior

Refactor a clickable generic element into a semantic button with correct loading and disabled behavior.

web-accessibility-development5 min read

The design-system PrimaryButton renders a div with click and key handlers. Keyboard and form behavior are inconsistent. Replace simulated semantics with native semantics, then add only the state the platform cannot know. Adding role="button" and tabIndex to a div creates only part of the contract. It does not automatically add correct Space behavior, disabled behavior, form submission, or durable focus semantics. Step 1 Change the rendered element from div to button and pass through type, disabled, and onClick/onSubmit behavior. The native element immediately supplies role, focusability, activation keys, and disabled semantics. This deletes code instead of adding a new accessibility…

Read the full lesson

Sign up free: one personalized lesson every day, matched to your role and goals.

← Back to library

Contáctanos