I've got a custom checkbox that doesn't use an input at all, since styling it is more pain than it's worth. It relies on tabIndex={0}, role="checkbox" and aria-checked to be focusable and accessible.
To be checkable and uncheckable via keyboard events, the following is written (ReactJS):
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
setChecked((prev) => !prev);
}
}}
Is it enough to simply react to enter and space, or screen readers expect something extra?