How can I type into the TextField input in the MUI datepicker with react-testing-library's user-event
? I can see there is a mask being applied
I've tried userEvent.type(inputEl, '1')
and userEvent.keyboard('1')
. In both cases, the input remains empty.
My current assumption is that a rerender replaces my update with the empty state of a higher order component (which makes sense, based on the application the date format mask to the input).
The documentation example works as expected, so my issue is specific to the MUI datepicker.
A watered down version of the component (and test) can be found in this sandbox.
Below is a copy of the rendered HTML to prove I'm targeting the input element with a data-testid
, which does not work:
screen.getByTestId('date-selector-text-field').outerHTML:
<input
aria-invalid="false"
placeholder="dd / mm / yyyy"
readonly=""
type="text"
aria-readonly="true"
aria-label="Choose date"
data-testid="date-selector-text-field"
class="MuiOutlinedInput-input MuiInputBase-input css-1t8l2tu-MuiInputBase-input-MuiOutlinedInput-input"
value=""
aria-describedby="mui-1-helper-text"
id="mui-1"
>