Skip to content

Conversation

@levibuzolic
Copy link

@levibuzolic levibuzolic commented Dec 11, 2025

Summary

We had a use case where we wanted to clear text in an input without blurring, to more realistically simulate the behaviour of a real user replacing the text of an input.

We needed this because we have some onBlur behaviour that would restore a default value, which made replacing the text problematic with the current clear() and type() APIs.

This can be solved in user-land with a bunch of manual {Backspace}, but I felt like it probably deserved a first-class API.

This PR adds:

  • clearBefore as an option to userEvent.type() to allow clearing existing text before entering new text.
  • skipBlur as an option to userEvent.clear() to allow clearing text without blurring

Test plan

Added unit tests for both new options.

@levibuzolic levibuzolic force-pushed the userevent-clear-skip-blur branch from 211becc to fb570b2 Compare December 11, 2025 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant