Skip to content

fireEvent change event not fired for input with type date #389

@kormbrek-rally

Description

@kormbrek-rally

This is quite similar to testing-library/react-testing-library#532 and testing-library/react-testing-library#544. But different from those, it is happening with a present and valid value for the type attribute of the input element.

  • @testing-library/react version: 9.4.0
  • react version: 16.9.3
  • node version: 8.17.0
  • npm (or yarn) version: npm 6.13.4
  • material-ui/core 3.9.2

Relevant code or config:

        <TextField
          type="date"
          value={this.state.date}
          onFocus={() => {console.log('FOCUS')}}
          onChange={() => {console.log('CHANGE')}}
          InputProps={{inputProps: {'data-testid': 'filter-date-input'}}}
        />

test.only('input date', async () => {
  const {getByTestId} = renderForTesting(<SomeComponent/>);
  const input = getByTestId('filter-date-input');
  console.log(`type: ` + input.getAttribute('type')); // prints type: date
  fireEvent.focus(input);
  fireEvent.change(input, { target: { value: '12/05/2020' } });
  // some code here waiting on result of onChange
});

What you did:

Trying to fire onChange of a component.

What happened:

BLUR is seen in the output (onBlur called).
CHANGE is not seen in the output (onChange not called).

If I change the type on TextField to "text", both events are fired.
However "date" is a valid type for inputs, and I can see that the input element material-ui creates has this from the log statement and some HTML from Chrome:

<input aria-invalid="false" class="MuiInputBase-input-198 MuiInput-input-183 MuiInputBase-inputType-201 MuiInput-inputType-186 MuiInputBase-inputMarginDense-199 MuiInput-inputMarginDense-184 MuiInputBase-inputAdornedStart-203" type="date" data-testid="filter-date-input" value="">

Reproduction:

Problem description:

Suggested solution:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions