mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
enhancement: add email address when input blur
This commit is contained in:
parent
d65523aa0b
commit
b242578b86
@ -81,23 +81,32 @@ const EmailInput = ({
|
|||||||
return emailRegex.test(email)
|
return emailRegex.test(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleEmailAdd = () => {
|
||||||
|
const emailAddress = searchKey.trim()
|
||||||
|
if (!checkEmailValid(emailAddress))
|
||||||
|
return
|
||||||
|
if (value.some(item => item.email === emailAddress))
|
||||||
|
return
|
||||||
|
if (list.some(item => item.email === emailAddress)) {
|
||||||
|
const item = list.find(item => item.email === emailAddress)!
|
||||||
|
onSelect(item.id)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
onAdd(emailAddress)
|
||||||
|
}
|
||||||
|
setSearchKey('')
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleInputBlur = () => {
|
||||||
|
setIsFocus(false)
|
||||||
|
handleEmailAdd()
|
||||||
|
}
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === 'Enter' || e.key === 'Tab' || e.key === ' ' || e.key === ',') {
|
if (e.key === 'Enter' || e.key === 'Tab' || e.key === ' ' || e.key === ',') {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const emailAddress = searchKey.trim()
|
handleEmailAdd()
|
||||||
if (!checkEmailValid(emailAddress))
|
|
||||||
return
|
|
||||||
if (value.some(item => item.email === emailAddress))
|
|
||||||
return
|
|
||||||
if (list.some(item => item.email === emailAddress)) {
|
|
||||||
const item = list.find(item => item.email === emailAddress)!
|
|
||||||
onSelect(item.id)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
onAdd(emailAddress)
|
|
||||||
}
|
|
||||||
setSearchKey('')
|
|
||||||
setOpen(false)
|
|
||||||
}
|
}
|
||||||
else if (e.key === 'Backspace') {
|
else if (e.key === 'Backspace') {
|
||||||
if (searchKey === '' && value.length > 0) {
|
if (searchKey === '' && value.length > 0) {
|
||||||
@ -144,7 +153,7 @@ const EmailInput = ({
|
|||||||
className="system-sm-regular h-6 min-w-[166px] appearance-none bg-transparent p-1 text-components-input-text-filled caret-primary-600 outline-none placeholder:text-components-input-text-placeholder"
|
className="system-sm-regular h-6 min-w-[166px] appearance-none bg-transparent p-1 text-components-input-text-filled caret-primary-600 outline-none placeholder:text-components-input-text-placeholder"
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onFocus={() => setIsFocus(true)}
|
onFocus={() => setIsFocus(true)}
|
||||||
onBlur={() => setIsFocus(false)}
|
onBlur={handleInputBlur}
|
||||||
value={searchKey}
|
value={searchKey}
|
||||||
onChange={handleValueChange}
|
onChange={handleValueChange}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user