Skip to content

Commit 7926af4

Browse files
author
Sergiu Miclea
committed
Focus switch inputs using TAB key
Switch inputs are now focusable and can be toggled using SPACE key.
1 parent da1251e commit 7926af4

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coriolis-web",
3-
"version": "1.4.5",
3+
"version": "1.4.6",
44
"license": "AGPL-3.0",
55
"scripts": {
66
"start": "npm run env:dev && node server.js --dev",

src/components/atoms/Switch/Switch.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1414

1515
// @flow
1616

17-
import React from 'react'
17+
import * as React from 'react'
1818
import { observer } from 'mobx-react'
1919
import styled from 'styled-components'
2020

@@ -170,6 +170,15 @@ class Switch extends React.Component<Props, State> {
170170
}
171171
}
172172

173+
handleKeyDown(evt: KeyboardEvent) {
174+
if (evt.which !== 32) {
175+
return
176+
}
177+
evt.preventDefault()
178+
179+
this.handleInputChange()
180+
}
181+
173182
renderInput() {
174183
return (
175184
<InputWrapper
@@ -179,6 +188,8 @@ class Switch extends React.Component<Props, State> {
179188
secondary={this.props.secondary}
180189
disabled={this.props.disabled}
181190
onClick={() => { this.handleInputChange() }}
191+
tabIndex={0}
192+
onKeyDown={evt => { this.handleKeyDown(evt) }}
182193
data-test-id={this.props['data-test-id'] || 'switch-input'}
183194
>
184195
<InputBackground

0 commit comments

Comments
 (0)