Make checkboxes changeable with key press

This commit is contained in:
René Pfeuffer
2020-09-01 13:55:53 +02:00
parent 6ba090b82e
commit 36b8f667bf
2 changed files with 15 additions and 1 deletions

View File

@@ -45,6 +45,13 @@ export default class Checkbox extends React.Component<Props> {
}
};
onKeyDown = (event: React.KeyboardEvent) => {
const SPACE = 32;
if (event.keyCode === SPACE) {
this.onCheckboxChange();
}
};
renderHelp = () => {
const { title, helpText } = this.props;
if (helpText && !title) {
@@ -64,7 +71,7 @@ export default class Checkbox extends React.Component<Props> {
return (
<div className="field">
{this.renderLabelWithHelp()}
<div className="control" onClick={this.onCheckboxChange}>
<div className="control" onClick={this.onCheckboxChange} onKeyDown={this.onKeyDown}>
{/*
we have to ignore the next line,
because jsx label does not the custom disabled attribute