Raccourci clavier 'Entrer' pour valider les questions à choix aussi

pull/151/head
mama 2018-01-18 19:15:29 +01:00
parent e7f2f658ce
commit 64fd6b84bf
2 changed files with 13 additions and 3 deletions

View File

@ -40,9 +40,6 @@ export default class Input extends Component {
? { border: '2px dashed #ddd' }
: { border: `1px solid ${themeColours.textColourOnWhite}` }
}
onKeyDown={({ key }) =>
key == 'Enter' && (submitDisabled ? input.onBlur() : submit())
}
/>
{suffixed && (
<label

View File

@ -7,6 +7,19 @@ export default class SendButton extends Component {
let { disabled, submit } = this.props
return () => (!disabled ? submit() : null)
}
componentDidMount() {
// removeEventListener will need the exact same function instance
this.boundHandleKeyDown = this.handleKeyDown.bind(this)
window.addEventListener('keydown', this.boundHandleKeyDown)
}
componentWillUnmount() {
window.removeEventListener('keydown', this.boundHandleKeyDown)
}
handleKeyDown({ key }) {
if (key !== 'Enter') return
this.getAction()()
}
render() {
let { disabled, themeColours, hover } = this.props
return (