question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chip preventing default on keydown events

See original GitHub issue

Currently I have an Input sitting inside the label of a Chip, and the way “backspace” is handled causes several issues with this text input. I’m able to stop the onDelete function being called, but cannot fix the fact Input is never getting an event.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

I would prefer Chip not handle “backspace” keydown events, but if this is desired functionality, being able to override the onKeyDown event unconditionally would suffice.

Current Behavior

The default event is prevented and the onChange function is never called.

Steps to Reproduce (for bugs)

I spun this up to demo the issue: https://codesandbox.io/s/42708vl2l9

Context

I’m creating a filter system for a desktop-only application, where the filters are editable and represented by Chips. Currently these filters are pretty simple, so editing them inline is pretty clean and simple from a user perspective.

screen shot 2018-02-16 at 15 09 58

screen shot 2018-02-16 at 15 10 34

Your Environment

Tech Version
Material-UI 1.0.0-beta.32
React 16.2.0
browser Chrome

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Feb 16, 2018

@maxdubrinsky I agree. I think that it’s an issue on our end. I think that the event listener https://github.com/mui-org/material-ui/blob/2de755d97f0d676f221b41446c78f9b54fa54a37/src/Chip/Chip.js#L101 should only listen to events triggered on the root element, not the child ones. We can prune the excution with the following logic: event.currentTarget === event.target <> this.chipRef === event.target.

0reactions
oliviertassinaricommented, Feb 16, 2018

@maxdubrinsky I don’t the link with mocha. Maybe you can hit us with what you have and I can have a look?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chip preventing default on keydown events #10324 - GitHub
Currently I have an Input sitting inside the label of a Chip, and the way "backspace" is handled causes several issues with this...
Read more >
Why can I preventDefault event on keydown but not on keyup ...
When the key is pressed code can prevent an action, because it simply hasn't happened yet, whereas on the keyup() event, it already...
Read more >
Disable propagation of pressing keys to parent form when in ...
I'm trying to implement a component for entering tags. Selected tags are shown first, then a combo box should allow to either enter...
Read more >
Issue 118639 in chromium: keydown and keyup events do not ...
It seems there's never a keypress event. keypress is great when you want to ... For each key event we get, we intercept,...
Read more >
Chips | Angular Material
Users can move through the chips using the arrow keys and select/deselect them with space. Chips also gain focus when clicked, ensuring keyboard...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found