Skip to content

Commit

Permalink
Clear vern selection when user returns to vern text field (#3290)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Aug 5, 2024
1 parent 468e516 commit 474ec40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface VernWithSuggestionsProps {
updateVernField: (newValue: string, openDialog?: boolean) => void;
onBlur: () => void;
onClose?: (e: SyntheticEvent, reason: AutocompleteCloseReason) => void;
onFocus?: () => void;
suggestedVerns?: string[];
handleEnter: () => void;
vernacularLang: WritingSystem;
Expand Down Expand Up @@ -51,6 +52,7 @@ export default function VernWithSuggestions(
// onChange is triggered when an option is selected
props.updateVernField(value ?? "", true);
}}
onFocus={props.onFocus}
onInputChange={(_e, value) => {
// onInputChange is triggered by typing
props.updateVernField(value);
Expand Down
8 changes: 8 additions & 0 deletions src/components/DataEntry/DataEntryTable/NewEntry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
}
};

/** Clear the duplicate selection if user returns to the vernacular field. */
const handleOnVernFocus = (): void => {
if (selectedDup) {
setSelectedDup();
}
};

const handleCloseVernDialog = (id?: string): void => {
if (id !== undefined) {
setSelectedDup(id);
Expand Down Expand Up @@ -260,6 +267,7 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
setVernOpen(true);
}
}}
onFocus={handleOnVernFocus}
suggestedVerns={suggestedVerns}
// To prevent unintentional no-gloss submissions:
// If enter pressed from the vern field, check whether gloss is empty
Expand Down

0 comments on commit 474ec40

Please sign in to comment.