vaadin / vaadin-text-field

The themable Web Component providing input controls. Part of the Vaadin components.
https://vaadin.com/components
Apache License 2.0
25 stars 23 forks source link

fix: prevent initial validation when the field is initialized as invalid (CP: 14) #611

Closed roastedcpu closed 1 year ago

roastedcpu commented 1 year ago

Backports web-components#4138 as part of an EoD task

Description

The PR prevents the initial validation that could previously take place when the field is initially provided with a non-empty value and is initially marked invalid:

const textField = document.createElement('vaadin-text-field');
textField.value = 'Initial Value';
textField.invalid = true;
document.appendChild(textField);

The initial validation is problematic because it fires a validated event that may result in an invalid state reset on the Flow side, see vaadin/flow-components#3429 (comment) for a more detailed case.

Part of #4150

Covered components

This PR only fixes the issue for the components that extend InputFieldMixin:

  • [x] text-field
  • [x] email-field
  • [x] password-field
  • [x] text-area
  • [x] number-field
  • [x] integer-field

Other components will be covered in the next PRs.

Type of change

  • [x] Bugfix

Checklist

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