bcgov / design-system

The B.C. Design System helps public sector design and development teams build consistent, accessible products
https://gov.bc.ca/designsystem
Apache License 2.0
57 stars 38 forks source link

Support for alternative 'required' patterns #479

Open mkernohanbc opened 2 months ago

mkernohanbc commented 2 months ago

In our existing input components (eg. Select, TextField, etc.), we communicate an input's required/optional state by displaying a "(required)" appendage to the input label.

We should consider how to provide support for alternative conventions in our components, for example:

I've done some initial POC work on a solution for this, using a new requiredConvention prop to toggle between text and asterisk formats:

Image

Image

In this example, I used a switch statement and RAC's isRequired prop:

<Label className="bcds-react-aria-TextArea--Label">
       {label} {isRequired && getRequiredIndicator(requiredConvention)}
</Label>

@ty2k suggested that a more generalised solution that can be implemented across all of our input components would be to break this functionality out into a RequiredIndicator utility component.

Some things to consider for this new component:

Putting this on the backlog to revisit in a future sprint. @Philip-Cheung I'd like to get your take on these questions, so please give it some thought!