From 27d436d7f133464533b7e04622eb87e054cff135 Mon Sep 17 00:00:00 2001 From: iryna Date: Thu, 19 Nov 2026 22:17:25 +0200 Subject: [PATCH 1/3] docs(file-input): fix docs controls inference and clarify upload-status migration guidance --- skills/carbon-react/components/file-input.md | 334 ++++++++++++++++-- src/components/file-input/file-input.mdx | 62 +++- .../file-input/file-input.stories.tsx | 67 ++-- 3 files changed, 397 insertions(+), 66 deletions(-) diff --git a/skills/carbon-react/components/file-input.md b/skills/carbon-react/components/file-input.md index 2e3fae5332..90c9272fa0 100644 --- a/skills/carbon-react/components/file-input.md +++ b/skills/carbon-react/components/file-input.md @@ -54,39 +54,48 @@ description: Carbon FileInput component props and usage examples. ## Examples ### Default +**Args** + +```tsx +{ + label: "File input", + multiple: false, + } +``` + **Render** ```tsx -() => { - const [uploadStatus, setUploadStatus] = useState< - FileUploadStatusProps | undefined - >(); - const [error, setError] = useState(); - const onChange = (files: FileList) => { - action("onChange")(files); - if (files.length > 1) { - setError("Select only one file"); - return; - } - const file = files[0]; - if (!file) return; - setError(undefined); - setUploadStatus({ - status: "completed", - filename: file.name, - onDelete: () => setUploadStatus(undefined), - }); - }; +(args) => { + const [uploadStatus, setUploadStatus] = useState< + FileUploadStatusProps | undefined + >(); + const [error, setError] = useState(); + const onChange = (files: FileList) => { + action("onChange")(files); + if (files.length > 1) { + setError("Select only one file"); + return; + } + const file = files[0]; + if (!file) return; + setError(undefined); + setUploadStatus({ + status: "completed", + filename: file.name, + onDelete: () => setUploadStatus(undefined), + }); + }; - return ( - - ); -} + return ( + + ); + } ``` @@ -888,3 +897,270 @@ description: Carbon FileInput component props and usage examples. } ``` + +### MDX Example 1 + +**Args** + +```tsx +## Examples + +### Default + + + +### With inputHint + + + +### Required + +You can use the `required` prop to indicate if the field is mandatory. + + + +### Required field validation + +FileInput never derives or clears `error` itself - it's a controlled prop. This example starts in the "required and no file uploaded" error +state, as if a form had just been submitted empty, then clears the error once a file is added, the same way a real form's `onChange` would. + + + +### Size variations + +By default the component fills the available width of its parent container and has a minimum height of `102px`. It can therefore follow a narrow sidebar, +a form column, or a wider content area without component-specific width props. + +You can constrain it with `minWidth` and `maxWidth`, or adjust its height with `minHeight` and `maxHeight`, to accommodate long explanatory text or a +particular design. These props accept valid CSS values, so consumers are responsible for choosing compatible minimum and maximum values and +ensuring that the button, text, status message, thumbnail, and actions still fit. Restrictive dimensions may cause content to wrap, overflow, or be clipped. + +Width constraints apply to both the drop zone and status cards. In single-file mode, custom height constraints also apply to the one status card that +replaces the drop zone. In multiple-file mode, status cards retain their content-driven height. + +#### Increased height + + + +#### Both height and width increased + + + +#### Parent container widths + +This example shows the fluid default inside a `400px`-wide container and inside a `Sidebar` at its default width. Select "Show file input in a sidebar" to open the sidebar: + + + +#### Width constraints + +Set `minWidth` and `maxWidth` when the component needs constraints independent of its parent. The two props are optional and behave independently. + + + +### Accept and file type validation + +The `accept` prop is passed directly to the underlying HTML `` element, and helps guide users towards uploading files of the correct format or type. +Please see the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) for more details on this attribute. When selecting a file via the +Select file button, the operating system's file picker will either highlight the appropriate files, or make it impossible to select incorrect ones. + +Note that `accept` does not prevent the user from uploading a file of the incorrect type via drag and drop, so you should still use the `onChange` prop to add an error +message as soon as an inappropriate file is added - as shown below. And of course nothing takes away the need for validation on the server side. + + + +### Single file vs multiple files + +By default FileInput is in single-file mode (`multiple` defaults to `false`): the operating system's file picker restricts selection to one file, and once +`uploadStatus` contains a status, the drop zone is replaced by its status card. A removable current file must be removed before another can be +selected. A `previously` status also keeps the drop zone hidden, so give it `onDelete` when users should be able to replace it. The default instruction explicitly offers both options: +drag and drop, or use the Select file button. If you supply `buttonText`, the default instruction uses that label; supply `dragAndDropText` to +replace the instruction entirely. + +Set `multiple={true}` (or just `multiple`) when users should be able to add files while status cards are displayed. + +Dragging and dropping bypasses the file picker's restriction, so more than one file can still reach `onChange` even with the single-file default. +FileInput never discards files or derives `error` on your behalf (the same rule that applies to a required field with no files), so your `onChange` +should check `files.length` and set `error` yourself when it's greater than one - the example below does exactly that, showing the same Field-error +treatment either for a missing required file or for too many files being dropped at once. + +FileInput is controlled: update `uploadStatus` in `onChange` to show a selected file and provide its remove action. The Default story demonstrates this +single-file flow and reports an error if multiple files are dropped together. Focus remains on the Select file button while a controlled status is pending, +then moves to the status card's first action or Preview link when it appears, or to the named status list when the card has neither. +Cancel, Delete, Remove, and Retry (status actions) are announced by their action and filename only (for example, "Delete report.pdf, button"). +In multiple-file mode, focus remains on the Select file button so users can continue adding files. The polite selection announcement also becomes the +button's accessible description, ensuring the selection result is available when assistive technology announces the returning focus. +The description clears when focus leaves the button, and later announcements, such as upload completion, are made through the live region only. +After Delete, Remove, or Cancel removes a status card, the localized result is added temporarily to the accessible description of the next action, +list, or Select file button before focus moves there. This ensures the focus announcement includes the result; the temporary description clears when focus leaves. +It also clears when Preview is activated, so returning from a preview does not repeat a stale removal result. If there is nowhere to move focus, +the result is announced through the polite live region instead. +No removal announcement is made when the consumer callback leaves the card rendered. + +Without moving focus, a persistent polite live region announces the selected filenames and any files that newly change to `status: "completed"`. +A status that changes to `status: "error"` is announced by that file's own polite status region (see [Upload error summary](#upload-error-summary)). +Other changes, such as progress updates or a retry returning a file to `status: "uploading"`, are not announced automatically; they are +available as the visible status message when users navigate to the file. Statuses supplied when the field first renders are not announced. + + + +### Tracking upload status + +The `uploadStatus` prop is used to indicate when a file has been added, as well as to display the current status or progress of its upload — +including options to cancel or remove the uploaded file. You must provide this prop (as a `FileUploadStatusProps` object) in order for users +to see any visual indication of the uploaded file. + +Consumers own the status array and append, update, or remove entries as the upload lifecycle changes. In the default single-file mode, the drop zone +remains hidden while any status is present; with `multiple`, the drop zone stays available alongside all statuses. +Custom minimum and maximum widths apply to both the drop zone and status cards. In single-file mode, custom minimum and maximum heights also apply to its +one status card. In multiple-file mode, status cards retain their content-driven height. + +For this reason the `onChange` function prop is mandatory - without providing an implementation for this event handler that updates the +components `uploadStatus`, there will be no visual change once a file has been added to the input. + +#### Status actions + +Each status shows the actions whose callbacks you supply. File Input only renders the buttons and announces the result; your callbacks do the +work and update `uploadStatus`. + +| `status` | Actions | Callbacks | +| ------------ | --------------------------------------- | ------------------------------ | +| `uploading` | Cancel | `onCancel` | +| `completed` | Delete, Preview | `onDelete`, `href` | +| `error` | Remove, Retry | `onRemove`, optional `onRetry` | +| `previously` | Delete (single-file mode only), Preview | optional `onDelete`, `href` | + +The actions differ by whether the file is stored: + +- **Cancel** stops an upload in progress. +- **Delete** is for a stored file (completed or previously uploaded); your `onDelete` should remove it from storage. +- **Remove** is for a failed file that was never stored; your `onRemove` only dismisses it. +- **Retry** repeats the failed upload. Supply `onRetry` only when trying again could succeed, such as after a network or server failure. + Omit it for files your validation rejected before upload (for example, an unsupported type or a file that is too large), since the same + file fails again. + +Previously uploaded files are read-only in multiple-file mode. If deleting a previously uploaded file fails, change it to `status: "error"` +with an `onRemove` that either clears the status, so the user can select another file, or restores the `previously` status, so the user +can try Delete again. + +Remove the file's status inside the Cancel, Delete, or Remove callback, without waiting for a server response. File Input then moves focus +to the next file's action and announces the result. If the status is removed later, focus is lost. Give each status an `id` when +filenames can repeat. + +#### Multiple files example + +This is the `multiple={true}` opt-in mode (single-file is the default), showing several files uploading side by side with every status-specific callback wired up and working: +`onCancel` while a file is uploading, `onRetry` and `onRemove` for a file that failed, and `onDelete` for one that completed. Add a few files (or drop +several at once) to try it. It also starts with a read-only previously uploaded file, representing an existing historical record. + + + +#### Consumer scroll container + +File Input does not add an internal scrollbar. When a long status list needs a +height constraint, place File Input in a consumer-owned scroll container. That +container owns the scrollbar and scrolls the complete File Input, including its +label and drop zone. + +This example uses a static list of 10 uploaded files to demonstrate scrolling, so +selecting files and the Delete actions have no effect. + + + +#### Upload error summary + +After an upload fails, update that current item in `uploadStatus` to +`status: "error"`. When there is more than one current file, File Input shows +a summary below the current-files label. The summary updates as failed items +are retried, removed, or changed to another status; previously uploaded files +are not included. + +Each file has a persistent polite status region. When a file fails, its filename +and error message populate that region. Remove and Retry remain outside it, so +they are available through normal keyboard and screen-reader navigation without +becoming part of the automatic announcement. + + + +#### Client side example + +Here is a relatively simple example of using a [FileReader](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) to track progress purely +on the client side, resulting in storing the file locally as a `data:` URL. This is a way to show users a preview of their file if you do not intend +to track upload progress on the server, or do not actually send the files to a server until form submission. + +Note the use of a `ref` to store the `FileReader` object - this is not essential but avoids having to create a new `FileReader` object more than once in the +lifecycle of the component. + +This example also contains validation to restrict the user from uploading large files - this is useful because storing a large file in memory may make the +browser freeze or even crash. If your application needs to process large files on the client side then consider +[reading the file into an ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer) and processing that piece-by-piece. + +This example starts with a static "Loaded 56%" card, so an in-progress state is visible right away rather than only once you add a file +yourself (for a small file, the browser may fire so few progress events that it jumps straight to "completed"). Cancel clears it, or add a +real file to see the FileReader-driven version take over. + + + +#### Uploading with a progress percentage + +With `progress` set, the status icon exposes a `progressbar` role with `aria-valuemin`, `aria-valuemax`, and `aria-valuenow` set to the +percentage, and is named with the filename. Assistive technology can report the value when users navigate to it, but progress changes are +not announced automatically. + +`progress` does not change the visual indicator: the ring loader plays a tracked animation that does not reflect the percentage, and the +value is not turned into visible text. Pair it with a `message` (for example `"Loaded 56%"`) so the percentage is shown as text too, as +in the client side example above. + +#### Uploading without a progress percentage + +Without `progress`, the ring loader plays an untracked animation to indicate an indeterminate upload. The visible status message (either +your own `message`, or the localized default, `fileInput.uploading`) already conveys the upload state, so the loader is hidden from +assistive technology and screen readers read the filename and status message as text. If the status message is empty, the loader is +exposed as an image named with the filename and the localized `fileInput.uploading` text instead, so the upload state is never lost. + +The example below omits `message`, so the default locale text ("Uploading…") is shown and read after the filename. Cancel is wired to +clear the status, so the drop zone returns afterwards. + + + +#### Showing a thumbnail + +Supplying `thumbnailSrc` on a status object (any status - uploading, completed, error, or previously uploaded) adds a leading thumbnail +column ahead of the filename, in place of the compact inline status icon shown otherwise. The image itself is shown for completed and +previously uploaded files; while uploading the column shows the loader, and in error it shows the error icon. If the image fails to load, +the file icon is shown instead. The thumbnail is decorative and has empty alternative text, so the filename remains the file's name for +assistive technology. + +`SingleFile` and `MultipleFiles` above demonstrate this too once you upload a real image, but this example shows the with-thumbnail +layout without needing to upload anything. + + + +## Validation States + +This component supports input validation, see our [Validations](../?path=/docs/documentation-validations--docs) documentation page for more information. + +By default, the input error message appears below the label set, after the hint text when provided, and before the drop zone. `validationMessagePositionTop={false}` is deprecated, but continues to render validation below the drop zone for existing consumers. Individual file upload errors remain with their file status. + +## Props + +### File Input + + + +Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. The deprecated `onAction` remains a primary-action fallback. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. + +#### Migrating upload item props (`uploadStatus` entries) + +`onAction` still works as a deprecated fallback, but new code should use the callback that matches each status: + +| `status` value | Preferred callback(s) | Legacy fallback | +| -------------- | --------------------- | --------------- | +| `uploading` | `onCancel` | `onAction` | +| `completed` | `onDelete` (+ optional `href` for Preview) | `onAction` | +| `error` | `onRemove` (+ optional `onRetry`) | `onAction` | +| `previously` | optional `onDelete` (+ optional `href` for Preview) | `onAction` | + +Status-by-status examples: +``` + diff --git a/src/components/file-input/file-input.mdx b/src/components/file-input/file-input.mdx index 62c1cf93f0..90d5c6c7d0 100644 --- a/src/components/file-input/file-input.mdx +++ b/src/components/file-input/file-input.mdx @@ -25,6 +25,7 @@ Allows one or more files to be selected or dropped and presents their controlled - [Examples](#examples) - [Validation states](#validation-states) - [Props](#props) +- [Migrating upload item props (`uploadStatus` entries)](#migrating-upload-item-props-uploadstatus-entries) - [Translation keys](#translation-keys) ## Quick Start @@ -280,15 +281,60 @@ By default, the input error message appears below the label set, after the hint Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. The deprecated `onAction` remains a primary-action fallback. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. -#### Migrating status props +#### Migrating upload item props (`uploadStatus` entries) + +`onAction` still works as a deprecated fallback, but new code should use the callback that matches each status: + +| `status` value | Preferred callback(s) | Legacy fallback | +| -------------- | --------------------- | --------------- | +| `uploading` | `onCancel` | `onAction` | +| `completed` | `onDelete` (+ optional `href` for Preview) | `onAction` | +| `error` | `onRemove` (+ optional `onRetry`) | `onAction` | +| `previously` | optional `onDelete` (+ optional `href` for Preview) | `onAction` | + +Status-by-status examples: + +```tsx +// uploading +{ status: "uploading", filename: "invoice.pdf", onAction: cancelUpload }; // before +{ status: "uploading", filename: "invoice.pdf", onCancel: cancelUpload }; // after + +// completed +{ status: "completed", filename: "invoice.pdf", onAction: deleteUpload }; // before +{ + status: "completed", + filename: "invoice.pdf", + onDelete: deleteUpload, + href: "/invoices/invoice.pdf", +}; // after + +// error +{ status: "error", filename: "invoice.pdf", onAction: removeFailedUpload }; // before +{ + status: "error", + filename: "invoice.pdf", + onRemove: removeFailedUpload, + onRetry: retryUpload, +}; // after + +// previously +{ status: "previously", filename: "invoice.pdf", onAction: deleteUpload }; // before +{ + status: "previously", + filename: "invoice.pdf", + onDelete: deleteUpload, + href: "/invoices/invoice.pdf", +}; // after +``` -- Use `href` to provide the Preview link for completed and previously uploaded files. -- Replace the deprecated `onAction` with `onCancel` for uploading files, `onDelete` for completed and previously uploaded files, and `onRemove` for failed files. -- Remove Link-only props from completed and previously uploaded statuses; the Preview action is now a button-styled link and no longer - accepts `download`, `icon`, `iconAlign`, `underline`, `tooltipMessage`, `tooltipPosition`, `ariaLabel`, `removeAriaLabelOnIcon`, - `isSkipLink`, `onMouseDown`, or ARIA attributes other than `aria-describedby` and `aria-labelledby`. Its accessible name is set - internally from the localized Preview text and the filename. -- `message` is now displayed for `status: "previously"`, so remove any value you do not want shown. +- For completed and previously uploaded files, Preview is now rendered as a button-styled link with a fixed accessible name format: + "`Preview` + filename" (localized). Do not pass link-only props such as `download`, `icon`, `iconAlign`, `underline`, + `tooltipMessage`, `tooltipPosition`, `ariaLabel`, `removeAriaLabelOnIcon`, `isSkipLink`, or `onMouseDown`. +- For `status: "previously"`, `message` is now shown in the UI. If you do not want extra text under the filename, omit `message`. +- `onDelete` for `status: "previously"` behaves differently by mode: + in single-file mode, Delete is shown so users can replace the current file; + in `multiple` mode, previously uploaded items are treated as historical read-only entries, so passing `onDelete` has no effect and no Delete action is shown. + Users can still delete current uploaded files in `multiple` mode via `status: "completed"` with `onDelete`. diff --git a/src/components/file-input/file-input.stories.tsx b/src/components/file-input/file-input.stories.tsx index 8a5722ca2a..412b59c933 100644 --- a/src/components/file-input/file-input.stories.tsx +++ b/src/components/file-input/file-input.stories.tsx @@ -33,7 +33,7 @@ const meta: Meta = { }; export default meta; -type Story = StoryObj; +type Story = StoryObj; const ParentContainer = styled.div<{ $width: string }>` box-sizing: border-box; @@ -72,35 +72,44 @@ const SelectedFileInput = (props: SelectedFileInputProps) => { ); }; -export const Default: Story = () => { - const [uploadStatus, setUploadStatus] = useState< - FileUploadStatusProps | undefined - >(); - const [error, setError] = useState(); - const onChange = (files: FileList) => { - action("onChange")(files); - if (files.length > 1) { - setError("Select only one file"); - return; - } - const file = files[0]; - if (!file) return; - setError(undefined); - setUploadStatus({ - status: "completed", - filename: file.name, - onDelete: () => setUploadStatus(undefined), - }); - }; +export const Default: Story = { + args: { + label: "File input", + multiple: false, + }, + argTypes: { + multiple: { control: false }, + }, + render: (args) => { + const [uploadStatus, setUploadStatus] = useState< + FileUploadStatusProps | undefined + >(); + const [error, setError] = useState(); + const onChange = (files: FileList) => { + action("onChange")(files); + if (files.length > 1) { + setError("Select only one file"); + return; + } + const file = files[0]; + if (!file) return; + setError(undefined); + setUploadStatus({ + status: "completed", + filename: file.name, + onDelete: () => setUploadStatus(undefined), + }); + }; - return ( - - ); + return ( + + ); + }, }; Default.storyName = "Default"; From cb19c055efa13c1c0f02ada31aacc20b1ce7e602 Mon Sep 17 00:00:00 2001 From: iryna Date: Wed, 2 Dec 2026 15:21:33 +0200 Subject: [PATCH 2/3] docs(file-input): clarify upload status props and fix story controls --- skills/carbon-react/components/file-input.md | 38 ++++++++++++-- .../file-upload-status.stories.tsx | 4 +- .../file-input/file-input-test.stories.tsx | 10 ++-- src/components/file-input/file-input.mdx | 52 +++++++++++++------ .../file-input/file-input.stories.tsx | 6 ++- 5 files changed, 81 insertions(+), 29 deletions(-) diff --git a/skills/carbon-react/components/file-input.md b/skills/carbon-react/components/file-input.md index 90c9272fa0..5dfd69f987 100644 --- a/skills/carbon-react/components/file-input.md +++ b/skills/carbon-react/components/file-input.md @@ -92,7 +92,7 @@ description: Carbon FileInput component props and usage examples. {...args} onChange={onChange} uploadStatus={args.uploadStatus ?? uploadStatus} - error={args.error ?? error} + error={args.error === "" ? error : (args.error ?? error)} /> ); } @@ -1144,15 +1144,37 @@ By default, the input error message appears below the label set, after the hint ## Props -### File Input +### File Input props Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. The deprecated `onAction` remains a primary-action fallback. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. -#### Migrating upload item props (`uploadStatus` entries) +### Upload status properties -`onAction` still works as a deprecated fallback, but new code should use the callback that matches each status: +Pass one item or an array of items to `uploadStatus`. Each item accepts the properties below according to its `status`. + +| Property | Applies to | Description | +| --- | --- | --- | +| `status` | All | Required. One of `"uploading"`, `"completed"`, `"error"`, or `"previously"`. | +| `filename` | All | Required. The filename shown on the card and used in action labels and announcements. | +| `id` | All | Optional stable, unique identifier. Use it when filenames can repeat so cards and completion announcements match the right file. | +| `message` | All | Optional text replacing the default status message. Previously uploaded files have no default message. Include the file state in custom messages so screen reader users can identify it. | +| `iconType` | All | Optional file icon. Defaults to an error icon for failed files and a generic file icon otherwise. Uploading files show a loader instead. | +| `thumbnailSrc` | All | Optional image URL that adds a thumbnail column. Completed and previously uploaded files show the image or a fallback icon; uploading files show a loader and failed files show an icon. | +| `progress` | `uploading` | Optional progress from 0 to 100, exposed to assistive technology. The spinner does not visually show the value. Omit when unknown. | +| `onCancel` | `uploading` | Cancels the upload. Required unless the deprecated `onAction` is supplied. | +| `onDelete` | `completed`, `previously` | Deletes the file. Required for `completed` unless `onAction` is supplied; optional for `previously` and ignored in multiple-file mode. | +| `onRemove` | `error` | Removes the failed item. Required unless the deprecated `onAction` is supplied. | +| `onRetry` | `error` | Optional callback that adds a Retry button. | +| `href` | `completed`, `previously` | Optional file URL. A non-empty value adds a Preview link. | +| `onAction` | All | Deprecated fallback for the status-specific primary action. Optional for `previously` and ignored in multiple-file mode for that status. | + +For `completed` and `previously` items, the type also accepts the props of the [Button](../?path=/docs/button--docs), except `aria-label`. When `href` is provided, these props are passed to the Preview link; for example, use `target` and `rel` to control how it opens. The status item's `id` identifies the item, rather than the Preview link. The Preview link's label, content, `size`, and `variantType` are set by FileInput. + +### Migrating status props + +Replace the deprecated `onAction` with `onCancel` for uploading files, `onDelete` for completed and previously uploaded files, and `onRemove` for failed files. `onAction` still works as a fallback: | `status` value | Preferred callback(s) | Legacy fallback | | -------------- | --------------------- | --------------- | @@ -1161,6 +1183,14 @@ Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploa | `error` | `onRemove` (+ optional `onRetry`) | `onAction` | | `previously` | optional `onDelete` (+ optional `href` for Preview) | `onAction` | +- Use `href` to provide the Preview link for completed and previously uploaded files. +- Remove Link-only props from completed and previously uploaded statuses. Preview is a button-styled link and does not accept `download`, `icon`, `iconAlign`, `underline`, `tooltipMessage`, `tooltipPosition`, `ariaLabel`, `removeAriaLabelOnIcon`, `isSkipLink`, or `onMouseDown`. Its accessible name is set internally from the localized Preview text and filename. Use `aria-describedby` or `aria-labelledby` for additional accessible descriptions or labels. +- For `status: "previously"`, `message` is now shown in the UI. If you do not want extra text under the filename, omit `message`. +- `onDelete` for `status: "previously"` behaves differently by mode: + in single-file mode, Delete is shown so users can replace the current file; + in `multiple` mode, previously uploaded items are treated as historical read-only entries, so passing `onDelete` has no effect and no Delete action is shown. + Users can still delete current uploaded files in `multiple` mode via `status: "completed"` with `onDelete`. + Status-by-status examples: ``` diff --git a/src/components/file-input/__internal__/file-upload-status/file-upload-status.stories.tsx b/src/components/file-input/__internal__/file-upload-status/file-upload-status.stories.tsx index bdd5dca0ad..133264dbfa 100644 --- a/src/components/file-input/__internal__/file-upload-status/file-upload-status.stories.tsx +++ b/src/components/file-input/__internal__/file-upload-status/file-upload-status.stories.tsx @@ -2,8 +2,8 @@ import { Meta, StoryObj } from "@storybook/react-vite"; import FileUploadStatus from "./file-upload-status.component"; /** - * Generates the `uploadStatus` props table in file-input.mdx. Tagged `!dev` - * so it does not appear in the sidebar. + * Internal story for FileUploadStatus. Tagged `!dev` so it does not appear in + * the sidebar. */ const meta: Meta = { diff --git a/src/components/file-input/file-input-test.stories.tsx b/src/components/file-input/file-input-test.stories.tsx index 6247ccf0b1..685d3300db 100644 --- a/src/components/file-input/file-input-test.stories.tsx +++ b/src/components/file-input/file-input-test.stories.tsx @@ -276,7 +276,7 @@ const StatusesSection = ({ ); -export const FileUploadStatuses = (args: Partial) => ( +export const FileUploadStatuses = () => ( <> {singleFileStatuses(true).map(({ name, status }) => ( @@ -288,7 +288,6 @@ export const FileUploadStatuses = (args: Partial) => ( inputHint={name} uploadStatus={status} onChange={() => {}} - {...args} /> ))} @@ -302,7 +301,6 @@ export const FileUploadStatuses = (args: Partial) => ( inputHint={name} uploadStatus={status} onChange={() => {}} - {...args} /> ))} @@ -316,7 +314,6 @@ export const FileUploadStatuses = (args: Partial) => ( uploadStatus={completedCustomSizeStatus} onChange={() => {}} {...dimensions} - {...args} /> ))} @@ -328,7 +325,6 @@ export const FileUploadStatuses = (args: Partial) => ( label="Files" uploadStatus={multiFileStatuses(true)} onChange={() => {}} - {...args} /> @@ -339,12 +335,14 @@ export const FileUploadStatuses = (args: Partial) => ( label="Files" uploadStatus={multiFileStatuses(false)} onChange={() => {}} - {...args} /> ); FileUploadStatuses.storyName = "File Upload Statuses"; +FileUploadStatuses.parameters = { + themeProvider: { chromatic: { theme: "sage" } }, +}; export const Validation = () => ( @@ -25,7 +24,9 @@ Allows one or more files to be selected or dropped and presents their controlled - [Examples](#examples) - [Validation states](#validation-states) - [Props](#props) -- [Migrating upload item props (`uploadStatus` entries)](#migrating-upload-item-props-uploadstatus-entries) + - [File Input props](#file-input-props) + - [Upload status properties](#upload-status-properties) + - [Migrating status props](#migrating-status-props) - [Translation keys](#translation-keys) ## Quick Start @@ -275,15 +276,37 @@ By default, the input error message appears below the label set, after the hint ## Props -### File Input +### File Input props Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. The deprecated `onAction` remains a primary-action fallback. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. -#### Migrating upload item props (`uploadStatus` entries) +### Upload status properties -`onAction` still works as a deprecated fallback, but new code should use the callback that matches each status: +Pass one item or an array of items to `uploadStatus`. Each item accepts the properties below according to its `status`. + +| Property | Applies to | Description | +| --- | --- | --- | +| `status` | All | Required. One of `"uploading"`, `"completed"`, `"error"`, or `"previously"`. | +| `filename` | All | Required. The filename shown on the card and used in action labels and announcements. | +| `id` | All | Optional stable, unique identifier. Use it when filenames can repeat so cards and completion announcements match the right file. | +| `message` | All | Optional text replacing the default status message. Previously uploaded files have no default message. Include the file state in custom messages so screen reader users can identify it. | +| `iconType` | All | Optional file icon. Defaults to an error icon for failed files and a generic file icon otherwise. Uploading files show a loader instead. | +| `thumbnailSrc` | All | Optional image URL that adds a thumbnail column. Completed and previously uploaded files show the image or a fallback icon; uploading files show a loader and failed files show an icon. | +| `progress` | `uploading` | Optional progress from 0 to 100, exposed to assistive technology. The spinner does not visually show the value. Omit when unknown. | +| `onCancel` | `uploading` | Cancels the upload. Required unless the deprecated `onAction` is supplied. | +| `onDelete` | `completed`, `previously` | Deletes the file. Required for `completed` unless `onAction` is supplied; optional for `previously` and ignored in multiple-file mode. | +| `onRemove` | `error` | Removes the failed item. Required unless the deprecated `onAction` is supplied. | +| `onRetry` | `error` | Optional callback that adds a Retry button. | +| `href` | `completed`, `previously` | Optional file URL. A non-empty value adds a Preview link. | +| `onAction` | All | Deprecated fallback for the status-specific primary action. Optional for `previously` and ignored in multiple-file mode for that status. | + +For `completed` and `previously` items, the type also accepts the props of the [Button](../?path=/docs/button--docs), except `aria-label`. When `href` is provided, these props are passed to the Preview link; for example, use `target` and `rel` to control how it opens. The status item's `id` identifies the item, rather than the Preview link. The Preview link's label, content, `size`, and `variantType` are set by FileInput. + +### Migrating status props + +Replace the deprecated `onAction` with `onCancel` for uploading files, `onDelete` for completed and previously uploaded files, and `onRemove` for failed files. `onAction` still works as a fallback: | `status` value | Preferred callback(s) | Legacy fallback | | -------------- | --------------------- | --------------- | @@ -292,6 +315,14 @@ Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploa | `error` | `onRemove` (+ optional `onRetry`) | `onAction` | | `previously` | optional `onDelete` (+ optional `href` for Preview) | `onAction` | +- Use `href` to provide the Preview link for completed and previously uploaded files. +- Remove Link-only props from completed and previously uploaded statuses. Preview is a button-styled link and does not accept `download`, `icon`, `iconAlign`, `underline`, `tooltipMessage`, `tooltipPosition`, `ariaLabel`, `removeAriaLabelOnIcon`, `isSkipLink`, or `onMouseDown`. Its accessible name is set internally from the localized Preview text and filename. Use `aria-describedby` or `aria-labelledby` for additional accessible descriptions or labels. +- For `status: "previously"`, `message` is now shown in the UI. If you do not want extra text under the filename, omit `message`. +- `onDelete` for `status: "previously"` behaves differently by mode: + in single-file mode, Delete is shown so users can replace the current file; + in `multiple` mode, previously uploaded items are treated as historical read-only entries, so passing `onDelete` has no effect and no Delete action is shown. + Users can still delete current uploaded files in `multiple` mode via `status: "completed"` with `onDelete`. + Status-by-status examples: ```tsx @@ -327,17 +358,6 @@ Status-by-status examples: }; // after ``` -- For completed and previously uploaded files, Preview is now rendered as a button-styled link with a fixed accessible name format: - "`Preview` + filename" (localized). Do not pass link-only props such as `download`, `icon`, `iconAlign`, `underline`, - `tooltipMessage`, `tooltipPosition`, `ariaLabel`, `removeAriaLabelOnIcon`, `isSkipLink`, or `onMouseDown`. -- For `status: "previously"`, `message` is now shown in the UI. If you do not want extra text under the filename, omit `message`. -- `onDelete` for `status: "previously"` behaves differently by mode: - in single-file mode, Delete is shown so users can replace the current file; - in `multiple` mode, previously uploaded items are treated as historical read-only entries, so passing `onDelete` has no effect and no Delete action is shown. - Users can still delete current uploaded files in `multiple` mode via `status: "completed"` with `onDelete`. - - - ## Translation keys The following keys are available to override the translations for this component by passing in a custom locale object to the diff --git a/src/components/file-input/file-input.stories.tsx b/src/components/file-input/file-input.stories.tsx index 412b59c933..83ebce6b87 100644 --- a/src/components/file-input/file-input.stories.tsx +++ b/src/components/file-input/file-input.stories.tsx @@ -79,6 +79,10 @@ export const Default: Story = { }, argTypes: { multiple: { control: false }, + onChange: { control: false }, + uploadStatus: { control: false }, + inputHint: { control: "text" }, + error: { control: "text" }, }, render: (args) => { const [uploadStatus, setUploadStatus] = useState< @@ -106,7 +110,7 @@ export const Default: Story = { {...args} onChange={onChange} uploadStatus={args.uploadStatus ?? uploadStatus} - error={args.error ?? error} + error={args.error === "" ? error : (args.error ?? error)} /> ); }, From 16908c812758a67f313f4b93e0e0de3788bf83e8 Mon Sep 17 00:00:00 2001 From: iryna Date: Fri, 4 Dec 2026 15:30:33 +0200 Subject: [PATCH 3/3] docs(file-input): move upload status docs above props and simplify wording --- skills/carbon-react/components/file-input.md | 11 +++-------- src/components/file-input/file-input.mdx | 20 +++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/skills/carbon-react/components/file-input.md b/skills/carbon-react/components/file-input.md index 5dfd69f987..10453a5ad0 100644 --- a/skills/carbon-react/components/file-input.md +++ b/skills/carbon-react/components/file-input.md @@ -1142,15 +1142,10 @@ This component supports input validation, see our [Validations](../?path=/docs/d By default, the input error message appears below the label set, after the hint text when provided, and before the drop zone. `validationMessagePositionTop={false}` is deprecated, but continues to render validation below the drop zone for existing consumers. Individual file upload errors remain with their file status. -## Props - -### File Input props - - +## Upload status properties -Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. The deprecated `onAction` remains a primary-action fallback. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. +The properties you need depend on the file's `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. `onAction` still works for now, but use the callback for that status instead. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. -### Upload status properties Pass one item or an array of items to `uploadStatus`. Each item accepts the properties below according to its `status`. @@ -1172,7 +1167,7 @@ Pass one item or an array of items to `uploadStatus`. Each item accepts the prop For `completed` and `previously` items, the type also accepts the props of the [Button](../?path=/docs/button--docs), except `aria-label`. When `href` is provided, these props are passed to the Preview link; for example, use `target` and `rel` to control how it opens. The status item's `id` identifies the item, rather than the Preview link. The Preview link's label, content, `size`, and `variantType` are set by FileInput. -### Migrating status props +## Migrating status props Replace the deprecated `onAction` with `onCancel` for uploading files, `onDelete` for completed and previously uploaded files, and `onRemove` for failed files. `onAction` still works as a fallback: diff --git a/src/components/file-input/file-input.mdx b/src/components/file-input/file-input.mdx index 77f78eca29..ef284df781 100644 --- a/src/components/file-input/file-input.mdx +++ b/src/components/file-input/file-input.mdx @@ -23,10 +23,9 @@ Allows one or more files to be selected or dropped and presents their controlled - [Quick Start](#quick-start) - [Examples](#examples) - [Validation states](#validation-states) +- [Upload status properties](#upload-status-properties) +- [Migrating status props](#migrating-status-props) - [Props](#props) - - [File Input props](#file-input-props) - - [Upload status properties](#upload-status-properties) - - [Migrating status props](#migrating-status-props) - [Translation keys](#translation-keys) ## Quick Start @@ -274,15 +273,10 @@ This component supports input validation, see our [Validations](../?path=/docs/d By default, the input error message appears below the label set, after the hint text when provided, and before the drop zone. `validationMessagePositionTop={false}` is deprecated, but continues to render validation below the drop zone for existing consumers. Individual file upload errors remain with their file status. -## Props - -### File Input props - - +## Upload status properties -Props for `uploadStatus` are discriminated by `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. The deprecated `onAction` remains a primary-action fallback. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. +The properties you need depend on the file's `status`. Use `onCancel` for uploading, `onDelete` for completed files, and `onRemove` plus optional `onRetry` for failures. In single-file mode, a previously uploaded file shows Delete when given `onDelete`; previously uploaded files are read-only in multiple-file mode, where `onDelete` is ignored. `onAction` still works for now, but use the callback for that status instead. Completed and previous files accept optional `href`; filenames remain text. Every status accepts an optional decorative `thumbnailSrc`. -### Upload status properties Pass one item or an array of items to `uploadStatus`. Each item accepts the properties below according to its `status`. @@ -304,7 +298,7 @@ Pass one item or an array of items to `uploadStatus`. Each item accepts the prop For `completed` and `previously` items, the type also accepts the props of the [Button](../?path=/docs/button--docs), except `aria-label`. When `href` is provided, these props are passed to the Preview link; for example, use `target` and `rel` to control how it opens. The status item's `id` identifies the item, rather than the Preview link. The Preview link's label, content, `size`, and `variantType` are set by FileInput. -### Migrating status props +## Migrating status props Replace the deprecated `onAction` with `onCancel` for uploading files, `onDelete` for completed and previously uploaded files, and `onRemove` for failed files. `onAction` still works as a fallback: @@ -358,6 +352,10 @@ Status-by-status examples: }; // after ``` +## Props + + + ## Translation keys The following keys are available to override the translations for this component by passing in a custom locale object to the