VA Forms Library - Web components in RJSF
This page documents information related to web component adoption by forms teams, using ui:webComponentField
in RJSF, including status, how to adopt, decisions, and defects
Status
All work is currently in branch
54747-ds-web-component-forms-library-integration
, not merged to main:
https://github.com/department-of-veterans-affairs/vets-website/tree/54747-ds-web-component-forms-library-integration
Related Epic
Decisions
Late March 2023 - We will inject the web component at the field template level rather than the widget level, So that the web component can own the entire field including the error, and we just pass it all the information. (widgets are only the input area and accept different props than the field, and would feel like an incomplete adoption of web components)
April 2023 - We will unit test by verifying at the
va-web-component
level rather than theshadowRoot
level, due to shadow root being difficult to test. Cypress however can test the shadow root.Late April 2023 - We will use v3 of the web components, which is
usdws: true
. There are many issues with v1 web components, that v3 solves, and it will better align with both DST + forms team's timeline to work on v3 at the same time to find the issues.
How to use
Web component fields
To any existing uiSchema
, include the property 'ui:webComponentField'
with a component from platform/forms-system/src/js/web-component-fields/
:
uiSchema: {
...existing fields
'ui:webComponentField': VaRadioField,
}
// other examples
'ui:webComponentField': VaTextInputField,
'ui:webComponentField': VaSelectField,
'ui:webComponentField': VaCheckboxField,
etc...
You should be able to change most existing schemas to the web component version simply by adding the 'ui:webComponentField'
.
Important: Do not use the React binding version component directly in this field property.
Example: VaTextInputField
is not the same thing VaTextInput
. The field contains extra mapping to translate RJSF properties to the React binding version of the web component.
Other notes
'ui:widget'
will not affect the input of the web component field, because the logic is shortcutted in src/js/components/FieldTemplate.jsx
. However 'ui:widget'
will still affect how the review page is displayed.
Web components may display description or title differently and may not accept HTML. This is by design. Some web components do not accept a description.
Check storybook to see properties of web components: https://design.va.gov/storybook/?path=/docs/components-va-text-input--default
Web component patterns
Instead of using 'ui:webComponentField'
, you can use some predefined patterns from platform/forms-system/src/js/web-component-patterns/
, which are similar to existing definitions
we have today:
import {
dateOfBirthSchema,
dateOfBirthUI,
emailSchema,
emailUI,
fullNameSchema,
fullNameUI,
phoneSchema,
phoneUI,
ssnOrVaFileNumberOrServiceNumberSchema,
ssnOrVaFileNumberOrServiceNumberUI,
} from 'platform/forms-system/src/js/web-component-patterns';
return default {
uiSchema: {
fullName: fullNameUI()
},
schema: {
type: 'object',
properties: {
fullName: fullNameSchema
}
}
Patterns come in pairs:
patternUI()
functionpatternSchema
object.
Patterns may not exactly match the prior non-web-component versions, so check usage by hovering the functions.
Defects
Not all uiOptions are tested yet.
CSS issues
Not tested for accessability
Shadow dom is difficult for accessability
https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/1780
https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/1775
https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/1713
https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/1712
https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/1704
Help and feedback
Get help from the Platform Support Team in Slack.
Submit a feature idea to the Platform.