feat: react add mechanism to disable file items by exposing file state#21446
Conversation
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sangeethababu9223
left a comment
There was a problem hiding this comment.
Hey @devadula-nandan,
I think we need to use Array.isArray here
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com>
done |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Overall lgtm, but needs tests
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
3a7a06c
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
The React
FileUploadermanages 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,
FileUploaderDropContainerin React does follow the compound component approach. It allows adopters to:FileUploaderItemas a childExamples:
Taking control of child rendering inside
FileUploaderis 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 passFileUploaderItem, similar to the currentFileUploaderDropContainerusage.Supporting a non–compound component architecture in
FileUploaderintroduces duplication and inconsistencies, as discussed in #21166.Changelog
New
setCurrentFilesto theFileUploader, allowing adopters to update the state of their files.disabledstate toFileUploaderItemandfile-uploader-itemfor use in any compound component pattern.Changed
Testing / Reviewing
Controlled File Statestory with the feature flag enabled.FileUploader. all items should appear disabled.setCurrentFileswith your desired state.FileUploaderItemandfile-uploader-itemhave adisabledproperty in their respective stories.PR Checklist
As the author of this PR, before marking ready for review, confirm you:
More details can be found in the pull request guide