Skip to content

Commit

Permalink
Merge pull request #64 from rosset-nocpes/improve-adding-synonims
Browse files Browse the repository at this point in the history
feat(list-param): add on enter
  • Loading branch information
olexh authored Jul 10, 2024
2 parents e325bce + 77d4e46 commit 849ce69
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions features/edit/edit-forms/params/list-param.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import * as React from 'react';
import { FC, useState } from 'react';
import { useFieldArray, useFormContext } from 'react-hook-form';
import MaterialSymbolsAddRounded from '~icons/material-symbols/add-rounded';
Expand Down Expand Up @@ -56,12 +55,25 @@ const ListParam: FC<Props> = ({ param, mode }) => {
value={newItem}
onChange={(e) => setNewItem(e.target.value)}
className="flex-1"
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
if (
newItem &&
newItem.length !== 0 &&
newItem.trim() !== ''
) {
append({ value: newItem });
setNewItem('');
}
}
}}
/>
<Button
disabled={
!newItem ||
newItem?.length === 0 ||
newItem === ''
newItem.trim() === ''
}
onClick={() => {
append({ value: newItem });
Expand Down

0 comments on commit 849ce69

Please sign in to comment.