Skip to content

Commit bc41883

Browse files
authored
docs: Update live examples for ARIA compliance. (bootstrap-vue#672)
* docs(form-fieldset): add IDs to form-fieldsets and inputs * docs(form-file): Add ID's to to file-input in examples * docs(form-radio): Add IDs to radio groups in live example * docs(form-checkbox): Update examples for ARIA compliance * docs(form-input): Update live examples and docs
1 parent aafea81 commit bc41883

File tree

4 files changed

+89
-53
lines changed

4 files changed

+89
-53
lines changed

docs/components/form-checkbox/README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Form Checkbox Input
22

3-
> For cross browser consistency, `b-form-checkbox` uses Bootstrap's custom
3+
> For cross browser consistency, `<b-form-checkbox>` uses Bootstrap's custom
44
checkbox input to replace the browser default checkbox input. It is built on top of
55
semantic and accessible markup, so it is a solid replacement for the default checkbox input.
66

77
**Example 1:** Single checkbox
88
```html
99
<template>
1010
<div>
11-
<b-form-checkbox v-model="state" value="accepted" unchecked-value="not_accepted">
11+
<b-form-checkbox id="checkbox1" v-model="state" value="accepted" unchecked-value="not_accepted">
1212
I accept terms and use
1313
</b-form-checkbox>
1414

@@ -31,11 +31,19 @@ export default {
3131
```html
3232
<template>
3333
<div>
34-
<b-form-fieldset :label="label" :description="desc" :state="state" :feedback="feedback">
35-
<b-form-checkbox v-model="selected" value="orange">Orange</b-form-checkbox>
36-
<b-form-checkbox v-model="selected" value="apple">Apple</b-form-checkbox>
37-
<b-form-checkbox v-model="selected" value="pineapple">Pineapple</b-form-checkbox>
38-
<b-form-checkbox v-model="selected" value="grape">Grape</b-form-checkbox>
34+
<b-form-fieldset id="fieldset2"
35+
:label="label"
36+
label-for="checkboxes2"
37+
:description="desc"
38+
:state="state"
39+
:feedback="feedback"
40+
>
41+
<div role="group" id="checkboxes2">
42+
<b-form-checkbox v-model="selected" name="flavour" value="orange">Orange</b-form-checkbox>
43+
<b-form-checkbox v-model="selected" name="flavour" value="apple">Apple</b-form-checkbox>
44+
<b-form-checkbox v-model="selected" name="flavour" value="pineapple">Pineapple</b-form-checkbox>
45+
<b-form-checkbox v-model="selected" name="flavour" value="grape">Grape</b-form-checkbox>
46+
</div>
3947
</b-form-fieldset>
4048
<hr>
4149
<div>Selected: <strong>{{ selected }}</strong></div>
@@ -47,7 +55,7 @@ export default {
4755
data: {
4856
label: 'Choose Your Flavours:',
4957
desc: 'Select at most <b>2</b> flavours',
50-
selected: []
58+
selected: [] // Must be an array reference!
5159
},
5260
computed: {
5361
feedback() {
@@ -88,9 +96,17 @@ Only the value(s) of the chcekboxes will be returned in the `v-model` bound arra
8896
should provide unique values for each checkbox's `value` prop.
8997

9098

91-
### Control sizing
92-
Set heights/text size by setting the `size` prop to `sm` or `lg` for small or
93-
large respectively.
99+
### Multiple checkboxes and accessibility
100+
When binding multiple checkboxes together, you should set the `name` prop to the same value for
101+
all checkboxes in the group, as well as wrap the group in a `<div>` (or other block element)
102+
which has the aria attribute `role="group"`. This will inform users of assitive technologies
103+
that the checkboxes are related.
104+
105+
When placing the group of checkboxes inside a `<b-form-fieldset>`, set a unique `id` on the
106+
element with `role="group"` and set the `label-for` prop of the `<b-form-fieldet>` to
107+
this `id` value (see **Example 2** above). Whenever using grouped checkboxes, it is
108+
recommended that they be placed in a `<b-form-fieldset>` component to associate a `<label>`
109+
with the entire group of checkboxes.
94110

95111

96112
### Contextual states
@@ -103,3 +119,7 @@ of the standard Bootstrap V4 `.has-*` state class applied.
103119
### Non custom check inputs
104120
You can have `b-form-checkbox` render a browser native chechbox input by setting the `plain` prop.
105121

122+
123+
### See also
124+
- [`<b-form-fieldset>`](./form-fieldset)
125+

docs/components/form-file/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ multiple files, and directory upload (for browsers that support directory mode)
77
<template>
88
<div>
99
<!-- Simple File -->
10-
<b-form-file v-model="file"></b-form-file>
10+
<b-form-file id="file_input1" v-model="file"></b-form-file>
1111
<br> Selected file: {{file && file.name}}
1212

1313
<div class="mt-3">
1414
<!-- Customized labels -->
15-
<b-form-file v-model="file2" choose-label="Attachment2"></b-form-file>
15+
<b-form-file id="file_input2" v-model="file2" choose-label="Attachment2"></b-form-file>
1616
<br> Selected file : {{file2 && file2.name}}
1717
</div>
1818
</div>
@@ -104,6 +104,12 @@ to use [:lang()](https://developer.mozilla.org/en-US/docs/Web/CSS/:lang) for mul
104104
### Non custom file input
105105
You can have `<b-form-file>` render a browser native file input by setting the `plain` prop.
106106

107+
### Accessibility
108+
When using the custom version of `<b-form-file>` input which hides the original input, it is
109+
highly recommended that you supply a unique ID string via the `id` prop. This will
110+
automatically render the extra ARIA atributes required to improve usability for
111+
persons using assitive technologies.
112+
107113
### Clearing the file selection
108114
Because of limitations in the value binding with `<input type="file">` elements, `v-model`
109115
for `<b-form-file>` is unidirectional, and cannot be used to set or clear the file(s) selection.

docs/components/form-input/README.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,42 @@
33
> Create various text style inputs such as: `text`, `password`, `number`, `url`,
44
`search`, and more. Also supports creating `textarea` controls.
55

6+
**Example:**
67
```html
78
<template>
89
<div>
9-
<b-form-input v-model="text"
10+
<h5>Text input with formatter</h5>
11+
<b-form-input v-model="text1"
1012
type="text"
1113
placeholder="Enter your name"
12-
:state="text.length?'success':'warning'"
1314
:formatter="format"
1415
></b-form-input>
1516
<small class="text-muted">We will convert your name to lowercase instantly</small>
17+
<p>Value: {{ text1 }}</p>
1618

17-
<br>
18-
<br>
19-
20-
<b-form-input v-model="text"
19+
<h5>Text input with lazy formatter (on bluer)</h5>
20+
<b-form-input v-model="text2"
2121
type="text"
2222
placeholder="Enter your name"
23-
:state="text.length?'success':'warning'"
2423
:formatter="format"
2524
lazy-formatter
2625
></b-form-input>
2726
<small class="text-muted">This one is a little lazy!</small>
27+
<p>Value: {{ text2 }}</p>
2828

29-
<br>
30-
<br>
31-
32-
<b-form-input textarea v-model="text" placeholder="Text area mode"></b-form-input>
33-
34-
<br>
35-
<p>Value: {{text}}</p>
29+
<h5>Textarea with auto row height</h5>
30+
<b-form-input textarea v-model="text3" placeholder="Text area mode"></b-form-input>
31+
<p>Value: </p>
32+
<pre>{{ text3 }}</pre>
3633
</div>
3734
</template>
3835

3936
<script>
4037
export default {
4138
data: {
42-
text: '',
39+
text1: '',
40+
text2: '',
41+
text3: ''
4342
},
4443
methods: {
4544
format(value) {
@@ -49,48 +48,58 @@ export default {
4948
}
5049
</script>
5150

52-
<!-- form-input.vue -->
51+
<!-- form-input-1.vue -->
5352
```
5453

54+
### Input type
55+
`<b-form-input>` defaults to a `text` input, but you can set it to any other text-like
56+
type, such as `password`, `number`, `url`, etc, by setting the `type` prop.
57+
58+
#### Textarea mode
59+
Render a `<textarea>` element by setting the `textarea` prop to `true`. The
60+
`type` prop is ignored when prop `textarea` is set.
61+
62+
By default the `<textarea>` will automatically size its height based on on the number
63+
lines (separated by newlines) of text it contains. You can override this behaviour by supplying
64+
a numeric value to the `rows` prop. The `rows` prop has no effect on other input types.
65+
66+
5567
### Formatter
56-
`<b-form-input>` supports optional formatting by passing a function reference to the `formatter` prop.
68+
`<b-form-input>` optionally supports formatting by passing a function reference to the `formatter` prop.
5769

58-
By default, formatting occurs when the control's input event fires. You can use the boolean
70+
By default, formatting occurs when the control's native `input` event fires. You can use the boolean
5971
prop `lazy-formatter` to restrict the formatter function to being called on the
60-
control's `change` event only.
72+
control's native `change` event (which usually occurs on blur).
6173

6274
The `formatter` function receives a single argument which is the control's current value, and
6375
should return the formatted value.
6476

65-
### Textarea
66-
Render a `<textarea>` element by setting the `textarea` prop to `true`. The
67-
`type` prop is ignored when prop `textarea` is set.
77+
No formatting occurs if a `formatter` is not provided.
6878

69-
By default the `<textarea>` will automatically size its height based on on the number
70-
lines (separated by newlines) of text it contains. You can override this behaviour by supplying
71-
a numeric value to the `rows` prop. The `rows` prop has no effect on other input types.
7279

7380
### Static Control
7481
Easily convert a `<b-form-input>` control to a Bootstrap static form
7582
control by setting the prop `static` to true.
7683

7784
You can also use the `<b-form-input-static>` component to create static form controls.
7885

86+
7987
### Control sizing
8088
Set heights using the `size` prop to `sm` or `lg` for small or large respectively.
8189

8290
To control width, place the input inside standard Bootstrap grid column.
8391

92+
8493
### Contextual States
8594
Bootstrap includes validation styles for danger, warning, and success states
86-
on most form controls. Note that these states will not appear unless the
87-
`<b-form-input>` is wrapped in a `<b-form fieldset>` which also has the same
88-
`state` value.
95+
on most form controls.
8996

90-
On `<b-form-input>`, these states will add the corresponding validtion state
91-
icon at the right of the input. Validation icons are url()s configured via
92-
Bootstrap V4's Sass variables that are applied to background-image declarations
93-
for each state.
97+
**Note that these states will not appear unless the `<b-form-input>` is
98+
wrapped in a `<b-form fieldset>` which also has the same `state` value.**
99+
100+
On `<b-form-input>`, these states will add the corresponding **validtion state icon**
101+
at the right of the input. Validation icons are url()s configured via Bootstrap V4's
102+
SaSS variables that are applied to background-image declarations for each state.
94103

95104
Generally speaking, you’ll want to use a particular state for specific types of feedback:
96105
- `danger` is great for when there’s a blocking or required field. A user must fill in
@@ -100,10 +109,10 @@ soft validation before a user attempts to submit a form.
100109
- `success` is ideal for situations when you have per-field validation throughout a form
101110
and want to encourage a user through the rest of the fields.
102111

103-
To apply one of the contextual states on `<b-form-input>`, set the `state` prop
112+
To apply one of the contextual state icons on `<b-form-input>`, set the `state` prop
104113
to `danger`, `warning`, or `success`. Remember that you will not see the validation
105114
state icon unless the input is wrapped in a `<b-form-fieldset>` which also
106-
has the same `state` applied!
115+
has the **same** `state` applied!
107116

108117
#### Conveying contextual validation state to assistive technologies and colorblind users:
109118
Using these contextual states to denote the state of a form control only provides
@@ -115,6 +124,7 @@ could include a hint about state in the form control's `<label>` text itself, or
115124
providing an additional help text block. Specifically for assistive technologies,
116125
invalid form controls can also be assigned an `aria-invalid="true"` attribute.
117126

127+
118128
### ARIA `aria-invalid` attribute
119129
When `<form-input>` has an invalid contextual state (i.e. `danger`) you may also
120130
want to set the `<b-form-input>` prop `invalid` to `true`, or a string value.

docs/components/form-radio/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ semantic and accessible markup, so it is a solid replacement for the default rad
88
<template>
99
<div>
1010
<h5>Inline radios (default)</h5>
11-
<b-form-radio v-model="selected" :options="options"></b-form-radio>
11+
<b-form-radio id="radios1" v-model="selected" :options="options"></b-form-radio>
1212

1313
<br>
1414

1515
<h5>Stacked radios</h5>
16-
<b-form-radio v-model="selected" :options="options" stacked></b-form-radio>
16+
<b-form-radio id="radios2" v-model="selected" :options="options" stacked></b-form-radio>
1717

1818
<br>
1919

2020
<h5>Small Stacked radios</h5>
21-
<b-form-radio v-model="selected" :options="options" stacked size="sm"></b-form-radio>
21+
<b-form-radio id="radios3" v-model="selected" :options="options" stacked size="sm"></b-form-radio>
2222

2323
<hr>
2424

@@ -55,13 +55,12 @@ export default {
5555
Please see options in [`<b-form-select>`](./form-select) docs for details on passing options
5656
to `<b-form-radio>`
5757

58-
### Control sizing
59-
Set heights using the `size` prop to `sm` or `lg` for small or large text respectively.
6058

6159
### Inline or stacked
6260
By default `<b-form-radio>` generates inline radio inputs. Set the prop `stacked` to make
6361
the radios appear one over the other.
6462

63+
6564
### Contextual States
6665
Bootstrap includes validation styles for danger, warning, and success states on most form controls.
6766

@@ -87,6 +86,7 @@ could include a hint about state in the form control's `<label>` text itself, or
8786
providing an additional help text block. Specifically for assistive technologies,
8887
invalid form controls can also be assigned an `aria-invalid="true"` attribute (see below).
8988

89+
9090
### ARIA `aria-invalid` attribute
9191
When `<b-form-radio>` has an invalid contextual state (i.e. `danger`) you may also
9292
want to set the `<b-form-radio>` prop `invalid` to `true`.
@@ -95,6 +95,6 @@ Supported `invalid` values are:
9595
- `false` (default) No errors detected
9696
- `true` The value has failed validation.
9797

98+
9899
### Non custom radio inputs
99100
You can have `b-form-radio` render a browser native radio input by setting the `plain` prop.
100-

0 commit comments

Comments
 (0)