feat(validator): add ValidationContext type and support optional context in validate()#1222
Merged
Conversation
|
|
||
| it('Uses context params format when provided', () => { | ||
| expect( | ||
| requiredDateInput.validate('1991-13', { |
Contributor
There was a problem hiding this comment.
This PR is great 😄
One thing, for full it should probably be:
Suggested change
| requiredDateInput.validate('1991-13', { | |
| requiredDateInput.validate('1991-13-', { |
Collaborator
Author
There was a problem hiding this comment.
I updated the test to cover both scenarios, and added some tests for compact too :D Thanks for the review, appreciate it!
ethanWallace
approved these changes
Apr 15, 2026
Collaborator
ethanWallace
left a comment
There was a problem hiding this comment.
LGTM
- I have tested the changes and functionality using the test instructions.
- I have confirmed test coverage is adequate.
- I have reviewed the code for clarity, maintainability and potential issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary | Résumé
When reviewing the PR that introduces the new format (
iso) for DateInput, I noticed that we can't support a "format" check for the DateInput validator. I think it'll be great to add support for different formats in the validator code itself and not the component code so it can be re-used by other components.This PR introduces a
ValidationContexttype to support passing additional contextual information into validation logic, (i.e. the component and other validation parameters).It also updates the validation API from:
to:
This change is backwards compatible. Existing functionality is not affected because the new context argument is optional and supported through TypeScript function overloading.
This change is needed to make validation logic more flexible and easier to extend without changing any code that uses the existing
validatefunction. By providing contextual information to validators, we can support more component-aware validation behaviour and reduce the need for ad hoc patterns or future API changes.No screenshots are included because this change is internal/API-focused and does not introduce a visual change.
🧩 Related Issues | Cartes liées
Related issues
🧪 Test instructions | Instructions pour tester la modification
mainbranchnpm installnpm run testgh pr checkout <pr_number>orgit checkout -b feat/update-validatornpm install✍️ Author checklist | Liste de vérification de l'auteur
Choose one:
fix:)feat:)feat!:)chore:,docs:,ci:)Breaking changes flag:
Ready for review: (all items must be checked)
🧐 Reviewer checklist | Liste de vérification du réviseur
Developer checklist
For PRs that are complex, in lieu of a simple approval or an "LGTM" ✅, paste the following info with your approval:
Design checklist (if needed)
For designers, include the following info with your approval:
Content checklist (if needed)
For content, include the following info with your approval:
This PR introduces a small API expansion to the
validate()function by allowing an optional context argument to be passed into validate().There are no breaking changes: