From 6f805d5984ce3f6b320eb4238bb0db626112bf4d Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Mon, 27 May 2019 16:23:53 +0300 Subject: [PATCH] Input fucus handling optimized --- src/navigation/Input/Input.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/navigation/Input/Input.js b/src/navigation/Input/Input.js index 68efc7c47..4842bcfc1 100644 --- a/src/navigation/Input/Input.js +++ b/src/navigation/Input/Input.js @@ -21,7 +21,7 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) => props.onKeyUp(event); } - if (!event.defaultPrevented && event.which === ENTER_KEY_CODE) { + if (!event.handled && event.which === ENTER_KEY_CODE) { if (BUTTON_INPUT_TYPES.includes(type)) { event.currentTarget.click(); } else if (TEXT_INPUT_TYPES.includes(type)) { @@ -36,19 +36,11 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) => props.onMouseDown(event); } - if (!event.defaultPrevented && BUTTON_INPUT_TYPES.includes(type)) { + if (!event.handled && BUTTON_INPUT_TYPES.includes(type)) { + event.preventDefault(); event.currentTarget.blur(); } }, [props.onMouseDown, type]); - const onMouseMove = React.useCallback((event) => { - if (typeof props.onMouseMove === 'function') { - props.onMouseMove(event); - } - - if (!event.defaultPrevented && BUTTON_INPUT_TYPES.includes(type)) { - event.currentTarget.blur(); - } - }, [props.onMouseMove, type]); const tagName = TAG_NAMES_FOR_TYPE[type]; const elementProps = { ...props, @@ -56,8 +48,7 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) => type: tagName === 'input' ? type : null, tabIndex: (isNaN(tabIndex) || tabIndex === null) ? (focusable ? 0 : -1) : tabIndex, onKeyUp, - onMouseDown, - onMouseMove + onMouseDown }; return React.createElement(tagName, elementProps, children); });