From 1c2934d3aa870f026eb2f38be329aba700c061ab Mon Sep 17 00:00:00 2001 From: Abdullah Waqar <39233007+ace4port@users.noreply.github.com> Date: Tue, 5 Mar 2024 04:47:05 +0000 Subject: [PATCH] Handle case insensitive duplicate emails check (#173) --- react-multi-email/ReactMultiEmail.tsx | 2 +- test/allowDuplicate.test.tsx | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/react-multi-email/ReactMultiEmail.tsx b/react-multi-email/ReactMultiEmail.tsx index e9011bc..ec0919f 100644 --- a/react-multi-email/ReactMultiEmail.tsx +++ b/react-multi-email/ReactMultiEmail.tsx @@ -88,7 +88,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) { const addEmails = (email: string) => { if (!allowDuplicate) { for (let i = 0, l = emails.length; i < l; i++) { - if (emails[i] === email) { + if (emails[i].toLowerCase() === email.toLowerCase()) { return false; } } diff --git a/test/allowDuplicate.test.tsx b/test/allowDuplicate.test.tsx index 89406f1..787d8ee 100644 --- a/test/allowDuplicate.test.tsx +++ b/test/allowDuplicate.test.tsx @@ -62,3 +62,20 @@ it('allowDuplicate = undefined', async () => { const emailsWrapper = document.querySelector('.data-labels'); expect(emailsWrapper?.childElementCount)?.toBe(1); }); + +it('allowDuplicate = false, case sensitive', async () => { + const { getByRole } = render(createReactMultiEmail(false)); + const textbox = getByRole('textbox'); + + const num = 3; + for (let i = 0; i < num; i++) { + fireEvent.change(textbox, { target: { value: `test@example.com` } }); + fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' }); + } + + fireEvent.change(textbox, { target: { value: `Test@example.com` } }); + fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' }); + + const emailsWrapper = document.querySelector('.data-labels'); + expect(emailsWrapper?.childElementCount)?.toBe(1); +});