Skip to content

Commit

Permalink
Feature/onblur action disable (#141)
Browse files Browse the repository at this point in the history
* add disableOnBlurValidation

* Update readme

add missing props

* 예제 페이지 제작

* Remove unused code

---------

Co-authored-by: Da-hwon Ju <[email protected]>
  • Loading branch information
thomasJang and hwonda authored Jul 23, 2023
1 parent dfff6aa commit 9eb58fe
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export default BasicExample;
<td></td>
</tr>
<tr>
<td>
getLabel</td>
<td>getLabel</td>
<td>
(
email: string,
Expand All @@ -189,6 +188,13 @@ export default BasicExample;
<td>''</td>
<td></td>
</tr>
<tr>
<td>
inputClassName</td>
<td>string</td>
<td>''</td>
<td></td>
</tr>
<tr>
<td>
placeholder</td>
Expand Down Expand Up @@ -217,13 +223,26 @@ export default BasicExample;
<td>'[ ,;]'</td>
<td></td>
</tr>
<tr>
<tr>
<td>
autoComplete</td>
<td>string | undefined</td>
<td></td>
<td></td>
</tr>
<tr>
<td>initialInputValue</td>
<td>string | undefined</td>
<td>''</td>
<td></td>
</tr>
<tr>
<td>
disableOnBlurValidation</td>
<td>boolean | undefined</td>
<td>false</td>
<td></td>
</tr>
</table>

## License
Expand Down
1 change: 1 addition & 0 deletions components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Nav(_props: Props) {
items={[
{ label: `Basic`, key: '/' },
{ label: `CustomizeStyle`, key: '/customizeStyle' },
{ label: `DisableOnBlurValidation`, key: '/disableOnBlurValidation' },
]}
onTabClick={async activeKey => {
await router.push(activeKey);
Expand Down
48 changes: 48 additions & 0 deletions examples/DisableOnBlurValidation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';
import styled from '@emotion/styled';
import { ReactMultiEmail } from '../react-multi-email';

interface Props {}

function DisableOnBlurValidation(props: Props) {
const [emails, setEmails] = React.useState<string[]>([]);

return (
<Container>
<form>
<h3>Email</h3>
<ReactMultiEmail
placeholder='Input your email'
emails={emails}
onChange={(_emails: string[]) => {
setEmails(_emails);
}}
autoFocus={true}
disableOnBlurValidation
getLabel={(email, index, removeEmail) => {
return (
<div data-tag key={index}>
<div data-tag-item>{email}</div>
<span data-tag-handle onClick={() => removeEmail(index)}>
×
</span>
</div>
);
}}
onChangeInput={value => {
console.log(value);
}}
/>
<br />
<h4>react-multi-email value</h4>
<p>{emails.join(', ') || 'empty'}</p>
</form>
</Container>
);
}

const Container = styled.div`
font-size: 13px;
`;

export default DisableOnBlurValidation;
24 changes: 24 additions & 0 deletions pages/disableOnBlurValidation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import type { NextPage } from 'next';
import { Container } from '../components/Layouts';
import styled from '@emotion/styled';
import BodyRoot from '../components/BodyRoot';
import DisableOnBlurValidation from '../examples/DisableOnBlurValidation';

const Custom: NextPage = () => {
return (
<PageContainer>
<Container>
<div>
<h2>DisableOnBlurValidation</h2>
<p>If the DisableOnBlurValidation value is true, email validation is not performed as a blur event.</p>
<DisableOnBlurValidation />
</div>
</Container>
</PageContainer>
);
};

const PageContainer = styled(BodyRoot)``;

export default Custom;
8 changes: 6 additions & 2 deletions react-multi-email/ReactMultiEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IReactMultiEmailProps {
delimiter?: string;
initialInputValue?: string;
autoComplete?: string;
disableOnBlurValidation?: boolean;
allowDisplayName?: boolean;
stripDisplayName?: boolean;
}
Expand Down Expand Up @@ -66,6 +67,7 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
onKeyDown,
onKeyUp,
spinner,
disableOnBlurValidation = false,
} = props;
const emailInputRef = React.useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -259,10 +261,12 @@ export function ReactMultiEmail(props: IReactMultiEmailProps) {
const handleOnBlur = React.useCallback(
async (e: React.SyntheticEvent<HTMLInputElement>) => {
setFocused(false);
await findEmailAddress(e.currentTarget.value, true);
if (!disableOnBlurValidation) {
await findEmailAddress(e.currentTarget.value, true);
}
onBlur?.();
},
[findEmailAddress, onBlur],
[disableOnBlurValidation, findEmailAddress, onBlur],
);

const handleOnFocus = React.useCallback(() => {
Expand Down

1 comment on commit 9eb58fe

@vercel
Copy link

@vercel vercel bot commented on 9eb58fe Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-multi-email – ./

react-multi-email-git-master-axframe.vercel.app
react-multi-email-axframe.vercel.app
react-multi-email.vercel.app

Please sign in to comment.