Skip to content

Commit

Permalink
Merge pull request #1445 from Adyen/fix/remove_fullWidthChar_conversion
Browse files Browse the repository at this point in the history
Remove composition handling & full width char conversion
  • Loading branch information
sponglord authored Jan 11, 2022
2 parents d5b01b8 + e71539d commit 626dacb
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions packages/lib/src/components/internal/FormFields/InputBase.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
import { h } from 'preact';
import { useState, useCallback, useRef } from 'preact/hooks';
import { useState, useCallback } from 'preact/hooks';
import classNames from 'classnames';
import { convertFullToHalf } from './utils';
import { ARIA_ERROR_SUFFIX } from '../../../core/Errors/constants';

export default function InputBase(props) {
const { autoCorrect, classNameModifiers, isInvalid, isValid, readonly = null, spellCheck, type, uniqueId, isCollatingErrors } = props;

const [handleChangeHasFired, setHandleChangeHasFired] = useState(false);
const isOnComposition = useRef<boolean>(false);

const handleInput = useCallback((event: h.JSX.TargetedCompositionEvent<HTMLInputElement>) => {
if (isOnComposition.current) return;

(event.target as HTMLInputElement).value = convertFullToHalf((event.target as HTMLInputElement).value);

props.onInput(event);
}, []);

const handleOnCompositionStart = useCallback(() => {
isOnComposition.current = true;
}, []);

const handleOnCompositionUpdate = useCallback((event: h.JSX.TargetedCompositionEvent<HTMLInputElement>) => {
props.onInput(event);
}, []);

const handleOnCompositionEnd = useCallback((event: h.JSX.TargetedCompositionEvent<HTMLInputElement>) => {
isOnComposition.current = false;
handleInput(event);
}, []);

const handleChange = useCallback((event: h.JSX.TargetedCompositionEvent<HTMLInputElement>) => {
setHandleChangeHasFired(true);
props?.onChange?.(event);
Expand Down Expand Up @@ -73,9 +54,6 @@ export default function InputBase(props) {
onChange={handleChange}
onBlur={handleBlur}
aria-invalid={isInvalid}
onCompositionStart={handleOnCompositionStart}
onCompositionUpdate={handleOnCompositionUpdate}
onCompositionEnd={handleOnCompositionEnd}
/>
);
}
Expand Down

0 comments on commit 626dacb

Please sign in to comment.