mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 03:22:11 +00:00
Input fucus handling optimized
This commit is contained in:
parent
ef1fd33bce
commit
6f805d5984
1 changed files with 4 additions and 13 deletions
|
|
@ -21,7 +21,7 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) =>
|
||||||
props.onKeyUp(event);
|
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)) {
|
if (BUTTON_INPUT_TYPES.includes(type)) {
|
||||||
event.currentTarget.click();
|
event.currentTarget.click();
|
||||||
} else if (TEXT_INPUT_TYPES.includes(type)) {
|
} else if (TEXT_INPUT_TYPES.includes(type)) {
|
||||||
|
|
@ -36,19 +36,11 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) =>
|
||||||
props.onMouseDown(event);
|
props.onMouseDown(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.defaultPrevented && BUTTON_INPUT_TYPES.includes(type)) {
|
if (!event.handled && BUTTON_INPUT_TYPES.includes(type)) {
|
||||||
|
event.preventDefault();
|
||||||
event.currentTarget.blur();
|
event.currentTarget.blur();
|
||||||
}
|
}
|
||||||
}, [props.onMouseDown, type]);
|
}, [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 tagName = TAG_NAMES_FOR_TYPE[type];
|
||||||
const elementProps = {
|
const elementProps = {
|
||||||
...props,
|
...props,
|
||||||
|
|
@ -56,8 +48,7 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) =>
|
||||||
type: tagName === 'input' ? type : null,
|
type: tagName === 'input' ? type : null,
|
||||||
tabIndex: (isNaN(tabIndex) || tabIndex === null) ? (focusable ? 0 : -1) : tabIndex,
|
tabIndex: (isNaN(tabIndex) || tabIndex === null) ? (focusable ? 0 : -1) : tabIndex,
|
||||||
onKeyUp,
|
onKeyUp,
|
||||||
onMouseDown,
|
onMouseDown
|
||||||
onMouseMove
|
|
||||||
};
|
};
|
||||||
return React.createElement(tagName, elementProps, children);
|
return React.createElement(tagName, elementProps, children);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue