Skip to content

✨ Add max file selection support to uploader#2423

Merged
b-l-i-n-d merged 1 commit into4.0.0-devfrom
file-uploader-max-files-support
Mar 10, 2026
Merged

✨ Add max file selection support to uploader#2423
b-l-i-n-d merged 1 commit into4.0.0-devfrom
file-uploader-max-files-support

Conversation

@b-l-i-n-d
Copy link
Collaborator

@b-l-i-n-d b-l-i-n-d commented Mar 9, 2026

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 multiple as a boolean and merged new selections without checking the final count. Separately, the PHP FileUploader builder did not expose any max_files option, so the limit could not be passed into the Alpine component config or demonstrated in the component demo.

Fix

The uploader now accepts a maxFiles prop 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, the FileUploader component now exposes a max_files() setter and forwards that value into the frontend config. The demo component has also been updated to show a concrete maxFiles: 3 example so the new API is visible and testable.

Validation

  • npx eslint assets/core/ts/components/file-uploader.ts
  • php -l components/FileUploader.php
  • php -l templates/demo-components/components/file-uploader.php

@b-l-i-n-d b-l-i-n-d changed the title feat(file-uploader): add max file selection support ✨ Add max file selection support to uploader Mar 9, 2026
@b-l-i-n-d b-l-i-n-d added the 4.0.0 Tutor v4.w0w label Mar 9, 2026
@b-l-i-n-d b-l-i-n-d changed the base branch from master to 4.0.0-dev March 9, 2026 07:43
@b-l-i-n-d b-l-i-n-d requested a review from sazedul-haque March 9, 2026 07:43
@b-l-i-n-d b-l-i-n-d marked this pull request as ready for review March 9, 2026 07:43
@b-l-i-n-d b-l-i-n-d merged commit 837237c into 4.0.0-dev Mar 10, 2026
10 of 13 checks passed
@b-l-i-n-d b-l-i-n-d deleted the file-uploader-max-files-support branch March 10, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0.0 Tutor v4.w0w

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants