fix(web): email input

This commit is contained in:
JzoNg 2026-05-09 09:49:17 +08:00
parent 132f80dd9e
commit 0e389d223f
2 changed files with 37 additions and 0 deletions

View File

@ -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(

View File

@ -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