material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Tabs] component reacts to child input's "change" event.

Open Li0liQ opened this issue 11 years ago • 19 comments

<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.

Li0liQ avatar Nov 16 '15 14:11 Li0liQ

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…}   

ghost avatar Jan 15 '16 02:01 ghost

Same here

derekwzheng avatar Jan 27 '16 00:01 derekwzheng

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

glennr avatar Feb 02 '16 07:02 glennr

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>

naveg avatar Mar 02 '16 20:03 naveg

I have: Tabs > Tab > TextField

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

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

liesislukas avatar Mar 23 '16 10:03 liesislukas

+1

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

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

vspiewak avatar Mar 31 '16 22:03 vspiewak

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...

willemx avatar Apr 24 '16 15:04 willemx

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.

tjunnone avatar May 18 '16 19:05 tjunnone

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

oreqizer avatar May 25 '16 06:05 oreqizer

@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)

clarkie avatar May 31 '16 06:05 clarkie

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

oreqizer avatar May 31 '16 07:05 oreqizer

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

aluksidadi avatar Oct 04 '16 02:10 aluksidadi

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

oliviertassinari avatar Oct 19 '16 19:10 oliviertassinari

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);
  };

jforaker avatar Jan 31 '17 16:01 jforaker

@oliviertassinari Is there a regression in 0.16.7?

Li0liQ avatar Jan 31 '17 20:01 Li0liQ

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

oliviertassinari avatar Jan 31 '17 21:01 oliviertassinari

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.

jforaker avatar Jan 31 '17 22:01 jforaker

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

satishchadokar avatar Nov 19 '18 22:11 satishchadokar

Still an issue, stopPropagation is not solving it

RoudyTarabay avatar Mar 11 '21 08:03 RoudyTarabay