material-components / material-components/material-web
event.preventDefault() has no effect on interactive components
Nobody has claimed this yet.
- Dominant language
- SCSS
- Stars
- 11.3k
- Forks
- 1.1k
- Avg merge
- 20h 28m
- Merged PRs (30d)
- 13
Description
### What is affected?
Component
### Description
On a native radio input, if a 'click' (or any other) event default action is being prevented by a listener, it immediately affects the input by preventing the default actions to take place.
``'s built-in event handling is not affected by preventing default of an event. Was [this code](https://github.com/material-components/material-web/blob/5f93c82546bbb428dcc8461b2e34cfe49178b0eb/radio/internal/radio.ts#L142C5-L146C6) supposed to allow the user to process the event before taking actions? If so, I believe it should wait for a macrotask instead,
Furthermore, same behavior could be observed in any component's event handling, where `await 0` or `await null` is used.
### Reproduction
The described behavior can be observed [here](https://stackblitz.com/edit/webpack-webpack-js-org-xwa6ut?file=dist%2Findex.html)
### Workaround
None
### Is this a regression?
No or unsure. This never worked, or I haven't tried before.
### Affected versions
1.1.1
### Browser/OS/Node environment
Browser: Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0
OS: Windows NT 10.0; Win64; x64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked radio/internal/radio.ts event-handling code and reproduce the behavior using the linked StackBlitz example. Compare native radio default-action timing with the component behavior, then inspect other component handlers that use await 0 or await null. Done means preventing the event default reliably affects the component's built-in action without breaking normal interaction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100