angular / angular/components

CDK/testing: typeInElement ignores event.defaultPrevented

Open
#27,475 1 comment 0 reactions 0 assignees View on GitHub
area: cdk/testing G P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

The `typeInElement` [1] still sets the input value even if the `keydown` event has default prevented. This is different from the actual behavior [2]

[1]: https://github.com/angular/components/blob/ffffc82084b3528a4b5a95a91ec77359449acc97/src/cdk/testing/testbed/fake-events/type-in-element.ts#L114
[2]: https://stackblitz.com/edit/web-platform-gwblaq?file=script.js

### Reproduction

StackBlitz link: https://stackblitz.com/edit/harness-issue-4xv58x?file=src%2Fapp%2Fharness-example.html

### Expected Behavior

`event.preventDefault()` should stop the browser from populating the input element.

### Actual Behavior

Input element is still populated with values

### Environment

- Angular: 10.2.3
- CDK/Material: 11.0.0
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS

Contributor guide

Open the contributing guide

Research direction

Start in src/cdk/testing/testbed/fake-events/type-in-element.ts at the linked line, then run the provided StackBlitz reproduction to compare the harness behavior with the browser behavior. The issue is done when a keydown event with defaultPrevented set no longer populates the input element.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.