瀏覽代碼

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

[web] Fix clearing suggestions in email input

GitOrigin-RevId: c821114e2112bf066f4ee5f01304321db983bc4e
Brian Gough 3 年之前
父節點
當前提交
95bb5ca4e4

+ 3 - 1
services/web/frontend/js/features/settings/components/emails/add-email/input.tsx

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

+ 3 - 3
services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx

@@ -146,11 +146,11 @@ describe('<AddEmailInput/>', function () {
         ).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'), {
-          target: { value: 'user@' },
+          target: { value: '' },
         })
-        expect(onChangeStub.calledWith('user@')).to.equal(true)
         expect(screen.queryByText('user@domain.edu')).to.be.null
       })