Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select TextField on change typings do not match #12257

Closed
Swazimodo opened this issue Jul 23, 2018 · 1 comment
Closed

Select TextField on change typings do not match #12257

Swazimodo opened this issue Jul 23, 2018 · 1 comment

Comments

@Swazimodo
Copy link

Swazimodo commented Jul 23, 2018

I noticed that the typescript type for the on change event of a select TextField does not match the actual event object returned.

Expected Behavior

Typescript type matches the actual object in an TextField onchange event.

Current Behavior

Event object passed into an onChange event handler from a TextField is different between a default text field and a choice TextField.

Steps to Reproduce

        <TextField
          label="With normal TextField"
          id="simple-start-adornment"
          className={classNames(classes.margin, classes.textField)}
          onChange={this.handleTextFieldOnChange('justText')}
        />
        <TextField
          select
          label="With Select"
          className={classNames(classes.margin, classes.textField)}
          value={this.state.weightRange}
          onChange={this.handleTextFieldOnChange('choices')}
        >
          {ranges.map(option => (
            <MenuItem key={option.value} value={option.value}>
              {option.label}
            </MenuItem>
          ))}
        </TextField>

    handleTextFieldOnChange = (prop: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
        console.log(event);
        this.setState({ [prop]: event.target.value });
    }

Your Environment

Tech Version
Material-UI v^1.1.0
React v^16.3.2
@types/react v^16.3.13
Chrome v67.0.3396.99
Typescript v2.8.4
@t49tran
Copy link
Contributor

t49tran commented Jul 27, 2018

I think this issue is legit. I reckon a fix can just be simply as updating [TextField] onChange type defintion to be:

  onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>;

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

No branches or pull requests

3 participants