mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 21:28:25 +08:00
fix(web): email input
This commit is contained in:
parent
132f80dd9e
commit
0e389d223f
@ -136,6 +136,40 @@ describe('human-input/delivery-method/recipient/email-input', () => {
|
||||
expect(handleSelect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should keep typing focused and stop keyboard events from reaching workflow listeners', () => {
|
||||
const handleParentKeyDown = vi.fn()
|
||||
const handleWindowKeyDown = vi.fn()
|
||||
window.addEventListener('keydown', handleWindowKeyDown)
|
||||
|
||||
try {
|
||||
render(
|
||||
<div onKeyDown={handleParentKeyDown}>
|
||||
<EmailInput
|
||||
email="owner@example.com"
|
||||
value={[]}
|
||||
list={members}
|
||||
onDelete={vi.fn()}
|
||||
onSelect={vi.fn()}
|
||||
onAdd={vi.fn()}
|
||||
/>
|
||||
</div>,
|
||||
)
|
||||
|
||||
const input = screen.getByRole('textbox')
|
||||
input.focus()
|
||||
|
||||
fireEvent.change(input, { target: { value: 'a' } })
|
||||
fireEvent.keyDown(input, { key: 'a', code: 'KeyA' })
|
||||
|
||||
expect(document.activeElement).toBe(input)
|
||||
expect(handleParentKeyDown).not.toHaveBeenCalled()
|
||||
expect(handleWindowKeyDown).not.toHaveBeenCalled()
|
||||
}
|
||||
finally {
|
||||
window.removeEventListener('keydown', handleWindowKeyDown)
|
||||
}
|
||||
})
|
||||
|
||||
it('should delete the last recipient with backspace, flag missing members as errors, and stop focusing when disabled', () => {
|
||||
const handleDelete = vi.fn()
|
||||
const { container, rerender } = render(
|
||||
|
||||
@ -104,6 +104,8 @@ const EmailInput = ({
|
||||
}
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
e.stopPropagation()
|
||||
|
||||
if (e.key === 'Enter' || e.key === 'Tab' || e.key === ' ' || e.key === ',') {
|
||||
e.preventDefault()
|
||||
handleEmailAdd()
|
||||
@ -155,6 +157,7 @@ const EmailInput = ({
|
||||
sideOffset={4}
|
||||
alignOffset={-40}
|
||||
popupClassName="border-none bg-transparent p-0 shadow-none backdrop-blur-none"
|
||||
popupProps={{ initialFocus: false, finalFocus: false }}
|
||||
positionerProps={{ anchor: inputRef }}
|
||||
>
|
||||
<MemberList
|
||||
|
||||
Loading…
Reference in New Issue
Block a user