Skip to content

fix: sync the hasInputValue state on input - #4335

Merged
web-padawan merged 2 commits into
masterfrom
fix/has-input-value-changed-on-input
Aug 10, 2022
Merged

web-padawan merged 2 commits into
masterfrom
fix/has-input-value-changed-on-input

Conversation

@vursen

@vursen vursen commented Aug 10, 2022 •

Copy link
Copy Markdown
Contributor

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

vursen commented Aug 10, 2022 •

Copy link
Copy Markdown
Contributor Author

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

vursen commented Aug 10, 2022 •

Copy link
Copy Markdown
Contributor Author

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

vursen commented Aug 10, 2022 •

Copy link
Copy Markdown
Contributor Author

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 requested a review from web-padawan August 10, 2022 09:56
@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
@sonarqubecloud

Copy link
Copy Markdown

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
Copy Markdown
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