using nativeEvent to mark event as handled

This commit is contained in:
NikolaBorislavovHristov 2019-06-04 10:57:02 +03:00
parent 45c0edbde9
commit ca4e83148e
2 changed files with 4 additions and 4 deletions

View file

@ -21,7 +21,7 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) =>
props.onKeyUp(event); props.onKeyUp(event);
} }
if (!event.handled && event.keyCode === ENTER_KEY_CODE) { if (!event.nativeEvent.handled && event.keyCode === 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,7 +36,7 @@ const Input = React.forwardRef(({ type, tabIndex, children, ...props }, ref) =>
props.onMouseDown(event); props.onMouseDown(event);
} }
if (!event.handled && BUTTON_INPUT_TYPES.includes(type)) { if (!event.nativeEvent.handled && BUTTON_INPUT_TYPES.includes(type)) {
event.preventDefault(); event.preventDefault();
if (document.activeElement instanceof HTMLElement) { if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur(); document.activeElement.blur();

View file

@ -7,12 +7,12 @@ const styles = require('./styles');
const ConsentCheckbox = React.forwardRef(({ className, checked, label, link, href, toggle }, ref) => { const ConsentCheckbox = React.forwardRef(({ className, checked, label, link, href, toggle }, ref) => {
const checkboxOnClick = React.useCallback((event) => { const checkboxOnClick = React.useCallback((event) => {
if (!event.handled && typeof toggle === 'function') { if (!event.nativeEvent.handled && typeof toggle === 'function') {
toggle(event); toggle(event);
} }
}, [toggle]); }, [toggle]);
const linkOnClick = React.useCallback((event) => { const linkOnClick = React.useCallback((event) => {
event.handled = true; event.nativeEvent.handled = true;
}, []); }, []);
return ( return (
<Checkbox ref={ref} className={classnames(className, styles['consent-checkbox-container'])} checked={checked} onClick={checkboxOnClick}> <Checkbox ref={ref} className={classnames(className, styles['consent-checkbox-container'])} checked={checked} onClick={checkboxOnClick}>