Skip to content

Commit 5e48e57

Browse files
committed
docs(many): add required field examples and * required field note to form component docs
INSTUI-4944
1 parent ce01c3e commit 5e48e57

16 files changed

Lines changed: 180 additions & 3 deletions

File tree

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
---
2-
title: Form Errors
2+
title: Forms
33
category: Guides
44
order: 4
55
relevantForAI: true
66
---
77

8-
# Adding Error Messages to Form Components
8+
## Required Fields
9+
10+
InstUI form components display an asterisk (`*`) next to labels when the `isRequired` (or `required`) prop is set. Whenever a form contains required fields, you **must include a note** explaining what the asterisk means — typically "Fields marked with an asterisk (\*) are required."
11+
12+
> **Exception:** You can omit this note when the form's purpose is entirely self-evident — for example, a standard login screen where it is obvious that both the email and password fields are required.
13+
14+
```ts
15+
---
16+
type: example
17+
---
18+
const RequiredFieldsExample = () => {
19+
return (
20+
<FormFieldGroup description="Contact Information" rowSpacing="small" layout="stacked">
21+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
22+
<TextInput renderLabel="Full Name" isRequired />
23+
<TextInput renderLabel="Email Address" isRequired />
24+
<TextInput renderLabel="Phone Number" />
25+
</FormFieldGroup>
26+
)
27+
}
28+
29+
render(<RequiredFieldsExample />)
30+
```
31+
32+
## Error Messages
933

1034
InstUI offers a range of form elements and all of them have a similar API to handle error/hint/success messages. These components use the `messages` prop with the following type definition:
1135

@@ -86,6 +110,8 @@ const Example = () => {
86110
</CheckboxGroup>
87111
<div style={{display: 'flex', gap: '2rem', marginTop: '3rem', flexDirection: 'column'}}>
88112

113+
{isRequired && <Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>}
114+
89115
<TextInput renderLabel="TextInput" messages={messages} isRequired={isRequired}/>
90116

91117
<NumberInput renderLabel="NumberInput" messages={messages} isRequired={isRequired}/>
@@ -138,6 +164,11 @@ const Example = () => {
138164
invalidDateTimeMessage="Invalid date!"
139165
prevMonthLabel="Previous month"
140166
nextMonthLabel="Next month"
167+
screenReaderLabels={{
168+
calendarIcon: 'Open calendar',
169+
prevMonthButton: 'Previous month',
170+
nextMonthButton: 'Next month'
171+
}}
141172
defaultValue="2018-01-18T13:30"
142173
layout="columns"
143174
isRequired={isRequired}
@@ -152,6 +183,11 @@ const Example = () => {
152183
invalidDateTimeMessage="Invalid date!"
153184
prevMonthLabel="Previous month"
154185
nextMonthLabel="Next month"
186+
screenReaderLabels={{
187+
calendarIcon: 'Open calendar',
188+
prevMonthButton: 'Previous month',
189+
nextMonthButton: 'Next month'
190+
}}
155191
defaultValue="2018-01-18T13:30"
156192
layout="stacked"
157193
isRequired={isRequired}

packages/__docs__/buildScripts/ai-accessible-documentation/summaries-for-llms-file.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433
"summary": "Comprehensive focus management system for dialogs, modals, and popovers. Uses Dialog component with FocusRegion and FocusRegionManager to trap focus, handle escape keys, and manage screen reader accessibility."
434434
},
435435
{
436-
"title": "form-errors",
436+
"title": "forms",
437437
"summary": "InstUI form components use a `messages` prop for error/hint/success messages. Required fields now show an asterisk automatically. Examples provided for various form components like TextInput, Checkbox, and DateTimeInput."
438438
},
439439
{

packages/ui-checkbox/src/Checkbox/v1/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ type: example
162162
/>
163163
```
164164

165+
### Required Fields
166+
167+
Whenever a `Checkbox` is required, you must include a note explaining what the asterisk means — typically "Fields marked with an asterisk (\*) are required."
168+
169+
```js
170+
---
171+
type: example
172+
---
173+
<FormFieldGroup description="Terms" rowSpacing="small" layout="stacked">
174+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
175+
<Checkbox label="I agree to the terms and conditions" value="terms" isRequired />
176+
</FormFieldGroup>
177+
```
178+
165179
### Guidelines
166180

167181
```js

packages/ui-checkbox/src/Checkbox/v2/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ type: example
166166

167167
The underlying `<input>` has a `data-checked` attribute (`"true"`, `"false"`, or `"mixed"` when indeterminate) that can be queried from the DOM to read the current state.
168168

169+
### Required Fields
170+
171+
Whenever a `Checkbox` is required, you must include a note explaining what the asterisk means — typically "Fields marked with an asterisk (\*) are required."
172+
173+
```js
174+
---
175+
type: example
176+
---
177+
<FormFieldGroup description="Terms" rowSpacing="small" layout="stacked">
178+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
179+
<Checkbox label="I agree to the terms and conditions" value="terms" isRequired />
180+
</FormFieldGroup>
181+
```
182+
169183
### Guidelines
170184

171185
```js

packages/ui-color-picker/src/ColorPicker/v1/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ type: example
201201

202202
return (
203203
<View as="div">
204+
{isRequired && <Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>}
204205
<ColorPicker
205206
onChange={(val) => setValue(val)}
206207
value={value}

packages/ui-color-picker/src/ColorPicker/v2/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ type: example
201201

202202
return (
203203
<View as="div">
204+
{isRequired && <Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>}
204205
<ColorPicker
205206
onChange={(val) => setValue(val)}
206207
value={value}

packages/ui-date-time-input/src/DateTimeInput/v1/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type: example
8282
<br />
8383
{text}
8484
</div>
85+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
8586
<div style={{ height: '14rem' }}>
8687
<DateTimeInput
8788
description={

packages/ui-form-field/src/FormFieldGroup/v1/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ type: example
100100
</FormFieldGroup>
101101
```
102102

103+
### Required Fields
104+
105+
Whenever a `FormFieldGroup` contains required fields, you must include a note explaining what the asterisk means — typically "Fields marked with an asterisk (\*) are required."
106+
107+
```js
108+
---
109+
type: example
110+
---
111+
<FormFieldGroup
112+
description="Contact Information"
113+
rowSpacing="small"
114+
layout="stacked"
115+
>
116+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
117+
<TextInput renderLabel="Full Name" isRequired />
118+
<TextInput renderLabel="Email Address" isRequired />
119+
<TextInput renderLabel="Phone Number" />
120+
</FormFieldGroup>
121+
```
122+
103123
### Guidelines
104124

105125
```js

packages/ui-form-field/src/FormFieldGroup/v2/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ type: example
100100
</FormFieldGroup>
101101
```
102102

103+
### Required Fields
104+
105+
Whenever a `FormFieldGroup` contains required fields, you must include a note explaining what the asterisk means — typically "Fields marked with an asterisk (\*) are required."
106+
107+
```js
108+
---
109+
type: example
110+
---
111+
<FormFieldGroup
112+
description="Contact Information"
113+
rowSpacing="small"
114+
layout="stacked"
115+
>
116+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
117+
<TextInput renderLabel="Full Name" isRequired />
118+
<TextInput renderLabel="Email Address" isRequired />
119+
<TextInput renderLabel="Phone Number" />
120+
</FormFieldGroup>
121+
```
122+
103123
### Guidelines
104124

105125
```js

packages/ui-number-input/src/NumberInput/v1/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const Example = () => {
125125
label="Inline display"
126126
onChange={toggleInline}
127127
/>
128+
<Text>Fields marked with an asterisk <span aria-hidden="true">(*)</span> are required.</Text>
128129
<NumberInput
129130
renderLabel={`How old are you? (${MIN}-${MAX})`}
130131
display={inline ? 'inline-block' : null}

0 commit comments

Comments
 (0)