Skip to content

Commit 8b75d77

Browse files
committed
Allow PF3 switch to switch on space
1 parent 7d3d5b4 commit 8b75d77

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/pf3-component-mapper/src/form-fields/switch-field.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ class Switch extends React.Component {
5353
<label
5454
className={ `pf3-switch${disabled || isReadOnly ? ' disabled' : ''}${bsSize === 'mini' || bsSize === 'mn' ? ' mini' : ''}` }
5555
style={{ width: this.state.labelWidth + DIVIDER_SIZE + COMBINED_MARGIN }}
56+
tabIndex={ disabled || isReadOnly ? -1 : 0 }
57+
onKeyDown={ (e) => {
58+
const SPACEBAR_CODE = 32;
59+
if (e.keyCode === SPACEBAR_CODE) {
60+
e.preventDefault();
61+
props.onChange({ target: { checked: !props.checked }});
62+
}
63+
} }
5664
>
5765
<input type="checkbox" { ...props } disabled={ disabled || isReadOnly } />
5866
<span className={ `pf3-switch-slider${props.checked ? ' checked' : ''}` }>

0 commit comments

Comments
 (0)