Skip to content

Instantly share code, notes, and snippets.

@connorrose
Created July 15, 2022 16:08
Show Gist options
  • Save connorrose/7ae8201200a8e61865d3da8b2da63920 to your computer and use it in GitHub Desktop.
Save connorrose/7ae8201200a8e61865d3da8b2da63920 to your computer and use it in GitHub Desktop.
A11y talk
// Bad Code
const No = () => (
<div>
<DivSoup />
<ForDinner />
</div>
);
const DivSoup = () => (
<div className="heading-1">
Some Headline!!
</div>
);
const ForDinner = (checkboxes) => (
<div>
Choices
{checkboxes.map((value, i) => (
<div
className="fancy-checkbox"
onClick={handler}
>
{`Option ${i}`}
</div>
))}
<div onClick={submit}>
Submit
</div>
</div>
);
// Semantic Refactor
const No = () => (
<>
<DivSoup />
<ForDinner />
</>
);
const DivSoup = () => (
<h1>
Some Headline!!
</h1>
);
const ForDinner = (checkboxes) => (
<form>
<fieldset>
<legend>
Choices
</legend>
{checkboxes.map(({ value, id }) => (
<input
type="checkbox"
id={id}
name={value}
onClick={handler}
/>
<label htmlFor={id}>
{value}
</label>
))}
</fieldset>
<button type="submit" onClick={submit}>
Submit
</button>
</form>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment