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

Selection not cleared when input is focused #1204

Open
nils4cosee opened this issue Mar 22, 2024 · 0 comments
Open

Selection not cleared when input is focused #1204

nils4cosee opened this issue Mar 22, 2024 · 0 comments
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member

Comments

@nils4cosee
Copy link

Reproduction example

https://codesandbox.io/p/devbox/ykz7x2?file=%2Fsrc%2FrenderApp.test.js

Prerequisites

  1. Render
<div>Some text</div>
<in
put data-test="input" autofocus>

with javascript

document.querySelector('div').addEventListener('click', () => {
    document.querySelector('input').focus()
    console.log('activeElement', document.activeElement)
    console.log(`selection "${window.getSelection()?.toString()}"`)
})
  1. Select some text out of the "Some text" div by clicking and dragging the mouse inside the div
await user.pointer([
    {target: screen.getByText('Some text'), offset: 1, keys: '[MouseLeft>]'},
    {offset: 8},
    {keys: '[/MouseLeft]'},
  ])
  await new Promise(resolve => setTimeout(resolve, 100))

Expected behavior

In a real browser, when I select text in the "Some text" element, the selection is visible until the mouse-button is released. Then, the mouse-release triggers a "click" event which. The event-handler is invoked, the input-field is focused.

This causes the selection to be removed.

text-select-reproduction

Actual behavior

The in the test-code the click is triggered as in the browser. The input-element is focused.

But the selection is not removed. window.getSelection.toString() still returns the selected string "ome tex"

User-event version

14.5.2

Environment

Dependencies of the reproduction example

dependencies:
@testing-library/dom 8.12.0
@testing-library/jest-dom 5.16.3
@testing-library/user-event 14.5.2

devDependencies:
@vitejs/plugin-react 4.2.1
husky 4.3.8
jsdom 24.0.0
lint-staged 10.5.4
prettier 1.19.1
vite 5.1.1
vitest 1.4.0

Additional context

No response

@nils4cosee nils4cosee added bug Something isn't working needs assessment This needs to be looked at by a team member labels Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member
Projects
None yet
Development

No branches or pull requests

1 participant