Skip to content

Commit f27f262

Browse files
authored
docs(forms): Update examples to use form-group where appropriate (bootstrap-vue#1435)
* docs(form-checkbox): Update multiple-checkbox examples to use form-group * docs(form-radio): update examples to use b-form-group where appropriate * docs(form-input): minor ARIA updates to examples
1 parent 6bd12bb commit f27f262

File tree

3 files changed

+190
-177
lines changed

3 files changed

+190
-177
lines changed

src/components/form-checkbox/README.md

Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ export default {
3636
```html
3737
<template>
3838
<div>
39-
<h5>Using options array:</h5>
40-
<b-form-checkbox-group id="checkboxes1" name="flavour1" v-model="selected" :options="options">
41-
</b-form-checkbox-group>
42-
43-
<h5 class="mt-3">Using sub-components:</h5>
44-
<b-form-checkbox-group id="checkboxes2" name="flavour2" v-model="selected">
45-
<b-form-checkbox value="orange">Orange</b-form-checkbox>
46-
<b-form-checkbox value="apple">Apple</b-form-checkbox>
47-
<b-form-checkbox value="pineapple">Pineapple</b-form-checkbox>
48-
<b-form-checkbox value="grape">Grape</b-form-checkbox>
49-
</b-form-checkbox-group>
39+
<b-form-group label="Using <code>options</code> array:">
40+
<b-form-checkbox-group id="checkboxes1" name="flavour1" v-model="selected" :options="options">
41+
</b-form-checkbox-group>
42+
</b-form-group>
43+
44+
<b-form-group label="Using sub-components:">
45+
<b-form-checkbox-group id="checkboxes2" name="flavour2" v-model="selected">
46+
<b-form-checkbox value="orange">Orange</b-form-checkbox>
47+
<b-form-checkbox value="apple">Apple</b-form-checkbox>
48+
<b-form-checkbox value="pineapple">Pineapple</b-form-checkbox>
49+
<b-form-checkbox value="grape">Grape</b-form-checkbox>
50+
</b-form-checkbox-group>
51+
</b-form-group>
5052
<hr>
5153
<div>Selected: <strong>{{ selected }}</strong></div>
5254
</div>
@@ -88,13 +90,15 @@ options (value array) to `<b-form-checkboxes>`.
8890
```html
8991
<template>
9092
<div>
91-
<h5>Inline checkboxes (default)</h5>
92-
<b-form-checkbox-group v-model="selected" name="flavour1" :options="options">
93-
</b-form-checkbox-group>
94-
95-
<h5 class="mt-3">Stacked checkboxes</h5>
96-
<b-form-checkbox-group stacked v-model="selected" name="flavour2" :options="options">
97-
</b-form-checkbox-group>
93+
<b-form-group label="Inline checkboxes (default)">
94+
<b-form-checkbox-group v-model="selected" name="flavour1" :options="options">
95+
</b-form-checkbox-group>
96+
</b-form-group>
97+
98+
<b-form-group label="Stacked checkboxes">
99+
<b-form-checkbox-group stacked v-model="selected" name="flavour2" :options="options">
100+
</b-form-checkbox-group>
101+
</b-form-group>
98102
</div>
99103
</template>
100104

@@ -139,7 +143,7 @@ checkboxes are related.
139143

140144
Whenever using multple checkboxes, it is recommended that the `<b-form-check-group>`
141145
be placed in a [`<b-form-group>`](/docs/components/form-group) component to
142-
associate a `<label>` with the entire group of checkboxes.
146+
associate a label with the entire group of checkboxes.
143147

144148
## Button style checkboxes
145149
Render checkboxes with the look of a button by setting the prop `buttons` on `<b-form-checkbox-group>`.
@@ -153,24 +157,25 @@ when they are in the _checked_ state.
153157
```html
154158
<template>
155159
<div>
156-
<h5>button style checkboxes</h5>
157-
<b-form-checkbox-group buttons v-model="selected" name="butons1" :options="options">
158-
</b-form-checkbox-group>
159-
160-
<h5 class="mt-3">
161-
button style checkboxes with variant <code>primary</code> and large buttons
162-
</h5>
163-
<b-form-checkbox-group v-model="selected"
164-
buttons
165-
button-variant="primary"
166-
size="lg"
167-
name="buttons2"
168-
:options="options">
169-
</b-form-checkbox-group>
170-
171-
<h5 class="mt-3">Stacked (vertical) button style checkboxes</h5>
172-
<b-form-checkbox-group buttons v-model="selected" stacked :options="options">
173-
</b-form-checkbox-group>
160+
<b-form-group label="Button style checkboxes">
161+
<b-form-checkbox-group buttons v-model="selected" name="butons1" :options="options">
162+
</b-form-checkbox-group>
163+
</b-form-group>
164+
165+
<b-form-group label="Button style checkboxes with variant <code>primary</code> and large buttons">
166+
<b-form-checkbox-group v-model="selected"
167+
buttons
168+
button-variant="primary"
169+
size="lg"
170+
name="buttons2"
171+
:options="options">
172+
</b-form-checkbox-group>
173+
</b-form-group>
174+
175+
<b-form-group label="Stacked (vertical) button style checkboxes">
176+
<b-form-checkbox-group buttons v-model="selected" stacked :options="options">
177+
</b-form-checkbox-group>
178+
</b-form-group>
174179
</div>
175180
</template>
176181

@@ -207,11 +212,13 @@ chechbox input by setting the `plain` prop.
207212
```html
208213
<template>
209214
<div>
210-
<h5>Plain inline checkboxes</h5>
211-
<b-form-checkbox-group plain v-model="selected" :options="options" />
215+
<b-form-group label="Plain inline checkboxes">
216+
<b-form-checkbox-group plain v-model="selected" :options="options" />
217+
</b-form-group>
212218

213-
<h5 class="mt-3">Plain stacked checkboxes</h5>
214-
<b-form-checkbox-group plain stacked v-model="selected" :options="options" />
219+
<b-form-group label="Plain stacked checkboxes">
220+
<b-form-checkbox-group plain stacked v-model="selected" :options="options" />
221+
</b-form-group>
215222
</div>
216223
</template>
217224

@@ -312,30 +319,34 @@ export default {
312319
**Indeterminate checkbox use-case:**
313320
```html
314321
<template>
315-
<b-card>
316-
<b-form-checkbox v-model="allSelected"
317-
:indeterminate="indeterminate"
318-
aria-describedby="flavours"
319-
aria-controls="flavours"
320-
@change="toggleAll"
321-
>
322-
{{ allSelected ? 'Un-select' : 'Select' }}
323-
All Flavors
324-
</b-form-checkbox>
325-
<b-form-checkbox-group id="flavors"
326-
stacked
327-
v-model="selected"
328-
name="flavs"
329-
:options="flavours"
330-
class="ml-3"
331-
aria-label="Individual flavours"
332-
></b-form-checkbox-group>
333-
<p aria-live="polite">
322+
<div>
323+
<b-form-group>
324+
<template slot="label">
325+
<b>Choose your flavours:</b><br>
326+
<b-form-checkbox v-model="allSelected"
327+
:indeterminate="indeterminate"
328+
aria-describedby="flavours"
329+
aria-controls="flavours"
330+
@change="toggleAll"
331+
>
332+
{{ allSelected ? 'Un-select All' : 'Select All' }}
333+
</b-form-checkbox>
334+
</template>
335+
<b-form-checkbox-group id="flavors"
336+
stacked
337+
v-model="selected"
338+
name="flavs"
339+
:options="flavours"
340+
class="ml-4"
341+
aria-label="Individual flavours"
342+
></b-form-checkbox-group>
343+
</b-form-group>
344+
<p>
334345
Selected: <strong>{{ selected }}</strong><br>
335346
All Selected: <strong>{{ allSelected }}</strong><br>
336347
Indeterminate: <strong>{{ indeterminate }}</strong><br>
337348
</p>
338-
</b-card>
349+
</div>
339350
</template>
340351

341352
<script>

src/components/form-input/README.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export default {
2626
<!-- form-input-1.vue -->
2727
```
2828

29-
## Input type
3029

30+
## Input type
3131
`<b-form-input>` defaults to a `text` input, but you can set the `type` prop to one
3232
of the supported types: `text`, `password`, `email`, `number`, `url`, `tel`, `search`,
3333
`date`, `datetime`, `datetime-local`, `month`, `week`, `time`,`range`, or `color`.
@@ -75,7 +75,6 @@ than what is returned by it's value.
7575

7676

7777
## Control sizing
78-
7978
Set heights using the `size` prop to `sm` or `lg` for small or large respectively.
8079

8180
To control width, place the input inside standard Bootstrap grid column.
@@ -106,7 +105,6 @@ To control width, place the input inside standard Bootstrap grid column.
106105
```
107106

108107
## Contextual States
109-
110108
Bootstrap includes validation styles for `valid` and `invalid` states
111109
on most form controls.
112110

@@ -151,18 +149,20 @@ to:
151149
```html
152150
<template>
153151
<div role="group">
154-
<b-form-input v-model.trim="name"
152+
<label for="inputLive">Name:</label>
153+
<b-form-input id="inputLive"
154+
v-model.trim="name"
155155
type="text"
156156
:state="nameState"
157-
aria-describedby="input-help input-feeback"
157+
aria-describedby="inputLiveHelp inputLiveFeeback"
158158
placeholder="Enter your name"></b-form-input>
159-
<b-form-invalid-feedback id="input-feedback">
159+
<b-form-invalid-feedback id="inputLiveFeedback">
160160
<!-- This will only be shown if the preceeding input has an invalid state -->
161161
Enter at least 3 letters
162162
</b-form-invalid-feedback>
163-
<b-form-text id="input-help">
163+
<b-form-text id="inputLiveHelp">
164164
<!-- this is a form text block (formerly known as help block) -->
165-
Enter your name.
165+
Your full name.
166166
</b-form-text>
167167
</div>
168168
</template>
@@ -189,7 +189,6 @@ export default {
189189
automatically generate markup similar to above.
190190

191191
### Conveying contextual state to assistive technologies and colorblind users
192-
193192
Using these contextual states to denote the state of a form control only provides
194193
a visual, color-based indication, which will not be conveyed to users of assistive
195194
technologies - such as screen readers - or to colorblind users.
@@ -199,7 +198,6 @@ could include a hint about state in the form control's `<label>` text itself, or
199198
providing an additional help text block.
200199

201200
### ARIA `aria-invalid` attribute
202-
203201
Specifically for assistive technologies, invalid form controls can also be assigned
204202
an `aria-invalid="true"` attribute.
205203

@@ -217,7 +215,6 @@ then the `aria-invalid` attribute on the input will automatically be set to `'tr
217215

218216

219217
## Formatter support
220-
221218
`<b-form-input>` optionally supports formatting by passing a function reference to
222219
the `formatter` prop.
223220

@@ -235,21 +232,29 @@ No formatting occurs if a `formatter` is not provided.
235232
```html
236233
<template>
237234
<div>
238-
<h5>Text input with formatter (on input)</h5>
239-
<b-form-input v-model="text1"
235+
<label for="inputFormatter">Text input with formatter (on input)</label>
236+
<b-form-input id="inputFormatter"
237+
v-model="text1"
240238
type="text"
241239
placeholder="Enter your name"
240+
aria-describedby="inputFormatterHelp"
242241
:formatter="format"></b-form-input>
243-
<b-form-text>We will convert your name to lowercase instantly</b-form-text>
242+
<b-form-text id="inputFormatterHelp">
243+
We will convert your name to lowercase instantly
244+
</b-form-text>
244245
<p>Value: {{ text1 }}</p>
245246

246-
<h5>Text input with lazy formatter (on change)</h5>
247-
<b-form-input v-model="text2"
247+
<label for="inputLazy">Text input with lazy formatter (on change)</label>
248+
<b-form-input id="inputLazy"
249+
v-model="text2"
248250
type="text"
249251
placeholder="Enter your name"
252+
aria-describedby="inputLazyHelp"
250253
:formatter="format"
251254
lazy-formatter></b-form-input>
252-
<b-form-text>This one is a little lazy!</b-form-text>
255+
<b-form-text id="inputLazyHelp">
256+
This one is a little lazy!
257+
</b-form-text>
253258
<p>Value: {{ text2 }}</p>
254259
</div>
255260
</template>
@@ -273,18 +278,20 @@ export default {
273278
<!-- form-input-formatter.vue -->
274279
```
275280

276-
**Note:** When using a non-text-like input (i.e. `color`, `range`, `date`, etc),
277-
ensure that your formatter function returns the value in the expected format
278-
for the input type. The formatter **must** return the value as a string.
281+
**Note:** When using a non-text-like input (i.e. `color`, `range`, `date`,
282+
`number` etc), ensure that your formatter function returns the value in the
283+
expected format for the input type. The formatter **must** return the value
284+
as a string.
279285

280286

281287
## Readonly plain text
282-
283288
If you want to have `<b-form-input readonly>` elements in your form styled as plain
284289
text, set the `plaintext` prop (no need to set `readonly`) to remove the default form
285290
field styling and preserve the correct margin and padding.
286291

292+
287293
## Component alias
288294
You can also use `<b-form-input>` by it's shorter alias of `<b-input>`.
289295

296+
290297
## Component Reference

0 commit comments

Comments
 (0)