Material-ui: [Tabs] component reacts to child input's "change" event.

Created on 16 Nov 2015  路  18Comments  路  Source: mui-org/material-ui

<Tabs onChange={(e) => console.log('change', e)}>
    <Tab label='Tab1' value={'1'}>
        <input />
    </Tab>
    <Tab label='Tab2' value={'2'}></Tab>
</Tabs>

Typing anything into input triggers onChange of Tabs component.
Seems like input's change event bubbles up and gets caught by Tabs.

bug 馃悰 Tabs

Most helpful comment

Try giving the input an onChange handler with a stopPropagation call.

handleInputChange(event) {
  event.stopPropagation();
}

<Tabs onChange={(e) => console.log('change', e)}>
    <Tab label='Tab1' value={'1'}>
        <input onChange={handleInputChange} />
    </Tab>
    <Tab label='Tab2' value={'2'}></Tab>
</Tabs>

All 18 comments

Having the same issue-

value =聽SyntheticEvent聽{dispatchConfig:聽Object,聽dispatchMarker:聽".0.0.2.2.0.0.0.0.1.3.0.2.$0.0.0.0.0.0.2",聽nativeEvent:聽Event,聽target:聽input#mui-id-1,聽currentTarget:聽div鈥聽 聽

Same here

+1 - using a redux-form component inside a Tab. Here's what it looks like: https://monosnap.com/file/gk4lE4L4Z8GDIyB0daQuobbyC3CQq6

Try giving the input an onChange handler with a stopPropagation call.

handleInputChange(event) {
  event.stopPropagation();
}

<Tabs onChange={(e) => console.log('change', e)}>
    <Tab label='Tab1' value={'1'}>
        <input onChange={handleInputChange} />
    </Tab>
    <Tab label='Tab2' value={'2'}></Tab>
</Tabs>

I have: Tabs > Tab > TextField

Confirmed. TextField onChange Tabs[onChange] is fired too. @Naveg solution works great.

<TextField  onChange={e => e.stopPropagation()} />

+1

Tabs > Tab > TextField (or a simple <input type="text" ... />)

Fixed like others with:
<TextField onChange={e => e.stopPropagation()} />

Also have this issue, but cannot use the stopPropagation-workaround because the event is triggered inside a third party component :(
So now I must have a check in the onChange handler for all valid Tab-values...

Stopping the event propagation seems to block some normal textfield interactions: double-click to select text, shift-arrow-keys to expand selection etc. so it's not a great workaround.

the problem is also when using Redux Form - then I can't stop propagation easily

@willemx you don't have to check for specific values. Because of the known behaviour of the click propagation you could just check for a string:

handleTabChange: function (value) {
  if (typeof value === 'string') {
    hashHistory.push(`/${value}`)
  }
},

(I'm using redux-form, material-ui and react-router)

what I ended up doing was:
screen shot 2016-05-31 at 08 59 40

which is basically what was suggested, just moved the event stopper to the form's root

Hey guys, so is this a bug or by design?

Oups, I have never seen this issue before. It was fixed by #5219 and released with v0.16.0.

FYI - This is still an issue in 0.16.7
(input still fires onChange event for <Tabs /> component)
image

current workaround:

  doHandleTabChange = (tab) => {
    if (typeof tab !== 'string') return false;
    this.props.doSwitchTab(tab);
  };

@oliviertassinari Is there a regression in 0.16.7?

Do you have a reproduction test case? I can't reproduce it.

I do not because as always, there are deps among deps and I can't easily abstract it to a webpackbin. i am using material-ui-chip-input inside the second tab, which might be the culprit. Thanks for the repro link.

Still same issue... is there any good solution?
please let me know

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

finaiized picture finaiized  路  3Comments

ericraffin picture ericraffin  路  3Comments

chris-hinds picture chris-hinds  路  3Comments

revskill10 picture revskill10  路  3Comments