question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MenuItem wrapped in Tooltip breaks Select's onChange callback

See original GitHub issue

If you want to explain a Select field’s MenuItems via a tooltip, the onChange will no longer work.

  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Select a new value, state is updated

Current Behavior

Crash. Event target is the tooltip, not the MenuItem, and thus there is no target value

Steps to Reproduce (for bugs)

<FormControl>
    <InputLabel htmlFor='activity-level'>Activity Level</InputLabel>
    <SelectField
        input={<Input name="sort" id='activity-level' />}
        onChange={this.handleFormChange('activityLevel')}
        value={this.state.activityLevel}
    >
        <Tooltip id="tooltip-sedentary" title="Little or no exercise" placement="right">
            <MenuItem value={'sedentary'} >Sedentary</MenuItem>
        </Tooltip>
        <Tooltip id="tooltip-light" title="1-3/week" placement="right">
            <MenuItem value={'light'} >Light</MenuItem>
        </Tooltip>
    </SelectField>
</FormControl>


handleFormChange(key) {
    return (event) => {
        debugger
        let newState = {};
        newState[key] = event.target.value;
        this.setState(newState);
    }
}

Your Environment

Tech Version
Material-UI 1.0.0-beta.26
React 16.1.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jan 5, 2018

@JarLowrey You need to create a custom menu item component, forward the injected property to the MenuItem. It’s fundamentally the same as what it’s documented here https://material-ui-next.com/guides/composition/#wrapping-components.

0reactions
nickfreemandesigncommented, Jun 1, 2022

@Jakeron thanks for providing this closure. I ended up just putting the tooltip inside the menuselect, rather than the reverse to solve my problem

<Select
  value={someValue}
  onChange={({ target: { value } }) => handleChange(value)}>
    {
      SOME_COLLECTION.map(({ name, description }) =>
        <MenuItem value={name}>
          <Tooltip
            title={description}
            placement={"left-start"}>
              <span>{name}</span>
          </Tooltip>
        </MenuItem>)
    }
</Select>
Read more comments on GitHub >

github_iconTop Results From Across the Web

MenuItem wrapped in Tooltip breaks Select's onChange ...
MenuItem wrapped in Tooltip breaks Select's onChange callback #9737 · Comments · Expected Behavior · Current Behavior · Steps to Reproduce (for bugs)....
Read more >
Material-UI - Tooltip on Select/MenuItem component stays ...
I want it to disappear as soon as the Select is clicked so that it doesn't stay over the MenuItems (Changing the zIndex...
Read more >
show message validate error input once at a time ant design ...
Now, just taking a look at your code snippet, I suggest you take a different approach. Instead of wrapping all three of your...
Read more >
1. The ZK User Interface Markup Language - Courses
An input control notifies the application with the onChange event if its content is changed by the user. Notice that, when the onChange's...
Read more >
React menu component - szhsin/react-menu
FocusableItem is a special menu item. It's used to wrap elements which are able to receive focus, such as input or button. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found