| 1 |
--- |
| 2 |
id: Simple file upload |
| 3 |
section: components |
| 4 |
subsection: file-upload |
| 5 |
cssPrefix: pf-v6-c-file-upload |
| 6 |
---## Examples |
| 7 |
|
| 8 |
### Basic file upload |
| 9 |
|
| 10 |
```html |
| 11 |
<div class="pf-v6-c-file-upload"> |
| 12 |
<div class="pf-v6-c-file-upload__file-select"> |
| 13 |
<div class="pf-v6-c-input-group"> |
| 14 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 15 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 16 |
<input |
| 17 |
readonly |
| 18 |
id="basic-file-upload-text-input" |
| 19 |
name="basic-file-upload-text-input" |
| 20 |
aria-label="Drag and drop a file or upload one" |
| 21 |
placeholder="Drag and drop a file or upload one" |
| 22 |
aria-describedby="basic-file-upload-browse" |
| 23 |
/> |
| 24 |
</span> |
| 25 |
</div> |
| 26 |
<div class="pf-v6-c-input-group__item"> |
| 27 |
<button |
| 28 |
class="pf-v6-c-button pf-m-control" |
| 29 |
type="button" |
| 30 |
id="basic-file-upload-browse" |
| 31 |
> |
| 32 |
<span class="pf-v6-c-button__text">Upload</span> |
| 33 |
</button> |
| 34 |
</div> |
| 35 |
<div class="pf-v6-c-input-group__item"> |
| 36 |
<button class="pf-v6-c-button pf-m-control" type="button" disabled> |
| 37 |
<span class="pf-v6-c-button__text">Clear</span> |
| 38 |
</button> |
| 39 |
</div> |
| 40 |
</div> |
| 41 |
</div> |
| 42 |
<div class="pf-v6-c-file-upload__file-details"> |
| 43 |
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical"> |
| 44 |
<textarea |
| 45 |
id="basic-file-upload-file-details" |
| 46 |
name="basic-file-upload-file-details" |
| 47 |
aria-label="Empty text area" |
| 48 |
></textarea> |
| 49 |
</span> |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
|
| 53 |
``` |
| 54 |
|
| 55 |
### With helper text |
| 56 |
|
| 57 |
```html |
| 58 |
<div class="pf-v6-c-file-upload"> |
| 59 |
<div class="pf-v6-c-file-upload__file-select"> |
| 60 |
<div class="pf-v6-c-input-group"> |
| 61 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 62 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 63 |
<input |
| 64 |
readonly |
| 65 |
id="file-upload-helper-text-text-input" |
| 66 |
name="file-upload-helper-text-text-input" |
| 67 |
aria-label="Drag and drop a file or upload one" |
| 68 |
placeholder="Drag and drop a file or upload one" |
| 69 |
aria-describedby="file-upload-helper-text-browse" |
| 70 |
/> |
| 71 |
</span> |
| 72 |
</div> |
| 73 |
<div class="pf-v6-c-input-group__item"> |
| 74 |
<button |
| 75 |
class="pf-v6-c-button pf-m-control" |
| 76 |
type="button" |
| 77 |
id="file-upload-helper-text-browse" |
| 78 |
aria-describedby="helper-text-example" |
| 79 |
> |
| 80 |
<span class="pf-v6-c-button__text">Upload</span> |
| 81 |
</button> |
| 82 |
</div> |
| 83 |
<div class="pf-v6-c-input-group__item"> |
| 84 |
<button class="pf-v6-c-button pf-m-control" type="button" disabled> |
| 85 |
<span class="pf-v6-c-button__text">Clear</span> |
| 86 |
</button> |
| 87 |
</div> |
| 88 |
</div> |
| 89 |
</div> |
| 90 |
<div class="pf-v6-c-file-upload__file-details"> |
| 91 |
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical"> |
| 92 |
<textarea |
| 93 |
id="file-upload-helper-text-file-details" |
| 94 |
name="file-upload-helper-text-file-details" |
| 95 |
aria-label="Uploaded file content" |
| 96 |
></textarea> |
| 97 |
</span> |
| 98 |
</div> |
| 99 |
<div class="pf-v6-c-file-upload__helper-text"> |
| 100 |
<div class="pf-v6-c-helper-text"> |
| 101 |
<div class="pf-v6-c-helper-text__item" id="helper-text-example"> |
| 102 |
<span class="pf-v6-c-helper-text__item-text">Upload a CSV file</span> |
| 103 |
</div> |
| 104 |
</div> |
| 105 |
</div> |
| 106 |
</div> |
| 107 |
|
| 108 |
``` |
| 109 |
|
| 110 |
### Upload complete non editable |
| 111 |
|
| 112 |
```html |
| 113 |
<div class="pf-v6-c-file-upload"> |
| 114 |
<div class="pf-v6-c-file-upload__file-select"> |
| 115 |
<div class="pf-v6-c-input-group"> |
| 116 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 117 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 118 |
<input |
| 119 |
readonly |
| 120 |
id="browsed-file-upload-complete-text-input" |
| 121 |
name="browsed-file-upload-complete-text-input" |
| 122 |
aria-label="Read only filename" |
| 123 |
value="Read only filename" |
| 124 |
aria-describedby="browsed-file-upload-complete-browse" |
| 125 |
/> |
| 126 |
</span> |
| 127 |
</div> |
| 128 |
<div class="pf-v6-c-input-group__item"> |
| 129 |
<button |
| 130 |
class="pf-v6-c-button pf-m-control" |
| 131 |
type="button" |
| 132 |
id="browsed-file-upload-complete-browse" |
| 133 |
> |
| 134 |
<span class="pf-v6-c-button__text">Upload</span> |
| 135 |
</button> |
| 136 |
</div> |
| 137 |
<div class="pf-v6-c-input-group__item"> |
| 138 |
<button class="pf-v6-c-button pf-m-control" type="button"> |
| 139 |
<span class="pf-v6-c-button__text">Clear</span> |
| 140 |
</button> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
</div> |
| 144 |
<div class="pf-v6-c-file-upload__file-details"> |
| 145 |
<span |
| 146 |
class="pf-v6-c-form-control pf-m-readonly pf-m-textarea pf-m-resize-vertical" |
| 147 |
> |
| 148 |
<textarea |
| 149 |
readonly |
| 150 |
id="browsed-file-upload-complete-file-details" |
| 151 |
name="browsed-file-upload-complete-file-details" |
| 152 |
aria-label="Text area" |
| 153 |
>Ssh-Rsa AAh3zJFkzjjakCJialksjfB3zJFkzzAAhhMskjjakCJialksjfB3z89z3zJFkz3 +kzMAjsauoox88aaZXphBx4fczJFkzMAjsauoox88aaZXphBx4fczJFkzMAjsauoox88aaZXphBx4fc |
| 154 |
|
| 155 |
</textarea> |
| 156 |
</span> |
| 157 |
</div> |
| 158 |
</div> |
| 159 |
|
| 160 |
``` |
| 161 |
|
| 162 |
### Upload complete editable |
| 163 |
|
| 164 |
```html |
| 165 |
<div class="pf-v6-c-file-upload"> |
| 166 |
<div class="pf-v6-c-file-upload__file-select"> |
| 167 |
<div class="pf-v6-c-input-group"> |
| 168 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 169 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 170 |
<input |
| 171 |
readonly |
| 172 |
id="drop-file-text-input" |
| 173 |
name="drop-file-text-input" |
| 174 |
aria-label="Read only filename" |
| 175 |
value="Sample.txt" |
| 176 |
aria-describedby="drop-file-browse" |
| 177 |
/> |
| 178 |
</span> |
| 179 |
</div> |
| 180 |
<div class="pf-v6-c-input-group__item"> |
| 181 |
<button |
| 182 |
class="pf-v6-c-button pf-m-control" |
| 183 |
type="button" |
| 184 |
id="drop-file-browse" |
| 185 |
> |
| 186 |
<span class="pf-v6-c-button__text">Upload</span> |
| 187 |
</button> |
| 188 |
</div> |
| 189 |
<div class="pf-v6-c-input-group__item"> |
| 190 |
<button class="pf-v6-c-button pf-m-control" type="button"> |
| 191 |
<span class="pf-v6-c-button__text">Clear</span> |
| 192 |
</button> |
| 193 |
</div> |
| 194 |
</div> |
| 195 |
</div> |
| 196 |
<div class="pf-v6-c-file-upload__file-details"> |
| 197 |
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical"> |
| 198 |
<textarea |
| 199 |
id="drop-file-file-details" |
| 200 |
name="drop-file-file-details" |
| 201 |
aria-label="Text area" |
| 202 |
>Ssh-Rsa AAh3zJFkzjjakCJialksjfB3zJFkzzAAhhMskjjakCJialksjfB3z89z3zJFkz3 +kzMAjsauoox88aaZXphBx4fczJFkzMAjsauoox88aaZXphBx4fczJFkzMAjsauoox88aaZXphBx4fc |
| 203 |
|
| 204 |
</textarea> |
| 205 |
</span> |
| 206 |
</div> |
| 207 |
</div> |
| 208 |
|
| 209 |
``` |
| 210 |
|
| 211 |
### Drag file hover component |
| 212 |
|
| 213 |
```html |
| 214 |
<div class="pf-v6-c-file-upload pf-m-drag-hover"> |
| 215 |
<div class="pf-v6-c-file-upload__file-select"> |
| 216 |
<div class="pf-v6-c-input-group"> |
| 217 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 218 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 219 |
<input |
| 220 |
readonly |
| 221 |
id="drag-file-hover-component-text-input" |
| 222 |
name="drag-file-hover-component-text-input" |
| 223 |
aria-label="Drag and drop a file or upload one" |
| 224 |
placeholder="Drag and drop a file or upload one" |
| 225 |
aria-describedby="drag-file-hover-component-browse" |
| 226 |
/> |
| 227 |
</span> |
| 228 |
</div> |
| 229 |
<div class="pf-v6-c-input-group__item"> |
| 230 |
<button |
| 231 |
class="pf-v6-c-button pf-m-control" |
| 232 |
type="button" |
| 233 |
id="drag-file-hover-component-browse" |
| 234 |
> |
| 235 |
<span class="pf-v6-c-button__text">Upload</span> |
| 236 |
</button> |
| 237 |
</div> |
| 238 |
<div class="pf-v6-c-input-group__item"> |
| 239 |
<button class="pf-v6-c-button pf-m-control" type="button" disabled> |
| 240 |
<span class="pf-v6-c-button__text">Clear</span> |
| 241 |
</button> |
| 242 |
</div> |
| 243 |
</div> |
| 244 |
</div> |
| 245 |
<div class="pf-v6-c-file-upload__file-details"> |
| 246 |
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical"> |
| 247 |
<textarea |
| 248 |
id="drag-file-hover-component-file-details" |
| 249 |
name="drag-file-hover-component-file-details" |
| 250 |
aria-label="Empty text area" |
| 251 |
></textarea> |
| 252 |
</span> |
| 253 |
</div> |
| 254 |
</div> |
| 255 |
|
| 256 |
``` |
| 257 |
|
| 258 |
### File upload in form with error |
| 259 |
|
| 260 |
```html |
| 261 |
<form class="pf-v6-c-form" novalidate> |
| 262 |
<div class="pf-v6-c-form__group"> |
| 263 |
<div class="pf-v6-c-form__group-control"> |
| 264 |
<div class="pf-v6-c-file-upload"> |
| 265 |
<div class="pf-v6-c-file-upload__file-select"> |
| 266 |
<div class="pf-v6-c-input-group"> |
| 267 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 268 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 269 |
<input |
| 270 |
readonly |
| 271 |
id="file-upload-error-text-input" |
| 272 |
name="file-upload-error-text-input" |
| 273 |
aria-label="File upload error" |
| 274 |
value="Sample.png" |
| 275 |
aria-describedby="file-upload-error-browse" |
| 276 |
/> |
| 277 |
</span> |
| 278 |
</div> |
| 279 |
<div class="pf-v6-c-input-group__item"> |
| 280 |
<button |
| 281 |
class="pf-v6-c-button pf-m-control" |
| 282 |
type="button" |
| 283 |
id="file-upload-error-browse" |
| 284 |
aria-describedby="with-error-example-helper-text" |
| 285 |
> |
| 286 |
<span class="pf-v6-c-button__text">Upload</span> |
| 287 |
</button> |
| 288 |
</div> |
| 289 |
<div class="pf-v6-c-input-group__item"> |
| 290 |
<button class="pf-v6-c-button pf-m-control" type="button"> |
| 291 |
<span class="pf-v6-c-button__text">Clear</span> |
| 292 |
</button> |
| 293 |
</div> |
| 294 |
</div> |
| 295 |
</div> |
| 296 |
<div |
| 297 |
class="pf-v6-c-file-upload__file-details" |
| 298 |
aria-describedby="with-error-example-helper-text" |
| 299 |
aria-invalid="true" |
| 300 |
> |
| 301 |
<span |
| 302 |
class="pf-v6-c-form-control pf-m-error pf-m-textarea pf-m-resize-vertical" |
| 303 |
> |
| 304 |
<textarea |
| 305 |
id="file-upload-error-file-details" |
| 306 |
name="file-upload-error-file-details" |
| 307 |
aria-label="Empty text area" |
| 308 |
aria-describedby="with-error-example-helper-text" |
| 309 |
aria-invalid="true" |
| 310 |
></textarea> |
| 311 |
<span class="pf-v6-c-form-control__utilities"> |
| 312 |
<span class="pf-v6-c-form-control__icon pf-m-status"> |
| 313 |
<i class="fas fa-exclamation-circle" aria-hidden="true"></i> |
| 314 |
</span> |
| 315 |
</span> |
| 316 |
</span> |
| 317 |
</div> |
| 318 |
|
| 319 |
<div class="pf-v6-c-file-upload__helper-text"> |
| 320 |
<div class="pf-v6-c-helper-text"> |
| 321 |
<div |
| 322 |
class="pf-v6-c-helper-text__item pf-m-error" |
| 323 |
id="with-error-example-helper-text" |
| 324 |
> |
| 325 |
<span class="pf-v6-c-helper-text__item-icon"> |
| 326 |
<i class="fas fa-fw fa-exclamation-circle" aria-hidden="true"></i> |
| 327 |
</span> |
| 328 |
<span class="pf-v6-c-helper-text__item-text"> |
| 329 |
<span class="pf-v6-screen-reader">Error:</span> |
| 330 |
Must be a CSV file no larger than 1 KB |
| 331 |
</span> |
| 332 |
</div> |
| 333 |
</div> |
| 334 |
</div> |
| 335 |
</div> |
| 336 |
</div> |
| 337 |
</div> |
| 338 |
</form> |
| 339 |
|
| 340 |
``` |
| 341 |
|
| 342 |
### File upload loading |
| 343 |
|
| 344 |
```html |
| 345 |
<div class="pf-v6-c-file-upload pf-m-loading"> |
| 346 |
<div class="pf-v6-c-file-upload__file-select"> |
| 347 |
<div class="pf-v6-c-input-group"> |
| 348 |
<div class="pf-v6-c-input-group__item pf-m-fill"> |
| 349 |
<span class="pf-v6-c-form-control pf-m-readonly"> |
| 350 |
<input |
| 351 |
readonly |
| 352 |
id="file-upload-loading-text-input" |
| 353 |
name="file-upload-loading" |
| 354 |
aria-label="Read only filename" |
| 355 |
value="Sample.png" |
| 356 |
aria-describedby="file-upload-loading-browse" |
| 357 |
/> |
| 358 |
</span> |
| 359 |
</div> |
| 360 |
<div class="pf-v6-c-input-group__item"> |
| 361 |
<button |
| 362 |
class="pf-v6-c-button pf-m-control" |
| 363 |
type="button" |
| 364 |
disabled |
| 365 |
id="file-upload-loading-browse" |
| 366 |
> |
| 367 |
<span class="pf-v6-c-button__text">Upload</span> |
| 368 |
</button> |
| 369 |
</div> |
| 370 |
<div class="pf-v6-c-input-group__item"> |
| 371 |
<button class="pf-v6-c-button pf-m-control" type="button"> |
| 372 |
<span class="pf-v6-c-button__text">Clear</span> |
| 373 |
</button> |
| 374 |
</div> |
| 375 |
</div> |
| 376 |
</div> |
| 377 |
<div class="pf-v6-c-file-upload__file-details"> |
| 378 |
<span class="pf-v6-c-form-control pf-m-textarea pf-m-resize-vertical"> |
| 379 |
<textarea |
| 380 |
id="file-upload-loading-file-details" |
| 381 |
name="file-upload-loading-file-details" |
| 382 |
aria-label="Text area" |
| 383 |
>Ssh-Rsa AAh3zJFkzjjakCJialksjfB3zJFkzzAAhhMskjjakCJialksjfB3z89z3zJFkz3 +kzMAjsauoox88aaZXphBx4fczJFkzMAjsauoox88aaZXphBx4fczJFkzMAjsauoox88aaZXphBx4fc |
| 384 |
|
| 385 |
</textarea> |
| 386 |
</span> |
| 387 |
|
| 388 |
<div class="pf-v6-c-file-upload__file-details-spinner"> |
| 389 |
<svg |
| 390 |
class="pf-v6-c-spinner pf-m-lg" |
| 391 |
role="progressbar" |
| 392 |
viewBox="0 0 100 100" |
| 393 |
aria-label="Loading..." |
| 394 |
> |
| 395 |
<circle |
| 396 |
class="pf-v6-c-spinner__path" |
| 397 |
cx="50" |
| 398 |
cy="50" |
| 399 |
r="45" |
| 400 |
fill="none" |
| 401 |
/> |
| 402 |
</svg> |
| 403 |
</div> |
| 404 |
</div> |
| 405 |
</div> |
| 406 |
|
| 407 |
``` |
| 408 |
|
| 409 |
## Documentation |
| 410 |
|
| 411 |
### Overview |
| 412 |
|
| 413 |
### Usage |
| 414 |
|
| 415 |
| Class | Applied to | Outcome | |
| 416 |
| -- | -- | -- | |
| 417 |
| `.pf-v6-c-file-upload` | `<div>`, `<form>` | Initiates the file upload component. **Required**. | |
| 418 |
| `.pf-v6-c-file-upload__file-select` | `<div>` | Initiates the file select element. **Required** | |
| 419 |
| `.pf-v6-c-file-upload__file-details` | `<div>` | Initiates the file details element. **Required** | |
| 420 |
| `.pf-v6-c-file-upload__file-details-spinner` | `<div>` | Initiates the file details element. **Required** | |
| 421 |
| `.pf-v6-c-file-upload__helper-text` | `<div>` | Initiates a container for [helper text](/components/helper-text) | |
| 422 |
| `.pf-m-drag-hover` | `.pf-v6-c-file-upload` | Modifies file upload for when an element is dragged or dropped inside of its container. | |
| 423 |
| `.pf-m-loading` | `.pf-v6-c-file-upload` | Modifies file upload for the loading state. | |