Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): don't release keyboard automatically #6083

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/browser/src/node/commands/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const keyboard: UserEventCommand<UserEvent['keyboard']> = async (
throw new TypeError(`Provider "${context.provider.name}" does not support selecting all text`)
}
},
false,
true,
)
}

Expand Down
16 changes: 16 additions & 0 deletions test/browser/test/userEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ describe('userEvent.keyboard', async () => {
])
})

test('should not auto release', async () => {
const spyKeydown = vi.fn()
const spyKeyup = vi.fn()
const button = document.createElement('button')
document.body.appendChild(button)
button.addEventListener('keydown', spyKeydown)
button.addEventListener('keyup', spyKeyup)
button.focus()
await userEvent.keyboard('{Enter>}')
expect(spyKeydown).toHaveBeenCalledOnce()
expect(spyKeyup).not.toHaveBeenCalled()
await userEvent.keyboard('{/Enter}')
// userEvent doesn't fire any event here, but should we?
expect(spyKeyup).not.toHaveBeenCalled()
})

test('standalone keyboard works correctly with active input', async () => {
const documentKeydown: string[] = []
const inputKeydown: string[] = []
Expand Down
Loading