Skip to content

feat: react add mechanism to disable file items by exposing file state#21446

Merged
devadula-nandan merged 17 commits into
carbon-design-system:mainfrom
devadula-nandan:feat/disable-prop-support-on-file-uploader-item
May 18, 2026
Merged

feat: react add mechanism to disable file items by exposing file state#21446
devadula-nandan merged 17 commits into
carbon-design-system:mainfrom
devadula-nandan:feat/disable-prop-support-on-file-uploader-item

Conversation

@devadula-nandan

@devadula-nandan devadula-nandan commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Closes #17882

adds mechanism to disable file items

Note

There are 2 variants of file uploaders FileUploader and FileUploaderDropContainer for react and web components.
The Web Components implementation intentionally follows the compound component architecture. This allows adopters to pass any relevant child components, which then consume and react to the parent’s state.

Web Components example:
https://stackblitz.com/edit/vitejs-vite-k2rjvtyp?file=src%2Fapp-root.ts

In contrast, the React implementation is inconsistent:
Table showing compound component architecture support

React Web Components
FileUploader ❌ file-uploader ✅
FileUploaderDropContainer ✅ file-uploader-drop-container ✅

The React FileUploader manages file mapping internally and renders its own markup, which breaks the compound component pattern. This limits flexibility and prevents adopters from fully controlling rendering and behavior.

By comparison, FileUploaderDropContainer in React does follow the compound component approach. It allows adopters to:

  • Map files themselves
  • Control rendering
  • Use the provided FileUploaderItem as a child
  • Apply custom state, validations, or advanced logic

Examples:

Taking control of child rendering inside FileUploader is overly restrictive and risks forcing the library to support every possible use case. Refactoring this component to align with the compound component architecture would improve flexibility; however, it would be a breaking change, as adopters would need to explicitly pass FileUploaderItem, similar to the current FileUploaderDropContainer usage.

Supporting a non–compound component architecture in FileUploader introduces duplication and inconsistencies, as discussed in #21166.

Changelog

New

  • Added a new method setCurrentFiles to the FileUploader, allowing adopters to update the state of their files.
  • Introduced a disabled state to FileUploaderItem and file-uploader-item for use in any compound component pattern.

Changed

  • Updated stories to demonstrate the new behavior:
    • Added a story under the feature flag for React.

Testing / Reviewing

  • Open the Controlled File State story with the feature flag enabled.
  • Upload files and disable the FileUploader. all items should appear disabled.
  • You can also selectively disable specific files by calling setCurrentFiles with your desired state.
  • Ensure that both FileUploaderItem and file-uploader-item have a disabled property in their respective stories.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

@netlify

netlify Bot commented Feb 6, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 4f64636
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6a0b775cbbd5ba00089e7203
😎 Deploy Preview https://deploy-preview-21446--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Feb 6, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4f64636
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6a0b775cfa44c500084a75fa
😎 Deploy Preview https://deploy-preview-21446--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Feb 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.51%. Comparing base (463edd5) to head (4f64636).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21446      +/-   ##
==========================================
- Coverage   95.51%   95.51%   -0.01%     
==========================================
  Files         582      582              
  Lines       50399    50409      +10     
  Branches     6763     6788      +25     
==========================================
+ Hits        48141    48147       +6     
- Misses       2126     2130       +4     
  Partials      132      132              
Flag Coverage Δ
main-packages 89.24% <100.00%> (+0.05%) ⬆️
web-components 98.07% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@devadula-nandan devadula-nandan marked this pull request as ready for review February 9, 2026 10:45
@devadula-nandan devadula-nandan requested a review from a team as a code owner February 9, 2026 10:45
Comment thread packages/react/src/components/FileUploader/FileUploader.stories.js Outdated
Comment thread packages/react/src/components/FileUploader/stories/drag-and-drop-single.js Outdated
Comment thread packages/react/src/components/FileUploader/FileUploader.featureflag.mdx Outdated
Comment thread packages/react/src/components/FileUploader/FileUploader.tsx
Comment thread packages/react/src/components/FileUploader/FileUploader.tsx

@sangeethababu9223 sangeethababu9223 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @devadula-nandan,
I think we need to use Array.isArray here

Comment thread packages/react/src/components/FileUploader/stories/drag-and-drop-single.js Outdated
Comment thread packages/react/src/components/FileUploader/stories/drag-and-drop-single.js Outdated
devadula-nandan and others added 2 commits April 10, 2026 12:18
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
@devadula-nandan

Copy link
Copy Markdown
Contributor Author

Hey @devadula-nandan, I think we need to use Array.isArray here

done

@sangeethababu9223 sangeethababu9223 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @devadula-nandan! This looks good to me.

My only suggestion is that if you want to get rid of getSelectedFileClasses, you could inline it like this since it’s not reused anywhere else:

displayFiles.map((file) => {
  const selectedFileClasses = classNames(
    `${prefix}--file__selected-file`,
    {
      [`${prefix}--file__selected-file--md`]:
        size === 'field' || size === 'md',
      [`${prefix}--file__selected-file--sm`]:
        size === 'small' || size === 'sm',
      [`${prefix}--file__selected-file--disabled`]: file.disabled,
    }
  );

  return (
    <span
      key={file.key}
      className={selectedFileClasses}
      ref={(node) => {
        nodes[file.index] = node as HTMLSpanElement;
      }}
      {...other}
    >
      {/* content */}
    </span>
  );
});

@tay1orjones tay1orjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm, but needs tests

@netlify

netlify Bot commented May 18, 2026

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 4f64636
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6a0b775cfa44c500084a75fc
😎 Deploy Preview https://deploy-preview-21446--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@devadula-nandan devadula-nandan added this pull request to the merge queue May 18, 2026
Merged via the queue into carbon-design-system:main with commit 3a7a06c May 18, 2026
40 of 42 checks passed
@devadula-nandan devadula-nandan deleted the feat/disable-prop-support-on-file-uploader-item branch May 18, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: FileUploader disabled does not disable deleting selected files

4 participants