Skip to content
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

Undo in controlled TextField stops working after leaving component #18545

Closed
ziktar opened this issue Nov 25, 2019 · 5 comments
Closed

Undo in controlled TextField stops working after leaving component #18545

ziktar opened this issue Nov 25, 2019 · 5 comments
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! external dependency Blocked by external dependency, we can’t do anything about it

Comments

@ziktar
Copy link

ziktar commented Nov 25, 2019

When using TextField in a controlled manner, you lose the ability to undo steps as soon as focus on the element is lost. Uncontrolled TextFields work fine.

For instance, on the TextField demo page, scroll to the "Uncontrolled vs Controlled" section. Input text into the "Name" field, then the "Uncontrolled" field, then the "Name" field again, and then the "Uncontrolled" field again. Use Ctrl/Cmd+Z or Edit->Undo to undo changes. The changes made in the uncontrolled field will be undone, but the changes in the controlled field will not. Focus will be changed to the uncontrolled field, but the data will not be changed.

As far as events goes, if an Undo command is triggered while the TextInput remains focus, then an onChange event will be fired. If you make changes, then leave focus, then trigger the Undo, then onChange events will not be fired.

ezgif-6-f3781d3de552

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 25, 2019

It looks close to facebook/react#8514. Can you reproduce the issue on a builtin input element? What browser/platform are you using?

@oliviertassinari oliviertassinari added waiting for user information component: text field This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work external dependency Blocked by external dependency, we can’t do anything about it and removed waiting for user information labels Nov 25, 2019
@oliviertassinari
Copy link
Member

I could reproduce on macOS and Chrome 78.0.3904.108. It fails when these lines run: https://github.com/mui-org/material-ui/blob/f6a9ea17d64835f9a4180195ae043d02f97601f7/packages/material-ui/src/InputBase/InputBase.js#L291-L295
Triggering a rerender prevents the change event to trigger. I suspect an issue with React.

@ziktar
Copy link
Author

ziktar commented Nov 25, 2019

This was tested on macOS with Chrome 78.0.3904.108 as well. I replaced the TextField components with input elements, and then Undo worked as expected.

See attached where for both I wrote "test" in field 1, then "test" in field 2, then appended "2" to field 1, then "2' to field 2, then hit Cmd+Z 4 times. For TextField, it undid the "2" from field 2 then bounced focus back and forth. For input, it undid the changes.
textfield
input

@ziktar
Copy link
Author

ziktar commented Nov 25, 2019

Additionally, FYI, undo in Firefox seems to be broken due React; both TextField and input work the same, where undo simply deletes everything in the field.

@oliviertassinari
Copy link
Member

I have opened facebook/react#17494.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! external dependency Blocked by external dependency, we can’t do anything about it
Projects
None yet
Development

No branches or pull requests

2 participants