Skip to content

Commit

Permalink
add new caller when caller still have empty list, just focus on the e…
Browse files Browse the repository at this point in the history
…mpty one (#7767)

Co-authored-by: Lu Han <32191031+luhan2017@users.noreply.github.com>
  • Loading branch information
VanyLaw and luhan2017 committed May 27, 2021
1 parent 095fccc commit d607e81
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const BorderlessTextField: React.FC<BorderlessTextFieldProps> = (props) => {
if (componentFocusOnMount) {
fieldRef.current?.focus();
}
}, []);
}, [componentFocusOnMount]);
return (
<TextField
borderless={borderless}
Expand All @@ -71,9 +71,15 @@ export const AddCallers: React.FC<ContentProps> = ({ projectId, callers, onUpdat
};
const handleAddNewAllowedCallerClick = () => {
const currentCallers = callers.slice();
currentCallers?.push('');
onUpdateCallers(currentCallers);
setFocusCallerIndex(currentCallers.length - 1);
const index = currentCallers.findIndex((content) => content === '');
if (index < 0) {
currentCallers?.push('');
onUpdateCallers(currentCallers);
setFocusCallerIndex(currentCallers.length - 1);
} else {
// just focus on the first empty caller.
setFocusCallerIndex(index);
}
};

const [focusCallerIndex, setFocusCallerIndex] = useState<number | undefined>(0);
Expand Down

0 comments on commit d607e81

Please sign in to comment.