File: FormControl.md

package info (click to toggle)
cockpit 354-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 308,956 kB
  • sloc: javascript: 775,606; python: 40,351; ansic: 35,655; cpp: 11,117; sh: 3,511; makefile: 580; xml: 261
file content (489 lines) | stat: -rw-r--r-- 16,118 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
---
id: Form control
section: components
subsection: forms
cssPrefix: pf-v6-c-form-control
---## Examples

### Input

**Note:** In webkit browsers, inputs with status icons that are autocompleted will have their icons removed by the user agent stylesheet. If the field does not need to use autocomplete, turn it off with `autocomplete="off"` to avoid the problem. Otherwise, use [helper text](/components/helper-text/html-demos)  instead to ensure that the status will remain visible if the field is autocompleted.

```html
<span class="pf-v6-c-form-control">
  <input
    type="text"
    value="Standard"
    id="input-standard"
    aria-label="Standard input example"
  />
</span>
<br />
<span class="pf-v6-c-form-control">
  <input
    type="text"
    placeholder="Placeholder"
    id="input-placeholder"
    aria-label="Placeholder input example"
  />
</span>
<br />
<span class="pf-v6-c-form-control pf-m-readonly">
  <input
    readonly
    type="text"
    value="Readonly"
    id="input-readonly"
    aria-label="Readonly input example"
  />
</span>
<br />
<span class="pf-v6-c-form-control pf-m-readonly pf-m-plain">
  <input
    readonly
    type="text"
    value="Readonly plain"
    id="input-readonly-plain"
    aria-label="Readonly plain input example"
  />
</span>
<br />
<span class="pf-v6-c-form-control pf-m-disabled">
  <input
    disabled
    type="text"
    value="Disabled"
    id="input-disabled"
    aria-label="Disabled input example"
  />
</span>
<br />
<span class="pf-v6-c-form-control pf-m-success">
  <input
    type="text"
    value="Success"
    id="input-success"
    aria-label="Success state input example"
  />
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-check-circle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-warning">
  <input
    type="text"
    value="Warning"
    id="input-warning"
    aria-label="Warning state input example"
  />
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-error">
  <input
    required
    type="text"
    value="Error"
    id="input-error"
    aria-invalid="true"
    aria-label="Error state input example"
  />
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-expanded">
  <input
    type="text"
    value="Expanded"
    id="input-expanded"
    aria-label="Expanded input example"
  />
</span>
<br />
<span class="pf-v6-c-form-control pf-m-icon">
  <input
    type="text"
    value="Calendar"
    id="input-calendar"
    name="input-calendar"
    aria-label="Calendar input example"
  />
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon">
      <i class="fas fa-calendar" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-warning pf-m-icon">
  <input
    type="text"
    value="Clock (invalid)"
    id="input-clock"
    name="input-clock"
    aria-label="Clock input example"
  />
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon">
      <i class="fas fa-clock" aria-hidden="true"></i>
    </span>
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-icon">
  <input
    type="text"
    value="Custom icon"
    id="input-custom-icon"
    name="custom-icon"
    aria-label="Custom icon input example"
  />
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon">
      <i class="fas fa-bell" aria-hidden="true"></i>
    </span>
  </span>
</span>

```

### Select

```html
<span class="pf-v6-c-form-control pf-m-placeholder">
  <select
    class
    id="select-selectable-placeholder"
    name="select-selectable-placeholder"
    aria-label="Selectable placeholder select example"
  >
    <option value selected>Selectable placeholder</option>
    <option value="Mr">Mr</option>
    <option value="Miss">Miss</option>
    <option value="Mrs">Mrs</option>
    <option value="Ms">Ms</option>
    <option value="Dr">Dr</option>
    <option value="Dr" disabled>Disabled option</option>
    <option value="Other">Other</option>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-placeholder">
  <select
    class
    id="select-non-selectable-placeholder"
    name="select-non-selectable-placeholder"
    aria-label="Non-selectable placeholder select example"
  >
    <option value selected disabled>Non-selectable placeholder</option>
    <option value="Mr">Mr</option>
    <option value="Miss">Miss</option>
    <option value="Mrs">Mrs</option>
    <option value="Ms">Ms</option>
    <option value="Dr">Dr</option>
    <option value="Other">Other</option>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control">
  <select
    class
    id="select-group"
    name="select-group"
    aria-label="Select group example"
  >
    <optgroup label="Group 1">
      <option value="Option 1">The first option</option>
      <option value="Option 2" selected>Option groups (second option selected)</option>
    </optgroup>
    <optgroup label="Group 2">
      <option value="Option 3">The third option</option>
      <option value="Option 4" disabled>The fourth option (disabled)</option>
    </optgroup>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-success">
  <select
    class
    id="select-group-success"
    name="select-group-success"
    aria-label="Success state select group example"
  >
    <option value>Valid option</option>
    <optgroup label="Group 1">
      <option value="Option 1">The first option</option>
      <option value="Option 2">The second option</option>
    </optgroup>
    <optgroup label="Group 2">
      <option value="Option 3">The third option</option>
      <option value="Option 4">The fourth option</option>
    </optgroup>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-check-circle" aria-hidden="true"></i>
    </span>
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-warning">
  <select
    class
    id="select-group-warning"
    name="select-group-warning"
    aria-label="Warning state select group example"
  >
    <option value>Warning option</option>
    <optgroup label="Group 1">
      <option value="Option 1">The first option</option>
      <option value="Option 2">The second option</option>
    </optgroup>
    <optgroup label="Group 2">
      <option value="Option 3">The third option</option>
      <option value="Option 4">The fourth option</option>
    </optgroup>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
    </span>
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-error">
  <select
    class
    required
    aria-invalid="true"
    id="select-group-error"
    name="select-group-error"
    aria-label="Error state select group example"
  >
    <option value>Invalid option</option>
    <optgroup label="Group 1">
      <option value="Option 1">The first option</option>
      <option value="Option 2">The second option</option>
    </optgroup>
    <optgroup label="Group 2">
      <option value="Option 3">The third option</option>
      <option value="Option 4">The fourth option</option>
    </optgroup>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
    </span>
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-disabled pf-m-placeholder">
  <select
    class
    disabled
    id="select-disabled"
    name="select-disabled"
    aria-label="Disabled select example"
  >
    <option value selected>Disabled</option>
    <option value="Mr">Mr</option>
    <option value="Miss">Miss</option>
    <option value="Mrs">Mrs</option>
    <option value="Ms">Ms</option>
    <option value="Dr">Dr</option>
    <option value="Other">Other</option>
  </select>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__toggle-icon">
      <i class="fas fa-caret-down" aria-hidden="true"></i>
    </span>
  </span>
</span>

```

### Textarea

```html
<span class="pf-v6-c-form-control pf-m-textarea">
  <textarea
    name="textarea-standard"
    id="textarea-standard"
    aria-label="Standard textarea example"
  >Standard
</textarea>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-readonly pf-m-textarea">
  <textarea
    readonly
    name="textarea-readonly"
    id="textarea-readonly"
    aria-label="Readonly textarea example"
  >Readonly
</textarea>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-readonly pf-m-plain pf-m-textarea">
  <textarea
    readonly
    name="textarea-readonly-plain"
    id="textarea-readonly-plain"
    aria-label="Readonly plain textarea example"
  >Readonly plain
</textarea>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-disabled pf-m-textarea">
  <textarea
    disabled
    name="textarea-disabled"
    id="textarea-disabled"
    aria-label="Disabled textarea example"
  >Disabled
</textarea>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-success pf-m-textarea">
  <textarea
    name="textarea-success"
    id="textarea-success"
    aria-label="Success state textarea example"
  >Success
</textarea>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-check-circle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-warning pf-m-textarea">
  <textarea
    name="textarea-warning"
    id="textarea-warning"
    aria-label="Warning state textarea example"
  >Warning
</textarea>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-error pf-m-textarea">
  <textarea
    required
    name="textarea-error"
    id="textarea-error"
    aria-label="Error state textarea example"
    aria-invalid="true"
  >Error
</textarea>
  <span class="pf-v6-c-form-control__utilities">
    <span class="pf-v6-c-form-control__icon pf-m-status">
      <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
    </span>
  </span>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical">
  <textarea
    name="textarea-resize-vertical"
    id="textarea-resize-vertical"
    aria-label="Resize vertical textarea example"
  >Resizes vertically
</textarea>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-horizontal">
  <textarea
    name="textarea-resize-horizontal"
    id="textarea-resize-horizontal"
    aria-label="Resize horizontal textarea example"
  >Resizes horizontally
</textarea>
</span>
<br />
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-both">
  <textarea
    name="textarea-resize-both"
    id="textarea-resize-both"
    aria-label="Resize both textarea example"
  >Resizes in both directions
</textarea>
</span>

```

## Documentation

### Accessibility

| Attribute | Applied to | Outcome |
| -- | -- | -- |
| `id` | `.pf-v6-c-form-control > input`,`.pf-v6-c-form-control > select`, or `.pf-v6-c-form-control > textarea` | Provides an `id` value that can be used with the `for` attribute on an associated `<label>` element to provide an accessible label for the form control element.
| `aria-invalid="true"` | `.pf-v6-c-form-control > input`,`.pf-v6-c-form-control > select`, or `.pf-v6-c-form-control > textarea` | Indicates that the form control is in the error state and applies error state styling. Use with `.pf-m-error` on the `.pf-v6-c-form-control` to ensure correct styling. |
| `aria-label="descriptive text"` | `.pf-v6-c-form-control > input`,`.pf-v6-c-form-control > select`, or `.pf-v6-c-form-control > textarea` | Provides an accessible label for assistive technology. |
| `aria-expanded="true"` | `.pf-v6-c-form-control > input` | Indicates that clicking in the form control has toggled something else to be expanded. Use with `.pf-m-expanded` on the `.pf-v6-c-form-control` to ensure correct styling. |

### Usage

| Class | Applied to | Outcome |
| -- | -- | -- |
| `.pf-v6-c-form-control` | `<span>` |  Initiates a container for an input, text area or select. For styling of checkboxes or radios see the [checkbox component](/components/forms/checkbox) or [radio component](/components/forms/radio). **Required**  |
| `.pf-v6-c-form-control__utilities` | `<span>` |  Initiates a container for elements like icons to be associated with the form control.  |
| `.pf-v6-c-form-control__icon` | `<span>` |  Creates a container for an icon associated with a form control.  |
| `.pf-v6-c-form-control__toggle-icon` | `<span>` |  Initiates a toggle icon for a form select.  |
| `.pf-m-resize-vertical` | `.pf-v6-c-form-control` | Modifies a form control element containing a text area so it can only be resized vertically. |
| `.pf-m-resize-horizontal` | `.pf-v6-c-form-control` | Modifies a form control element containing a text area so it can only be resized horizontally. |
| `.pf-m-resize-both` | `.pf-v6-c-form-control` | Modifies a `.pf-v6-c-form-control` element containing a text area so it resizes in both directions. |
| `.pf-m-icon` | `.pf-v6-c-form-control` | Modifies a form control to allow for an icon. |
| `.pf-m-readonly` | `.pf-v6-c-form-control` | Modifies a form control for a readonly input, text area, or select.|
| `.pf-m-disabled` | `.pf-v6-c-form-control` | Modifies a form control for a disabled input, text area, or select.|
| `.pf-m-success` | `.pf-v6-c-form-control` | Modifies a form control for the success state. |
| `.pf-m-warning` | `.pf-v6-c-form-control` | Modifies a form control for the warning state. |
| `.pf-m-error` | `.pf-v6-c-form-control` | Modifies a form control for the error (invalid) state. |
| `.pf-m-expanded` | `.pf-v6-c-form-control` | Modifies a form control for the expanded state. This is used when clicking in the text input toggles something open/closed. |
| `.pf-m-placeholder` | `.pf-v6-c-form-control` | Modifies a form select for placeholder styles. This modifier is set programatically based on the chosen option. |
| `.pf-m-plain` | `.pf-v6-c-form-control` | Modifies a form control containing an `<input>` or `<textarea>` with a `readonly` attribute to be presented as normal text. |
| `.pf-m-status`| `.pf-v6-c-form-control__icon` | Modifies a form control icon to show status. |