feat: modified DoubleTextInput to split First and Last name accordingly (#4598)
* feat: modified DoubleTextInput to split First and Last name accordingly * Fix Linter --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -66,6 +66,10 @@ export const FullNameFieldInput = ({
|
|||||||
setDraftValue(convertToFullName(newDoubleText));
|
setDraftValue(convertToFullName(newDoubleText));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePaste = (newDoubleText: FieldDoubleText) => {
|
||||||
|
setDraftValue(convertToFullName(newDoubleText));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FieldInputOverlay>
|
<FieldInputOverlay>
|
||||||
<DoubleTextInput
|
<DoubleTextInput
|
||||||
@ -82,6 +86,7 @@ export const FullNameFieldInput = ({
|
|||||||
onEscape={handleEscape}
|
onEscape={handleEscape}
|
||||||
onShiftTab={handleShiftTab}
|
onShiftTab={handleShiftTab}
|
||||||
onTab={handleTab}
|
onTab={handleTab}
|
||||||
|
onPaste={handlePaste}
|
||||||
hotkeyScope={hotkeyScope}
|
hotkeyScope={hotkeyScope}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,4 +1,10 @@
|
|||||||
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
import {
|
||||||
|
ChangeEvent,
|
||||||
|
ClipboardEvent,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { Key } from 'ts-key-enum';
|
import { Key } from 'ts-key-enum';
|
||||||
|
|
||||||
@ -39,6 +45,7 @@ type DoubleTextInputProps = {
|
|||||||
newDoubleTextValue: FieldDoubleText,
|
newDoubleTextValue: FieldDoubleText,
|
||||||
) => void;
|
) => void;
|
||||||
onChange?: (newDoubleTextValue: FieldDoubleText) => void;
|
onChange?: (newDoubleTextValue: FieldDoubleText) => void;
|
||||||
|
onPaste?: (newDoubleTextValue: FieldDoubleText) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DoubleTextInput = ({
|
export const DoubleTextInput = ({
|
||||||
@ -53,6 +60,7 @@ export const DoubleTextInput = ({
|
|||||||
onShiftTab,
|
onShiftTab,
|
||||||
onTab,
|
onTab,
|
||||||
onChange,
|
onChange,
|
||||||
|
onPaste,
|
||||||
}: DoubleTextInputProps) => {
|
}: DoubleTextInputProps) => {
|
||||||
const [firstInternalValue, setFirstInternalValue] = useState(firstValue);
|
const [firstInternalValue, setFirstInternalValue] = useState(firstValue);
|
||||||
const [secondInternalValue, setSecondInternalValue] = useState(secondValue);
|
const [secondInternalValue, setSecondInternalValue] = useState(secondValue);
|
||||||
@ -150,6 +158,20 @@ export const DoubleTextInput = ({
|
|||||||
enabled: isDefined(onClickOutside),
|
enabled: isDefined(onClickOutside),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleOnPaste = (event: ClipboardEvent<HTMLInputElement>) => {
|
||||||
|
if (firstInternalValue.length > 0 || secondInternalValue.length > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const name = event.clipboardData.getData('Text');
|
||||||
|
|
||||||
|
const splittedName = name.split(' ');
|
||||||
|
|
||||||
|
onPaste?.({ firstValue: splittedName[0], secondValue: splittedName[1] });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledContainer ref={containerRef}>
|
<StyledContainer ref={containerRef}>
|
||||||
<StyledInput
|
<StyledInput
|
||||||
@ -162,6 +184,9 @@ export const DoubleTextInput = ({
|
|||||||
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
||||||
handleChange(event.target.value, secondInternalValue);
|
handleChange(event.target.value, secondInternalValue);
|
||||||
}}
|
}}
|
||||||
|
onPaste={(event: ClipboardEvent<HTMLInputElement>) =>
|
||||||
|
handleOnPaste(event)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<StyledInput
|
<StyledInput
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
|
|||||||
Reference in New Issue
Block a user