Skip to content

Commit

Permalink
Remove enter key catcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jmainguytalend committed Jul 25, 2023
1 parent 726d717 commit eb481e3
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions packages/forms/src/UIForm/fields/Code/Code.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import {
lazy,
DetailedHTMLProps,
KeyboardEvent,
LabelHTMLAttributes,
Suspense,
useEffect,
useRef,
useState,
} from 'react';
import { lazy, DetailedHTMLProps, LabelHTMLAttributes, Suspense, useEffect, useState } from 'react';
import { IAceEditorProps } from 'react-ace';
import { useTranslation } from 'react-i18next';

import { isEventKey, codes } from 'keycode';

import assetsApi from '@talend/assets-api';

import { I18N_DOMAIN_FORMS } from '../../../constants';
Expand Down Expand Up @@ -89,7 +78,6 @@ export default function Code({
const descriptionId = generateDescriptionId(id);
const errorId = generateErrorId(id);
const instructionsId = generateId(id, 'instructions');
const containerRef = useRef<any>(null);
const [editor, setEditor] = useState<any>(null);

Check warning on line 81 in packages/forms/src/UIForm/fields/Code/Code.component.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/forms/src/UIForm/fields/Code/Code.component.tsx#L81

[@typescript-eslint/no-explicit-any] Unexpected any. Specify a different type.

useEffect(() => {
Expand All @@ -100,22 +88,6 @@ export default function Code({
}
}, [editor, instructionsId, descriptionId, errorId, id]);

function onKeyDown(event: KeyboardEvent) {
if (isEventKey(event.nativeEvent, codes.enter)) {
const now = Date.now();

if (containerRef.current.lastEsc && containerRef.current.lastEsc - now < 1000) {
containerRef.current.lastEsc = null;
containerRef.current.focus();
editor.textInput.getElement().setAttribute('tabindex', -1);
} else {
containerRef.current.lastEsc = now;
}
} else {
containerRef.current.lastEsc = null;
}
}

function onBlur() {
editor.textInput.getElement().removeAttribute('tabindex');
}
Expand All @@ -136,8 +108,6 @@ export default function Code({
<div // eslint-disable-line jsx-a11y/no-static-element-interactions
id={id && `${id}-editor-container`}
onBlur={onBlur}
onKeyDown={onKeyDown}
ref={containerRef}
tabIndex={-1}
>
<div id={instructionsId} className="sr-only">
Expand Down

0 comments on commit eb481e3

Please sign in to comment.