Creating an Accessible Custom Checkbox

Robert DeLuca
Oct 4, 2017 · 4 min read
Naive checkbox example
<span id="checkbox" tabindex="0"></span>
A keyboard accessible checkbox
Update checkbox state for AT
Completed checkbox example

Introducing Checkbox.js

<label for="checkbox">Label</label>
<span id="checkbox">
<script>
let checkbox = document.getElementById('checkbox')
new Checkbox(checkbox);
</script>
<label>
Label
<span id="checkbox">
</label>
<script>
let checkbox = document.getElementById('checkbox')
new Checkbox(checkbox);
</script>
import React, { Component } from 'react';
import Checkbox from 'checkboxjs';
class ReactCheckbox extends Component {
componentDidMount() {
this.checkbox = new Checkbox(this.refs.checkbox, {
isChecked: this.props.isChecked,
label: this.props.label
});
}
render() {
return (
<span ref="checkbox" className="checkbox" id={this.props.id}></span>
);
}
}
export default ReactCheckbox;
<label for="checkbox">My Label</label>
<ReactCheckbox isChecked={true} id="checkbox" />

Robert DeLuca

Written by

• SDK + Support Engineer @percy_io 🦔 • I care a lot about accessibility. • Mustang enthusiast. • #ItsAllAboutTheU

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade