Skip to content

Commit

Permalink
feat(editableInput): adds keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
riyalohia authored and satyamyadav committed Jan 27, 2021
1 parent 66d132e commit 19c6327
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/components/molecules/editableInput/EditableInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ export const EditableInput = (props: EditableInputProps) => {
/>
);

const onKeyDown = (event: any) => {
if (document.activeElement === inputRef.current) {
switch (event.key) {
case 'Enter':
onSaveChanges();
break;
case 'Escape':
setDefaultComponent();
break;
}
}
};

const renderChildren = () => {
if (showComponent) {
return error && errorMessage && editing ? (
Expand Down Expand Up @@ -164,6 +177,7 @@ export const EditableInput = (props: EditableInputProps) => {
data-test="DesignSystem-EditableInput"
{...baseProps}
className={EditableInputClass}
onKeyDown={onKeyDown}
>
<Editable
onChange={onChangeHandler}
Expand Down

0 comments on commit 19c6327

Please sign in to comment.