Skip to content

fix(material/input): input harness not dispatching change event - #34042

Open
ewerton336 wants to merge 1 commit into
angular:mainfrom
ewerton336:fix/input-harness-change-event
Open

ewerton336 wants to merge 1 commit into
angular:mainfrom
ewerton336:fix/input-harness-change-event

Conversation

@ewerton336

Copy link
Copy Markdown

MatInputHarness.setValue updates the value by clearing the input, sending keys and setting the
value property, but it never dispatches a change event. As a result, (change) listeners on a
matInput aren't invoked in tests, even though the value changed (see the reproduction in the issue).

This change dispatches a change event at the end of setValue, which is consistent with what
MatDatepickerInputHarness.setValue already does (#20877). A unit test was added that fails without
the fix.

Fixes #30160

Fixes that `MatInputHarness.setValue` didn't dispatch a `change` event after
updating the value. This meant that listeners bound to `(change)` on the input
weren't invoked, even though the value had been changed. The datepicker input
harness already dispatches the event in its `setValue` method.

Fixes angular#30160
@google-cla

google-cla Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ewerton336

Copy link
Copy Markdown
Author

I signed it!

@crisbeto

crisbeto commented Nov 1, 2026

Copy link
Copy Markdown
Member

I think this was intentional, because if I remember correctly, the change event gets dispatched when the user blurs the input.

@ewerton336

Copy link
Copy Markdown
Author

Thanks for taking a look! That makes sense for real user interaction, since change fires when the value is committed/blurred. The reason I went this way is that MatDatepickerInputHarness.setValue already dispatches change at the end (from #20877), so the two input harnesses currently behave differently, and with MatInputHarness tests that listen to (change) have to call blur() explicitly after setValue.

If you'd rather keep the current behavior, I'm happy to close this, or alternatively update the setValue docs to mention that blur() is needed to trigger change. Whatever you prefer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(MatInputTestHarness): setValue does not trigger "change" event

2 participants