Skip to content

Commit

Permalink
fix: Add timeout to SingleSelectComponent value change
Browse files Browse the repository at this point in the history
- Android devices freezes totally when trying to change value of a SingleSelectComponent. Add a short timeout to prevent infinite loop after calling onChange.
  • Loading branch information
jorilindell committed Jan 15, 2024
1 parent 9c13747 commit b877130
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/__tests__/Pages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const signupGroupValues: SignupGroupFormFields = {
id: TEST_SIGNUP_ID,
inWaitingList: false,
lastName: 'Last name',
phoneNumber: '0441234567',
streetAddress: 'Street address',
zipcode: '00100',
},
Expand Down
10 changes: 7 additions & 3 deletions src/common/components/formFields/SingleSelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ const SingleSelectField: React.FC<Props> = ({
};

const handleChange = (selected: OptionType) => {
onChange({
target: { id: name, value: selected.value },
});
// Set timeout to prevent Android devices to end up
// to an infinite loop when changing value
setTimeout(() => {
onChange({
target: { id: name, value: selected.value },
});
}, 5);
};

return (
Expand Down

0 comments on commit b877130

Please sign in to comment.