-
Notifications
You must be signed in to change notification settings - Fork 841
feat(ui): dispatch validation events from TextField #609
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new a2ui-validation-input event dispatched from the TextField component to communicate validation state changes. The changes look good and achieve the goal. I've added a couple of minor suggestions to improve code style and robustness.
ditman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about having a specific, shared type for the failed/passed validation event in web_core!
| return; | ||
| } | ||
|
|
||
| this.dispatchEvent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of this block seems wrong.
| } | ||
|
|
||
| this.dispatchEvent( | ||
| new CustomEvent("a2ui-validation-input", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be an A2UIValidationEvent extends CustomEvent, with a specific signature for the detail property, so it can be accessed safely later?
There's an example of an extension of CustomEvent here. In this case, I think the event should be in web_core, so it can be shared with other renderers; or is this a Lit-only functionality?
|
|
||
| // Debug Validation Events | ||
| #handleValidationInput = (e: Event) => { | ||
| const detail = (e as CustomEvent).detail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This is where having a custom event type would help to access detail in a type-safe way)
This PR introduces the a2ui-validation-input event to the
TextField
component to bubble validation state changes.
Changes
TextField (
text-field.ts
):
Added dispatch of a2ui-validation-input on every input event.
Payload: { componentId, value, valid: boolean }.
Reason: Native invalid events do not cross the Shadow DOM boundary. This custom event allows parent components (like the Shell) to observe real-time validation status.
Component Gallery (
component-gallery.ts
):
Added a listener for a2ui-validation-input at the document root.
Logs validation events to both the Console and the internal Debug Panel for visual verification.
Verification
Verified manually in the Component Gallery:
Typing in "TextField (Regex)" now triggers logs in the Debug Panel.
Valid/Invalid states strictly match the regex rules.
Pre-launch Checklist
If you need help, consider asking for advice on the discussion board.