Debian Codegraph @

node/@patternfly/patternfly/docs/components/FormControl/examples/FormControl.md

raw
1 ---
2 id: Form control
3 section: components
4 subsection: forms
5 cssPrefix: pf-v6-c-form-control
6 ---## Examples
7
8 ### Input
9
10 **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.
11
12 ```html
13 <span class="pf-v6-c-form-control">
14 <input
15 type="text"
16 value="Standard"
17 id="input-standard"
18 aria-label="Standard input example"
19 />
20 </span>
21 <br />
22 <span class="pf-v6-c-form-control">
23 <input
24 type="text"
25 placeholder="Placeholder"
26 id="input-placeholder"
27 aria-label="Placeholder input example"
28 />
29 </span>
30 <br />
31 <span class="pf-v6-c-form-control pf-m-readonly">
32 <input
33 readonly
34 type="text"
35 value="Readonly"
36 id="input-readonly"
37 aria-label="Readonly input example"
38 />
39 </span>
40 <br />
41 <span class="pf-v6-c-form-control pf-m-readonly pf-m-plain">
42 <input
43 readonly
44 type="text"
45 value="Readonly plain"
46 id="input-readonly-plain"
47 aria-label="Readonly plain input example"
48 />
49 </span>
50 <br />
51 <span class="pf-v6-c-form-control pf-m-disabled">
52 <input
53 disabled
54 type="text"
55 value="Disabled"
56 id="input-disabled"
57 aria-label="Disabled input example"
58 />
59 </span>
60 <br />
61 <span class="pf-v6-c-form-control pf-m-success">
62 <input
63 type="text"
64 value="Success"
65 id="input-success"
66 aria-label="Success state input example"
67 />
68 <span class="pf-v6-c-form-control__utilities">
69 <span class="pf-v6-c-form-control__icon pf-m-status">
70 <i class="fas fa-check-circle" aria-hidden="true"></i>
71 </span>
72 </span>
73 </span>
74 <br />
75 <span class="pf-v6-c-form-control pf-m-warning">
76 <input
77 type="text"
78 value="Warning"
79 id="input-warning"
80 aria-label="Warning state input example"
81 />
82 <span class="pf-v6-c-form-control__utilities">
83 <span class="pf-v6-c-form-control__icon pf-m-status">
84 <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
85 </span>
86 </span>
87 </span>
88 <br />
89 <span class="pf-v6-c-form-control pf-m-error">
90 <input
91 required
92 type="text"
93 value="Error"
94 id="input-error"
95 aria-invalid="true"
96 aria-label="Error state input example"
97 />
98 <span class="pf-v6-c-form-control__utilities">
99 <span class="pf-v6-c-form-control__icon pf-m-status">
100 <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
101 </span>
102 </span>
103 </span>
104 <br />
105 <span class="pf-v6-c-form-control pf-m-expanded">
106 <input
107 type="text"
108 value="Expanded"
109 id="input-expanded"
110 aria-label="Expanded input example"
111 />
112 </span>
113 <br />
114 <span class="pf-v6-c-form-control pf-m-icon">
115 <input
116 type="text"
117 value="Calendar"
118 id="input-calendar"
119 name="input-calendar"
120 aria-label="Calendar input example"
121 />
122 <span class="pf-v6-c-form-control__utilities">
123 <span class="pf-v6-c-form-control__icon">
124 <i class="fas fa-calendar" aria-hidden="true"></i>
125 </span>
126 </span>
127 </span>
128 <br />
129 <span class="pf-v6-c-form-control pf-m-warning pf-m-icon">
130 <input
131 type="text"
132 value="Clock (invalid)"
133 id="input-clock"
134 name="input-clock"
135 aria-label="Clock input example"
136 />
137 <span class="pf-v6-c-form-control__utilities">
138 <span class="pf-v6-c-form-control__icon">
139 <i class="fas fa-clock" aria-hidden="true"></i>
140 </span>
141 <span class="pf-v6-c-form-control__icon pf-m-status">
142 <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
143 </span>
144 </span>
145 </span>
146 <br />
147 <span class="pf-v6-c-form-control pf-m-icon">
148 <input
149 type="text"
150 value="Custom icon"
151 id="input-custom-icon"
152 name="custom-icon"
153 aria-label="Custom icon input example"
154 />
155 <span class="pf-v6-c-form-control__utilities">
156 <span class="pf-v6-c-form-control__icon">
157 <i class="fas fa-bell" aria-hidden="true"></i>
158 </span>
159 </span>
160 </span>
161
162 ```
163
164 ### Select
165
166 ```html
167 <span class="pf-v6-c-form-control pf-m-placeholder">
168 <select
169 class
170 id="select-selectable-placeholder"
171 name="select-selectable-placeholder"
172 aria-label="Selectable placeholder select example"
173 >
174 <option value selected>Selectable placeholder</option>
175 <option value="Mr">Mr</option>
176 <option value="Miss">Miss</option>
177 <option value="Mrs">Mrs</option>
178 <option value="Ms">Ms</option>
179 <option value="Dr">Dr</option>
180 <option value="Dr" disabled>Disabled option</option>
181 <option value="Other">Other</option>
182 </select>
183 <span class="pf-v6-c-form-control__utilities">
184 <span class="pf-v6-c-form-control__toggle-icon">
185 <i class="fas fa-caret-down" aria-hidden="true"></i>
186 </span>
187 </span>
188 </span>
189 <br />
190 <span class="pf-v6-c-form-control pf-m-placeholder">
191 <select
192 class
193 id="select-non-selectable-placeholder"
194 name="select-non-selectable-placeholder"
195 aria-label="Non-selectable placeholder select example"
196 >
197 <option value selected disabled>Non-selectable placeholder</option>
198 <option value="Mr">Mr</option>
199 <option value="Miss">Miss</option>
200 <option value="Mrs">Mrs</option>
201 <option value="Ms">Ms</option>
202 <option value="Dr">Dr</option>
203 <option value="Other">Other</option>
204 </select>
205 <span class="pf-v6-c-form-control__utilities">
206 <span class="pf-v6-c-form-control__toggle-icon">
207 <i class="fas fa-caret-down" aria-hidden="true"></i>
208 </span>
209 </span>
210 </span>
211 <br />
212 <span class="pf-v6-c-form-control">
213 <select
214 class
215 id="select-group"
216 name="select-group"
217 aria-label="Select group example"
218 >
219 <optgroup label="Group 1">
220 <option value="Option 1">The first option</option>
221 <option value="Option 2" selected>Option groups (second option selected)</option>
222 </optgroup>
223 <optgroup label="Group 2">
224 <option value="Option 3">The third option</option>
225 <option value="Option 4" disabled>The fourth option (disabled)</option>
226 </optgroup>
227 </select>
228 <span class="pf-v6-c-form-control__utilities">
229 <span class="pf-v6-c-form-control__toggle-icon">
230 <i class="fas fa-caret-down" aria-hidden="true"></i>
231 </span>
232 </span>
233 </span>
234 <br />
235 <span class="pf-v6-c-form-control pf-m-success">
236 <select
237 class
238 id="select-group-success"
239 name="select-group-success"
240 aria-label="Success state select group example"
241 >
242 <option value>Valid option</option>
243 <optgroup label="Group 1">
244 <option value="Option 1">The first option</option>
245 <option value="Option 2">The second option</option>
246 </optgroup>
247 <optgroup label="Group 2">
248 <option value="Option 3">The third option</option>
249 <option value="Option 4">The fourth option</option>
250 </optgroup>
251 </select>
252 <span class="pf-v6-c-form-control__utilities">
253 <span class="pf-v6-c-form-control__icon pf-m-status">
254 <i class="fas fa-check-circle" aria-hidden="true"></i>
255 </span>
256 <span class="pf-v6-c-form-control__toggle-icon">
257 <i class="fas fa-caret-down" aria-hidden="true"></i>
258 </span>
259 </span>
260 </span>
261 <br />
262 <span class="pf-v6-c-form-control pf-m-warning">
263 <select
264 class
265 id="select-group-warning"
266 name="select-group-warning"
267 aria-label="Warning state select group example"
268 >
269 <option value>Warning option</option>
270 <optgroup label="Group 1">
271 <option value="Option 1">The first option</option>
272 <option value="Option 2">The second option</option>
273 </optgroup>
274 <optgroup label="Group 2">
275 <option value="Option 3">The third option</option>
276 <option value="Option 4">The fourth option</option>
277 </optgroup>
278 </select>
279 <span class="pf-v6-c-form-control__utilities">
280 <span class="pf-v6-c-form-control__icon pf-m-status">
281 <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
282 </span>
283 <span class="pf-v6-c-form-control__toggle-icon">
284 <i class="fas fa-caret-down" aria-hidden="true"></i>
285 </span>
286 </span>
287 </span>
288 <br />
289 <span class="pf-v6-c-form-control pf-m-error">
290 <select
291 class
292 required
293 aria-invalid="true"
294 id="select-group-error"
295 name="select-group-error"
296 aria-label="Error state select group example"
297 >
298 <option value>Invalid option</option>
299 <optgroup label="Group 1">
300 <option value="Option 1">The first option</option>
301 <option value="Option 2">The second option</option>
302 </optgroup>
303 <optgroup label="Group 2">
304 <option value="Option 3">The third option</option>
305 <option value="Option 4">The fourth option</option>
306 </optgroup>
307 </select>
308 <span class="pf-v6-c-form-control__utilities">
309 <span class="pf-v6-c-form-control__icon pf-m-status">
310 <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
311 </span>
312 <span class="pf-v6-c-form-control__toggle-icon">
313 <i class="fas fa-caret-down" aria-hidden="true"></i>
314 </span>
315 </span>
316 </span>
317 <br />
318 <span class="pf-v6-c-form-control pf-m-disabled pf-m-placeholder">
319 <select
320 class
321 disabled
322 id="select-disabled"
323 name="select-disabled"
324 aria-label="Disabled select example"
325 >
326 <option value selected>Disabled</option>
327 <option value="Mr">Mr</option>
328 <option value="Miss">Miss</option>
329 <option value="Mrs">Mrs</option>
330 <option value="Ms">Ms</option>
331 <option value="Dr">Dr</option>
332 <option value="Other">Other</option>
333 </select>
334 <span class="pf-v6-c-form-control__utilities">
335 <span class="pf-v6-c-form-control__toggle-icon">
336 <i class="fas fa-caret-down" aria-hidden="true"></i>
337 </span>
338 </span>
339 </span>
340
341 ```
342
343 ### Textarea
344
345 ```html
346 <span class="pf-v6-c-form-control pf-m-textarea">
347 <textarea
348 name="textarea-standard"
349 id="textarea-standard"
350 aria-label="Standard textarea example"
351 >Standard
352 </textarea>
353 </span>
354 <br />
355 <span class="pf-v6-c-form-control pf-m-readonly pf-m-textarea">
356 <textarea
357 readonly
358 name="textarea-readonly"
359 id="textarea-readonly"
360 aria-label="Readonly textarea example"
361 >Readonly
362 </textarea>
363 </span>
364 <br />
365 <span class="pf-v6-c-form-control pf-m-readonly pf-m-plain pf-m-textarea">
366 <textarea
367 readonly
368 name="textarea-readonly-plain"
369 id="textarea-readonly-plain"
370 aria-label="Readonly plain textarea example"
371 >Readonly plain
372 </textarea>
373 </span>
374 <br />
375 <span class="pf-v6-c-form-control pf-m-disabled pf-m-textarea">
376 <textarea
377 disabled
378 name="textarea-disabled"
379 id="textarea-disabled"
380 aria-label="Disabled textarea example"
381 >Disabled
382 </textarea>
383 </span>
384 <br />
385 <span class="pf-v6-c-form-control pf-m-success pf-m-textarea">
386 <textarea
387 name="textarea-success"
388 id="textarea-success"
389 aria-label="Success state textarea example"
390 >Success
391 </textarea>
392 <span class="pf-v6-c-form-control__utilities">
393 <span class="pf-v6-c-form-control__icon pf-m-status">
394 <i class="fas fa-check-circle" aria-hidden="true"></i>
395 </span>
396 </span>
397 </span>
398 <br />
399 <span class="pf-v6-c-form-control pf-m-warning pf-m-textarea">
400 <textarea
401 name="textarea-warning"
402 id="textarea-warning"
403 aria-label="Warning state textarea example"
404 >Warning
405 </textarea>
406 <span class="pf-v6-c-form-control__utilities">
407 <span class="pf-v6-c-form-control__icon pf-m-status">
408 <i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
409 </span>
410 </span>
411 </span>
412 <br />
413 <span class="pf-v6-c-form-control pf-m-error pf-m-textarea">
414 <textarea
415 required
416 name="textarea-error"
417 id="textarea-error"
418 aria-label="Error state textarea example"
419 aria-invalid="true"
420 >Error
421 </textarea>
422 <span class="pf-v6-c-form-control__utilities">
423 <span class="pf-v6-c-form-control__icon pf-m-status">
424 <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
425 </span>
426 </span>
427 </span>
428 <br />
429 <span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical">
430 <textarea
431 name="textarea-resize-vertical"
432 id="textarea-resize-vertical"
433 aria-label="Resize vertical textarea example"
434 >Resizes vertically
435 </textarea>
436 </span>
437 <br />
438 <span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-horizontal">
439 <textarea
440 name="textarea-resize-horizontal"
441 id="textarea-resize-horizontal"
442 aria-label="Resize horizontal textarea example"
443 >Resizes horizontally
444 </textarea>
445 </span>
446 <br />
447 <span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-both">
448 <textarea
449 name="textarea-resize-both"
450 id="textarea-resize-both"
451 aria-label="Resize both textarea example"
452 >Resizes in both directions
453 </textarea>
454 </span>
455
456 ```
457
458 ## Documentation
459
460 ### Accessibility
461
462 | Attribute | Applied to | Outcome |
463 | -- | -- | -- |
464 | `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.
465 | `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. |
466 | `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. |
467 | `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. |
468
469 ### Usage
470
471 | Class | Applied to | Outcome |
472 | -- | -- | -- |
473 | `.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** |
474 | `.pf-v6-c-form-control__utilities` | `<span>` | Initiates a container for elements like icons to be associated with the form control. |
475 | `.pf-v6-c-form-control__icon` | `<span>` | Creates a container for an icon associated with a form control. |
476 | `.pf-v6-c-form-control__toggle-icon` | `<span>` | Initiates a toggle icon for a form select. |
477 | `.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. |
478 | `.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. |
479 | `.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. |
480 | `.pf-m-icon` | `.pf-v6-c-form-control` | Modifies a form control to allow for an icon. |
481 | `.pf-m-readonly` | `.pf-v6-c-form-control` | Modifies a form control for a readonly input, text area, or select.|
482 | `.pf-m-disabled` | `.pf-v6-c-form-control` | Modifies a form control for a disabled input, text area, or select.|
483 | `.pf-m-success` | `.pf-v6-c-form-control` | Modifies a form control for the success state. |
484 | `.pf-m-warning` | `.pf-v6-c-form-control` | Modifies a form control for the warning state. |
485 | `.pf-m-error` | `.pf-v6-c-form-control` | Modifies a form control for the error (invalid) state. |
486 | `.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. |
487 | `.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. |
488 | `.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. |
489 | `.pf-m-status`| `.pf-v6-c-form-control__icon` | Modifies a form control icon to show status. |