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(input, input-number, input-text, text-area): ensure all applicable props are considered in form validation #8655

Merged

Conversation

jcfranco
Copy link
Member

Related Issue: #8647

Summary

This ensures pattern, minlength, maxlength, min, max, step are set on the internal form input based on the matching type.

Note: minlength and maxlength won't trigger constraint validation unless a user interacts with the input (see minlength spec and maxlength spec). This will have to be a known limitation until #8126 is completed.

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Jan 26, 2024
Copy link
Member

@benelan benelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a couple comments; I'll take another look once this becomes ready for review. Thanks for putting this together so quickly!

export interface TextualInputComponent {
pattern?: string;
minLength: number;
maxLength: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably deprecate minLength and maxLength on calcite-input-number. That's on me - I didn't check the constraint validation doc when I ported the input code over to the new component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Good catch. 🎣

const textualInputComponent = inputComponent as TextualInputComponent;

if (hiddenFormInput.minLength != null) {
hiddenFormInput.minLength = textualInputComponent.minLength;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be minlength (and maxlength below) on the hidden input right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally setting it via the props (vs attributes), but switched the approach since there are some props that can't be reset via the prop. 🥲

@jcfranco jcfranco requested a review from benelan January 30, 2024 20:56
@jcfranco jcfranco added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Jan 30, 2024
@jcfranco jcfranco marked this pull request as ready for review February 5, 2024 18:55
@jcfranco jcfranco requested a review from a team as a code owner February 5, 2024 18:55
@jcfranco jcfranco added the low risk Issues with low risk for consideration in low risk milestones label Feb 6, 2024
Copy link
Member

@benelan benelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Once this is installed I can work on using these utils in input-date-picker and input-time-picker so we can add validation for the min/max constraints.

I'll try comparing the date/time to min/max during the sync process, and then call setValidity() on the hidden input if invalid. That would be a pretty clean approach if it works.

@jcfranco jcfranco merged commit 6de8534 into main Feb 10, 2024
16 of 18 checks passed
@jcfranco jcfranco deleted the jcfranco/8647-set-all-validation-props-on-hidden-form-input branch February 10, 2024 04:57
Elijbet pushed a commit that referenced this pull request Feb 15, 2024
…e props are considered in form validation (#8655)

**Related Issue:** #8647 

## Summary

This ensures `pattern`, `minlength`, `maxlength`, `min`, `max`, `step`
are set on the internal form input based on the matching type.

**Note**: `minlength` and `maxlength` won't trigger constraint
validation unless a user interacts with the input (see [`minlength`
spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#setting-minimum-input-length-requirements:-the-minlength-attribute:~:text=Constraint%20validation%3A%20If%20an%20element%20has%20a%20minimum,element%20is%20suffering%20from%20being%20too%20short.)
and [`maxlength`
spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#setting-minimum-input-length-requirements:-the-minlength-attribute:~:text=Constraint%20validation%3A%20If%20an%20element%20has%20a%20maximum,element%20is%20suffering%20from%20being%20too%20long.)).
This will have to be a known limitation until #8126 is completed.
jcfranco pushed a commit that referenced this pull request Feb 15, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>@esri/calcite-components: 2.5.0</summary>

##
[2.5.0](https://github.com/Esri/calcite-design-system/compare/@esri/[email protected]...@esri/[email protected])
(2024-02-15)


### Features

* **stepper:** Add horizontal-single layout
([#8742](#8742))
([c34bc4f](c34bc4f))
* **table:** Add `interactionMode` property to control focus behavior
([#8686](#8686))
([0cb78c0](0cb78c0))
* **table:** Improve accessibility of interaction-mode: static Table
([#8754](#8754))
([eead1b5](eead1b5))
* **tile:** Add responsive layout features
([#8691](#8691))
([f4f872e](f4f872e))


### Bug Fixes

* **color-picker:** Alpha-channel slider scope updates to reflect
current opacity
([#8700](#8700))
([cd0b532](cd0b532))
* **combobox:** Avoid inline-start padding on combobox label when icon
is displayed
([#8672](#8672))
([9eb680a](9eb680a))
* Don't override existing validationMessage when displaying after form
submission
([#8690](#8690))
([3076220](3076220))
* Fix dragging items on a mobile device
([#8751](#8751))
([dc11612](dc11612))
* Fix styling when dragging items on a mobile device
([#8750](#8750))
([7c01e6e](7c01e6e))
* **input, input-number, input-text, text-area:** Ensure all applicable
props are considered in form validation
([#8655](#8655))
([6de8534](6de8534))
* **list-item:** Fix slotted list border styling.
([#8712](#8712))
([855f98d](855f98d))
* **loader:** Optimize animation performance
([#8714](#8714))
([1ed8a01](1ed8a01))
* **preset:** Add back legacy token for calcite-ui-focus-color
([#8694](#8694))
([1d1b933](1d1b933))
* Prevent interaction when component is disabled after initialization
(Firefox)
([#8746](#8746))
([aa84182](aa84182))
* **stepper:** No longer adds default `min-width` for items when
`layout='horizontal'`
([#8758](#8758))
([23a7439](23a7439))


### Reverts

* Fix(panel, flow-item): remove overflow rule
([#8711](#8711))
([21226ce](21226ce))
</details>

<details><summary>@esri/calcite-components-angular: 2.5.0</summary>

##
[2.5.0](https://github.com/Esri/calcite-design-system/compare/@esri/[email protected]...@esri/[email protected])
(2024-02-15)


### Miscellaneous Chores

* **@esri/calcite-components-angular:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @esri/calcite-components bumped from ^2.5.0-next.6 to ^2.5.0
</details>

<details><summary>@esri/calcite-components-react: 2.5.0</summary>

##
[2.5.0](https://github.com/Esri/calcite-design-system/compare/@esri/[email protected]...@esri/[email protected])
(2024-02-15)


### Miscellaneous Chores

* **@esri/calcite-components-react:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @esri/calcite-components bumped from ^2.5.0-next.6 to ^2.5.0
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
jcfranco added a commit that referenced this pull request Feb 21, 2024
…ave no effect (#8734)

**Related Issue:** N/A

## Summary

Deprecates `minLength`/`maxLength` since they have no effect on numeric
inputs. We can remove them at a future breaking change release.

This stems from
#8655 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. low risk Issues with low risk for consideration in low risk milestones pr ready for visual snapshots Adding this label will run visual snapshot testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants