Git Product home page Git Product logo

Comments (5)

leMaik avatar leMaik commented on August 13, 2024

We already call the onChange handler with an empty string in the handleCancel method, so you just need to handle that.

from material-ui-search-bar.

nwshane avatar nwshane commented on August 13, 2024

@leMaik Ah, I think I see the problem.onChange is called directly on the event object in the handleInput method, but onChange is called with an empty string in the handleCancel method. When I click the cancel button, my onChange handler is expecting an event object with event.target.value, and so I get the error Cannot read property 'value' of undefined.

from material-ui-search-bar.

nwshane avatar nwshane commented on August 13, 2024

@leMaik How about this for a fix? Instead of...

handleCancel () {
  this.setState({active: false, value: ''})
  this.props.onChange('')
}

Do this:

handleCancel () {
  this.setState({active: false, value: ''})
  this.props.onChange({target: {value: ''}})
}

from material-ui-search-bar.

nwshane avatar nwshane commented on August 13, 2024

@leMaik I've been trying to link a local, forked version of this repository in order to test this change (and to potentially make a PR), but I'm having trouble doing so. I'm getting this error:

removeComponentAsRefFrom(...): Only a ReactOwner can have refs. You might be removing a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

It doesn't look like multiple copies of React are loading (output from yarn list react is just one copy). Could this have something to do with the AutoComplete ref? Sorry, I'm a little out of my league here - haven't used refs before.

from material-ui-search-bar.

leMaik avatar leMaik commented on August 13, 2024

@nwshane I'd prefer to always call onChange with the new value instead. That would be a breaking change, but a PR would be highly appreciated! 👍

from material-ui-search-bar.

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.