✨ Add max file selection support to uploader#2423
Merged
Conversation
sazedul-haque
approved these changes
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds maximum file-count support to the shared file uploader so upload limits can be enforced consistently across native file input, drag and drop, and the WordPress media library flow.
Problem
The uploader already validated file size and file type, but it had no component-level limit for how many files a user could add in one field. That meant forms using the uploader could allow more files than intended, especially when users mixed repeated selections, drag and drop, and WordPress media selections. The PHP component API also had no way to declare a file-count limit, so consumers could not configure this behavior from server-rendered component usage.
Root Cause
The TypeScript uploader component only tracked
multipleas a boolean and merged new selections without checking the final count. Separately, the PHPFileUploaderbuilder did not expose anymax_filesoption, so the limit could not be passed into the Alpine component config or demonstrated in the component demo.Fix
The uploader now accepts a
maxFilesprop in the TypeScript component and passes it through to the WordPress media service. For native input and drag/drop flows, the component validates the deduplicated merged file list before mutating state and shows the existing limit error message when the final selection exceeds the configured maximum. On the PHP side, theFileUploadercomponent now exposes amax_files()setter and forwards that value into the frontend config. The demo component has also been updated to show a concretemaxFiles: 3example so the new API is visible and testable.Validation
npx eslint assets/core/ts/components/file-uploader.tsphp -l components/FileUploader.phpphp -l templates/demo-components/components/file-uploader.php