Skip to content

Wrong Selection when <input/> inside contenteditable is focused #1248

Open

Description

@ph-fritsche

Reproduction example

https://codesandbox.io/p/sandbox/nostalgic-sutherland-w2n2w8

Prerequisites

  1. Render <div contenteditable="true"><input/></div>
  2. Focus the HTMLInputElement

Expected behavior

The selection has one collapsed range at the position of the input element.

Actual behavior

The selection has no range.

User-event version

14.5.2

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

No response

Activity

  1. added
    bug
    on Jan 13, 2025
  2. yucheng-du commented on Dec 2, 2026

    @yucheng-du

    I compared the exact markup with an initially empty document selection. After focusing the input with a click, Tab, or input.focus(), Chromium, Firefox and WebKit all returned one collapsed range at (div, 0). On jsdom 20 with user-event 14.6.1 the range count was zero for all three paths.

    A preceding text node makes a difference when choosing which boundary to emulate. With <div contenteditable><span>before</span><input></div>, Chromium and WebKit reported (div, 1), immediately before the input. Firefox reported (span.firstChild, 0). The engines agree on the original example. #1344 changes when the selection helper is called on programmatic focus, but the helper still returns early when the selection starts empty.

  3. snowystinger commented on Dec 2, 2026

    @snowystinger
    Contributor

    I'm sorry, I have no idea what that comment is saying.

    Are you saying this issue is still reproducing and that #1344 doesn't fix it?

    Please make the intent of why you're commenting very obvious. What is the action you are suggesting be taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions