-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AutoComplete] Issue with the controlled behavior / clear #2615
Comments
This is rather react related not material-ui you cannot call methods on |
@alitaheri how would you suggest we get / set the |
@joncursi Take a look at react's docs: https://facebook.github.io/react/docs/more-about-refs.html#a-complete-example |
@alitaheri I guess what I'm trying to say is that Material UI does not expose the |
right right. You can't do that but you can use |
Hey, I am trying to use the props |
What if we do something like this there: const currentSearchText = this.state.searchText;
this.timerTouchTapCloseId = setTimeout(() => {
if(this.state.searchText === currentSearchText) {
this.setState({
searchText: searchText,
});
}
this.close();
this.timerTouchTapCloseId = null;
}, this.props.menuCloseDelay); |
Edit: actually, I don't think that solution would fully address the issue. @alexprice91 explains the problem above. Even if you are controlling the I don't really like the |
A short-term workaround is to give your auto complete component a ref, then manually call this.refs.autoComplete.setState({ searchText: ''}) |
Thanks @greypants! Your approach worked for me. |
@jlroettger I completely agree, that handleItemTouchTap = (event, child) => {
const dataSource = this.props.dataSource;
const index = parseInt(child.key, 10);
const chosenRequest = dataSource[index];
const searchText = this.chosenRequestText(chosenRequest);
+
+ this.setState({
+ searchText: searchText,
+ });
+ this.props.onUpdateInput(searchText, this.props.dataSource, {
+ type: 'selected',
+ });
this.timerTouchTapCloseId = setTimeout(() => {
this.timerTouchTapCloseId = null;
-
- this.setState({
- searchText: searchText,
- });
this.close();
this.props.onNewRequest(chosenRequest, index);
}, this.props.menuCloseDelay);
}; |
For some reason, this issue still persisted for me. There are different arguments to the third parameter depending on whether you're typing or selecting a menu item. I just honed in on that action to only set the state when it is a change event |
As the components are now functional, setState is no longer working, do we have any alternative solution? |
@sirajalam049 Material-UI can still be used in class components, only our demos can't. This is very handy for the legacy parts of your codebase so you don't have to migrate them to hooks (assuming you write all new features in hooks). |
I have an autocomplete field which uses
like this;
but when I update the
in the
onNewRequest
funcit will clear the autoComplete once, but not the second time.
it seems some internal caching happens?
how to call internal methods of the MUI components?
mat-ui components more general question:
Is there a way to call the methods on that object directly like setValue?
https://github.com/callemall/material-ui/blob/master/src/auto-complete.jsx#L244-L248
I tried something like
but that doesn't work. Given an instance of a component how would I access its methods?
this is a more general question, i could add it to the docs if someone could illuminate me.
The text was updated successfully, but these errors were encountered: