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

@@ -44045,6 +44045,7 @@ exports[`Storyshots Forms|Checkbox Default 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"
@@ -44068,6 +44069,7 @@ exports[`Storyshots Forms|Checkbox Default 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"
@@ -44091,6 +44093,7 @@ exports[`Storyshots Forms|Checkbox Default 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"
@@ -44121,6 +44124,7 @@ exports[`Storyshots Forms|Checkbox Disabled 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"
@@ -44152,6 +44156,7 @@ exports[`Storyshots Forms|Checkbox With HelpText 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"
@@ -44183,6 +44188,7 @@ exports[`Storyshots Forms|Checkbox With HelpText 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"
@@ -47567,6 +47573,7 @@ exports[`Storyshots Modal|Modal With long tooltips 1`] = `
<div <div
className="control" className="control"
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
> >
<label <label
className="checkbox" className="checkbox"

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