TextInput submit onKeyDown

This commit is contained in:
NikolaBorislavovHristov 2019-11-19 11:36:54 +02:00
parent 7e83f9b071
commit d9f5bec1f5

View file

@ -3,15 +3,15 @@ const classnames = require('classnames');
const styles = require('./styles');
const TextInput = React.forwardRef((props, ref) => {
const onKeyUp = React.useCallback((event) => {
if (typeof props.onKeyUp === 'function') {
props.onKeyUp(event);
const onKeyDown = React.useCallback((event) => {
if (typeof props.onKeyDown === 'function') {
props.onKeyDown(event);
}
if (event.key === 'Enter' && !event.nativeEvent.submitPrevented && typeof props.onSubmit === 'function') {
props.onSubmit(event);
}
}, [props.onKeyUp, props.onSubmit]);
}, [props.onKeyDown, props.onSubmit]);
return (
<input
size={1}
@ -23,7 +23,7 @@ const TextInput = React.forwardRef((props, ref) => {
{...props}
ref={ref}
className={classnames(props.className, styles['text-input'], { 'disabled': props.disabled })}
onKeyUp={onKeyUp}
onKeyDown={onKeyDown}
/>
);
});