Skip to content

Commit

Permalink
Handle case insensitive duplicate emails check (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ace4port authored Mar 5, 2024
1 parent c8a150c commit 1c2934d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion react-multi-email/ReactMultiEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/allowDuplicate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: `[email protected]` } });
fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' });
}

fireEvent.change(textbox, { target: { value: `[email protected]` } });
fireEvent.keyUp(textbox, { key: 'Enter', code: 'Enter' });

const emailsWrapper = document.querySelector('.data-labels');
expect(emailsWrapper?.childElementCount)?.toBe(1);
});

0 comments on commit 1c2934d

Please sign in to comment.