Giter VIP home page Giter VIP logo

Comments (6)

faergeek avatar faergeek commented on July 25, 2024

Great point.

@tleunen What do you think? Why did you decide to pass value to handler instead of original event?

from react-mdl.

faergeek avatar faergeek commented on July 25, 2024

Not sure that it's fired twice because of that though, AFAIK comments don't work like this in JSX.
@joshq00 Try removing it instead of commenting.

from react-mdl.

joshq00 avatar joshq00 commented on July 25, 2024

Re-writing this comment.

Essentially, the problem is that I couldn't stop the onChange event from propagating.

handleChange ( checked ) {
   // logic
   // ...
   // ...
   this.props.onChange( this.state.checkedCount );
}

render () {
   let { title, ...other } = this.props;
   return (
      <MyComponent { ...other }>
         <h1>{ title }</h1>
         <Checkbox label='option 1' onChange={ ::this.handleChange } />
      </MyComponent>
   );
}

Use <MyComponent onChange={ console.log } /> and it'll fire twice: once with checkedCount, once with SyntheticEvent.

It's hard to reason why: but it's because we trigger it, then the original onChange from the checkbox propagates and fires on MyComponent. But as a user, we never saw this because the handler is (under the covers) swallowing the event and letting it continue propagating. I'd normally have to stop that in 'handleChange'

from react-mdl.

joshq00 avatar joshq00 commented on July 25, 2024

Sorry for those repeated commits. Don't know if you expect one-commit merges. Had to do some tweaking tweaking with the demos

from react-mdl.

joshq00 avatar joshq00 commented on July 25, 2024

If accepted, should probably bump a minor version... As these will be breaking changes

from react-mdl.

tleunen avatar tleunen commented on July 25, 2024

@web2style once made a PR about the same kind of change: #25. It was accepted and then reverted.

But this one seems to be more consistant. It updates every component with the same behavior.

Initially, the reason why the value was only sent is because usually, that's the only information you care to receive. But I do understand sometimes you want more, or like in this case, you want the same function signature. So I agree to accept the PR. I'll do it later after a better look at it.

from react-mdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.