Comments (5)
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.
@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.
@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.
@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.
@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)
- FEATURE REQUEST: Give option to NOT clear the search when canceling search. HOT 2
- how to set color to input and searchbutton
- Forked this project, republished and willing to help with features HOT 7
- Does this project have support for material-ui 5 beta? HOT 3
- It is not working with latest version of @mui-material HOT 4
- About the datasource and auto complete in the action. HOT 2
- Material UI Search Bar is not compatible with React 17 and above HOT 1
- Icon Accessibility
- The original material button style lossed after I import the SearchBar
- How to install a module on react 17+? HOT 4
- Placeholder can go out of search bar container HOT 1
- Can we search without pressing enter ?
- @material-ui/icons/Clear need to install first? HOT 1
- onClearSearch is not triggered HOT 1
- Cannot use variant or any props on the input HOT 1
- inputRef can't be used HOT 1
- Integration with DataGrid HOT 1
- Can't seem to autofocus the searchbar HOT 5
- Cant change the Icon hover effect HOT 1
- unable to resolve dependency tree for React 17 HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui-search-bar.