-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Chip] Backspace and delete keys don't work when nesting an input #20297
Comments
I think it has to do with some of the recent changes to the
I wonder if my use case is no longer supported or if this is a bug that should be fixed? |
@bunste Thanks for the report, I think that we should have the handler of diff --git a/packages/material-ui/src/Chip/Chip.js b/packages/material-ui/src/Chip/Chip.js
index f80d27599..09abc369d 100644
--- a/packages/material-ui/src/Chip/Chip.js
+++ b/packages/material-ui/src/Chip/Chip.js
@@ -260,6 +260,10 @@ export const styles = (theme) => {
};
};
+function isDeleteKeyboardEvent(keyboardEvent) {
+ return keyboardEvent.key === 'Backspace' || keyboardEvent.key === 'Delete';
+}
+
/**
* Chips represent complex entities in small blocks, such as a contact.
*/
@@ -295,19 +299,21 @@ const Chip = React.forwardRef(function Chip(props, ref) {
}
};
- const isDeleteKeyboardEvent = (keyboardEvent) =>
- keyboardEvent.key === 'Backspace' || keyboardEvent.key === 'Delete';
-
const handleKeyDown = (event) => {
+ if (onKeyDown) {
+ onKeyDown(event);
+ }
+
+ // Ignore events from children of `Chip`.
+ if (event.currentTarget !== event.target) {
+ return;
+ }
+
if (isDeleteKeyboardEvent(event)) {
// will be handled in keyUp, otherwise some browsers
// might init navigation
event.preventDefault();
}
-
- if (onKeyDown) {
- onKeyDown(event);
- }
};
const handleKeyUp = (event) => { Do you want to work on a pull request? :) |
I can work on the this PR? cc @oliviertassinari @bunste |
@chaudharykiran I would also have tried to create a pull request, but you are welcome to do so! |
I'm using a
TextField
component as label prop for aChip
. That worked without problems for a long time. Since the type of label is specified withnode
, I assumed that I could insert any child component there. Since I recently updated to the latest version, there is the following problem: I can still add text (cut and paste works too), but I can no longer delete text with the backspace or delete keys.Current Behavior 😯
Text cannot be deleted using backspace / delete.
Expected Behavior 🤔
Text can be deleted using backspace / delete.
Steps to Reproduce 🕹
https://codesandbox.io/s/sleepy-dust-yjiee
Steps:
Context 🔦
I built a editable Chip component. First, the user sees a normal Chip. But when he clicks on it, he can edit the content on-the-fly. As I said at the beginning, it worked very well for a long time.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: