Skip to content

userEvent.type on contenteditable #442

@ph-fritsche

Description

@ph-fritsche

userEvent.type() on an element with contenteditable does not honor the cursor position / selection.

I've set up a code example to demonstrate the problem here:
https://codesandbox.io/s/usereventtype-on-contenteditable-obxib?file=/src/app.test.js

The input field with the content foo has an EventListener that just copies InputEvents event.target.textContent on another div.

When you click one of the buttons and start typing bar, you can see your input being inserted as expected.

Trying to emulate the behavior per userEvent.type fails.
When the cursor is in front of foo , it sets textContent to foobar instead of barfoo.
When the cursor is behind foo, it sets textContent to fbaroo instead if foobar.
When the content is selected, it sets textContent to baroo instead of bar.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions