Skip to content

Commit 3e468ec

Browse files
committed
docs: update docs for new ids
1 parent 36a6aa3 commit 3e468ec

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

docs/components/field/demo/base-demo.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
```hbs template
22
<Form::Field as |field|>
3-
<field.Label>First name</field.Label>
4-
<field.Hint>What should we call you?</field.Hint>
3+
<field.Label for={{field.id}}>Label</field.Label>
4+
<field.Hint id={{field.hintId}}>Extra information about the field</field.Hint>
55
<field.Control>
66
<input
7-
class='border bg-basement text-titles-and-attributes'
7+
class='border bg-basement text-titles-and-attributes p-1 rounded-sm'
8+
id={{field.id}}
9+
aria-invalid='true'
10+
aria-describedby='{{field.hintId}} {{field.errorId}}'
811
...attributes
912
/>
1013
</field.Control>
11-
<field.Error>error</field.Error>
14+
<field.Error id={{field.errorId}}>Error message</field.Error>
1215
</Form::Field>
1316
```
1417

docs/components/field/index.md

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,74 @@
11
# Field
22

3-
Field is a component to aid in creating form components. It provides a label, hint sections for things like help text, a control block, and an error section for rendering errors. It allows you to provide your own custom controls with a consistent form-element shell.
3+
Field is a component to aid in creating form components. It provides a label, hint sections for things like help text, a control block, and an error section for rendering errors. It allows users to provide custom controls with a consistent form-element shell and is not opinionated on what underlying control element is used.
44

5-
## Yielded Components
5+
## Yielded Items
66

7+
- `id`: A unique ID to provide to the control element `id` attribute and the Label component `for` attribute.
8+
- `hintId`: A unique ID to provide to the control element `aria-describedby` attribute and the Hint component `id` attribute.
9+
- `errorId`: A unique ID to provide to the control element `aria-describedby` or `aria-errormessage` attribute and the Error component `id` attribute.
710
- `Label`: Renders a `<label>` element. Form element label text is normally rendered here.
811
- `Hint`: Renders a `<div>` element. Help text or supplemental information is normally rendered here.
9-
- `Control`: Renders a control of your choosing, for example, you can provide `<input>`, `<textarea>`, etc.
12+
- `Control`: A control block where a form element is rendered, for example, an `<input>`, `<textarea>`, etc.
1013
- `Error`: Renders a `<div>` element. Error information is normally rendered here.
1114

15+
## Accessibility
16+
17+
The Field component does not handle accessibility automatically for the label, hint, and error sections of the component; however, it does provide identifiers to assist here. Each code example on this page also shows how to take advantage of these IDs.
18+
19+
- [for](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/for)
20+
- [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby)
21+
- [aria-errormessage](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-errormessage)
22+
- [aria-invalid](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid)
23+
1224
## Optionally Rendering Components
1325

14-
The yielded components from Field can be optionally rendered by using the `{{if}}` helper. For example, control when helper text or errors may be displayed.
26+
The yielded components from Field can be optionally rendered by using the `{{#if}}` helper. The below example optionally renders the Hint and Error based on component arguments.
1527

1628
```hbs
1729
<Form::Field as |field|>
18-
<field.Label>{{@label}}</field.Label>
30+
<field.Label for={{field.id}}>{{@label}}</field.Label>
1931
2032
{{#if @helperText}}
21-
<field.Hint>{{@helperText}}</field.Hint>
33+
<field.Hint id={{field.hintId}}>{{@helperText}}</field.Hint>
2234
{{/if}}
2335
2436
<field.Control>
25-
<input class='border-critical bg-blue' ...attributes />
37+
<input id={{field.id}} aria-describedby={{field.hintId}} aria-invalid={{if @error "true"}} aria-errormessage={{if @error field.errorId}}class='border-critical bg-blue' ...attributes />
2638
</field.Control>
2739
2840
{{#if @error}}
29-
<field.Error>{{@error}}</field.Error>
41+
<field.Error id={{field.errorId}}>{{@error}}</field.Error>
3042
{{/if}}
3143
</Form::Field>
3244
```
3345

3446
### Attributes and Modifiers
3547

36-
We have `...attributes` added to each sub component of the Field, so HTML attributes and Ember modifiers can be added.
48+
Attributes are spread to each sub component of the Field via `...attributes`, so HTML attributes and Ember modifiers can be added.
3749

3850
```hbs
3951
<Form::Field as |field|>
40-
<field.Label class='mt-3' {{on 'hover' this.onLabelHover}}>First name</field.Label>
52+
<field.Label
53+
for={{field.id}}
54+
class='mt-3'
55+
data-test-label
56+
{{on 'hover' this.onLabelHover}}
57+
>First name</field.Label>
4158
{{! other components below ...}}
4259
</Form::Field>
4360
```
4461

4562
### Ordering of Components
4663

47-
Ordering of the elements can be changed by adjusting the children order. For example, if you'd prefer putting help text below the control:
64+
Ordering of the elements can be changed by adjusting the order of the children. For example, if it is preferred to put the hint block underneath the control.
4865

4966
```hbs
5067
<Form::Field as |field|>
51-
<field.Label>First name</field.Label>
68+
<field.Label for={{field.id}}>First name</field.Label>
5269
<field.Control>
53-
<input ...attributes />
70+
<input id={{field.id}} aria-describedby={{field.hintId}} ...attributes />
5471
</field.Control>
55-
<field.Hint>Hint text below the input</field.Hint>
72+
<field.Hint id={{field.hintId}}>Hint text below the input</field.Hint>
5673
</Form::Field>
5774
```

0 commit comments

Comments
 (0)