1
0
mirror of synced 2024-11-12 01:00:46 +01:00

Add keyboard control to the slider control.

This commit is contained in:
Jennifer Taylor 2022-10-13 02:23:57 +00:00
parent edc9150bc5
commit d6cddebe88

View File

@ -1,6 +1,30 @@
/** @jsx React.DOM */
var Slider = createReactClass({
key: function(e) {
if (e.keyCode == 32) {
// Toggle on space.
if (this.props.onChange) {
this.props.onChange(!this.props.value);
}
} else if (e.keyCode == 39) {
// Slide with cursor keys.
if (this.props.onChange && this.props.value) {
this.props.onChange(!this.props.value);
}
} else if (e.keyCode == 37) {
// Slide with cursor keys.
if (this.props.onChange && !this.props.value) {
this.props.onChange(!this.props.value);
}
} else {
// Don't handle, so don't hit the default prevent below.
return;
}
e.preventDefault();
e.stopPropagation();
},
render: function() {
return (
<div
@ -12,6 +36,8 @@ var Slider = createReactClass({
this.props.onChange(!this.props.value);
}
}.bind(this)}
tabindex={0}
onKeyDown={this.key}
>{ this.props.value ?
<>
<span className="ball on"></span>