Merge pull request #11002 from overleaf/msm-fix-email-suggestion

[web] Fix clearing suggestions in email input

GitOrigin-RevId: c821114e2112bf066f4ee5f01304321db983bc4e
This commit is contained in:
Brian Gough 2023-01-16 11:35:01 +00:00 committed by Copybot
parent c87772d732
commit 95bb5ca4e4
2 changed files with 6 additions and 4 deletions

View file

@ -148,7 +148,9 @@ function Input({ onChange, handleAddNewEmail }: InputProps) {
) )
useEffect(() => { useEffect(() => {
if (suggestion && inputValue && !suggestion.startsWith(inputValue)) { if (!inputValue) {
setSuggestion(null)
} else if (suggestion && !suggestion.startsWith(inputValue)) {
setSuggestion(null) setSuggestion(null)
} }
}, [suggestion, inputValue]) }, [suggestion, inputValue])

View file

@ -146,11 +146,11 @@ describe('<AddEmailInput/>', function () {
).to.equal(true) ).to.equal(true)
}) })
it('should clear the suggestion when the potential domain match is completely deleted', function () { it('should clear the suggestion when the potential domain match is completely deleted', async function () {
await screen.findByText('user@domain.edu')
fireEvent.change(screen.getByRole('textbox'), { fireEvent.change(screen.getByRole('textbox'), {
target: { value: 'user@' }, target: { value: '' },
}) })
expect(onChangeStub.calledWith('user@')).to.equal(true)
expect(screen.queryByText('user@domain.edu')).to.be.null expect(screen.queryByText('user@domain.edu')).to.be.null
}) })