Skip to content

Commit

Permalink
feat(list-param): add on enter
Browse files Browse the repository at this point in the history
  • Loading branch information
rosset-nocpes committed Jul 10, 2024
1 parent e325bce commit 77d4e46
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 77d4e46

Please sign in to comment.