Skip to content
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

fix: sync the hasInputValue state on input #4335

Merged
merged 2 commits into from
Aug 10, 2022

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Aug 10, 2022

Description

It turns out that TimePicker prevents the change event on the input element until it loses focus, so it is possible to commit a non-empty value on Enter but have the hasInputValue state not updated.

This PR makes the hasInputValue state update on input rather than change which ensures hasInputValue is synced in the above case as well.

A follow-up to #4276

Related to vaadin/flow-components#3515

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen changed the title fix: fire has-input-value-changed event on input instead of change fix: fire has-input-value-changed event on input Aug 10, 2022
@vursen vursen force-pushed the fix/has-input-value-changed-on-input branch from 2e33dc2 to f94a70c Compare August 10, 2022 07:33
@vursen
Copy link
Contributor Author

vursen commented Aug 10, 2022

Although this PR fixes the claimed issue, I wonder if we should rather investigate why time-picker prevents the change event on Enter as it looks quite unexpected.

@vursen
Copy link
Contributor Author

vursen commented Aug 10, 2022

The change event gets prevented here:

// Stop propagation of the enter event only if the dropdown is opened, this
// "consumes" the enter event for the action of closing the dropdown
if (this.opened) {
// Do not submit the surrounding form.
e.preventDefault();
// Do not trigger global listeners
e.stopPropagation();
}

As follows from the comment, the logic is intended to prevent the form submission but in fact, preventDefault also prevents the change event.

@vursen vursen changed the title fix: fire has-input-value-changed event on input fix: update the hasInputValue state on input Aug 10, 2022
@vursen vursen changed the title fix: update the hasInputValue state on input fix: sync the hasInputValue state on input Aug 10, 2022
@vursen
Copy link
Contributor Author

vursen commented Aug 10, 2022

Anyway, the current fix is still good enough to solve the original problem on the Flow side.

As for the change event not firing on Enter, I think it is not a big issue at the moment as I can't think of a use case where the user would need to listen for change directly on the slotted input element. At least, I don't think we encourage that, but tell me if I'm wrong.

@vursen vursen marked this pull request as ready for review August 10, 2022 09:56
@vursen vursen requested a review from yuriy-fix August 10, 2022 09:56
@vursen vursen force-pushed the fix/has-input-value-changed-on-input branch from a9d7182 to 29c1ef1 Compare August 10, 2022 10:59
@sonarcloud
Copy link

sonarcloud bot commented Aug 10, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan merged commit 2b05f47 into master Aug 10, 2022
@web-padawan web-padawan deleted the fix/has-input-value-changed-on-input branch August 10, 2022 11:14
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 23.2.0.beta1 and is also targeting the upcoming stable 23.2.0 version.

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.

4 participants