Skip to content

Commit 16d3abc

Browse files
fix(plugin-chatbot): composer accept list reads the HTML accept grammar; a refused type is named to the user (#35330)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg48yiCyRmnqoUoHcQ9VbBp6)_ Fixes #35276 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:AI 聊天输入框的附件类型判断改为按 HTML `accept` 语法(`.ext` 按文件名后缀、`type/*` 按 MIME 前缀、其余按 MIME 精确匹配,均不区分大小写);被拒的文件在输入框上方的提示条里点名并列出允许的类型。 - 为什么改:默认允许列表是 `.pdf,.csv,.xlsx…` 这类后缀,旧逻辑拿它和 MIME 类型逐字比较,永远不相等——用户选了 CSV / PDF 却静默附不上,只有控制台有一条 warn。 - 风险与回滚:仅 `@object-ui/plugin-chatbot` 一个包、纯前端;回滚即 revert 本 PR。`onError` 对“部分被拒”的选择多回调一次(同 `code: 'accept'`,带 `files`),不读 `files` 的宿主行为不变。 - 先看:`ui/packages/plugin-chatbot/src/elements/prompt-input.tsx`(`fileMatchesAccept` 与 `addLocal` 的拒收上报)、`ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx`(`handlePromptInputError` 的 accept 分支与同一次选择的提示合并)、测试文件 `ChatbotEnhanced.sendError.test.tsx` 新增的 describe。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.sendError.test.tsx`,预期 22 passed(含新增 8 条 objectstack#35276 用例)。 - 需要你做的:无,席位落地。 ## What changes - `PromptInput` (vendored AI Elements, `elements/prompt-input.tsx`): the accept check moves into one module-level helper, `fileMatchesAccept`, that reads the HTML `accept` grammar: a `.ext` token matches the end of the file NAME, a `type/*` token matches the MIME prefix, any other token matches the MIME type exactly, all case-insensitive; an empty list admits everything. The helper is not exported (no new public symbol). - `addLocal` now reports EVERY type-refused file through `onError({ code: 'accept', files })`, in the all-refused case and in a mixed pick, mirroring the `max_file_size` shape the previous composer-notice change added. Before, a mixed pick dropped the type-failing files with no report, and the all-refused report carried no `files`. - `ChatbotEnhanced`: `handlePromptInputError` shows an `accept` refusal in the existing `ComposerNotice` band (`chat-attachment-refused`), naming the refused files and the accepted list. The sentence reuses the existing pack key `fields.file.typeNotAccepted` (present in every built-in locale pack), so no locale file changes and no new key. Refusals reported by one pick (wrong type and over size) are joined into one notice instead of the second replacing the first. - Changeset: `.changeset/35276-composer-accept-tokens.md`, `patch` on `@object-ui/plugin-chatbot`. ## Tests New top-level `describe` in the existing composer-notice harness `ChatbotEnhanced.sendError.test.tsx` (8 cases): - a CSV and a PDF picked with the default accept list attach, with no notice; - a `.ext` token matches the name case-insensitively whatever type the browser reported (`EXPORT.CSV` with an empty type, `Book.XLSX` as `application/octet-stream`); - extension, wildcard and exact-MIME tokens (`image/*,.CSV,application/pdf`) each admit their own files and nothing else (`video/mp4` and `application/x-pdf` refused); - a refused type shows the notice (`role="alert"`) naming the file and the accepted list, and is not attached; - a mixed pick attaches the accepted file and names only the refused one; - one pick refused for type and for size names both files; - CONTROL: a `.png` with the default list attaches with no notice; - under zh the notice is the zh pack sentence, not the English one (proves the borrowed key resolves through the pack, not only through its English default). <details><summary>Package run and type-check (head f14d489)</summary> ``` pnpm --filter @object-ui/plugin-chatbot run type-check && pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-chatbot/ Test Files 103 passed (103) Tests 1058 passed (1058) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablations (each mutation proven on disk by scripts/ablation-replace.mjs, restored to the HEAD blob)</summary> The test resolves `../ChatbotEnhanced` from source, so no rebuild is involved. 1. Extension arm off in `fileMatchesAccept` (`if (token.startsWith(".")) {` to `if (false && token.startsWith(".")) {`): 4 failed / 18 passed, the CSV-and-PDF, case-insensitive-extension, grammar and mixed-pick cases red. 2. Notice branch off in `handlePromptInputError` (the `e.code === 'accept'` arm to `false`): 5 failed / 17 passed, the grammar, refused-type, mixed-pick, type-and-size and zh cases red. 3. Mixed-pick report off in `addLocal` (`if (refused.length > 0) {` to `if (refused.length > 0 && accepted.length === 0) {`): 3 failed / 19 passed, the grammar, mixed-pick and type-and-size cases red. Every restore: blob equals HEAD and `git diff HEAD` is empty. </details> ## Acceptance notes - Multi-file refusal grammar: the borrowed sentence is singular (`"NAME" is not an accepted file type (LIST)`); a pick refusing several files lists their names inside it. A plural-aware sentence would need a new key in every published locale pack (a widening), which the dispatch asked to avoid when an existing sentence fits. - Two copies of the accept grammar now exist under `ui/`: this one and the private `matchesAcceptEntry` / `acceptError` in `@object-ui/fields` `FileField.tsx`. They differ deliberately in one point: the field widget admits a pick no entry can be weighed against (mirroring the server's save-time check), while the composer has no server check behind it and refuses. Noted, not filed (no defect). - `PromptInputProvider`'s `attachments.add` (provider mode) applies no accept, size or count check at all; `ChatbotEnhanced` does not use provider mode, so nothing reaches it today. Noted, not filed. - Browser: verified in jsdom only (as the card was filed); no live-app run. ## Verification <details><summary>Derived gate families (node scripts/pm/dispatch-gates.mjs --commands, tree f14d489)</summary> All 39 derived families exit 0 locally; reconciliation: ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ✓ dispatch-gates --ran: 39 derived famil(ies) accounted for — 39 run, 0 NOT-MEASURED (a DERIVED zero — all 39 recorded an exit code and none of them is 3). ``` Also run: `pnpm check:new-line-citations` (ui): `VERDICT new-cross-file-line-citations: 0 new citation(s)`. Every family CI runs is read from this PR's check-runs, not re-run here. </details> `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0` (against origin/main, 0 PR heads sharing a file). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6296909 commit 16d3abc

4 files changed

Lines changed: 215 additions & 31 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/plugin-chatbot': patch
3+
---
4+
5+
fix(plugin-chatbot): the chat composer's accept list reads the HTML `accept` grammar, so a picked CSV, PDF or spreadsheet attaches, and a file of a refused type is named to the user
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The vendored `PromptInput` compared every `accept` token with the file's MIME type, so the extension tokens of `ChatbotEnhanced`'s default list (`.pdf`, `.csv`, `.xlsx`, …) never matched: a picked CSV or PDF did not attach, and the refusal reached only `console.warn`. A token is now read the way the file picker reads it: `.ext` matches the end of the file name, `type/*` matches the MIME prefix, any other token matches the MIME type exactly, all case-insensitive.
11+
12+
A file that still fails is shown to the user: `ChatbotEnhanced` names it, with the accepted list, in the same notice above the composer that names an over-size file, in the user's language (the existing pack sentence `fields.file.typeNotAccepted`; no new key). When one pick refuses files for type and for size, the notice names both.
13+
14+
`PromptInput` now reports every type-refused file of a pick through `onError` with `code: 'accept'` and the refused files in `files`. Before, it reported only a pick where every file was refused, without `files`; a pick that mixed types attached the matching files and dropped the rest with no report. An `onError` handler that ignores `files` sees one more call, for a mixed pick, with the same `code`.

‎ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,22 +3326,47 @@ const ChatbotEnhanced = React.forwardRef<HTMLDivElement, ChatbotEnhancedProps>(
33263326
// refuses for size is named to the user with the limit, instead of only
33273327
// reaching `console.warn` while the file silently fails to attach. Cleared
33283328
// by the next send or the notice's close button; a later refusal replaces it.
3329+
// A file whose type `acceptedFileTypes` does not admit is named the same way,
3330+
// with the accepted list. Refusals reported by ONE pick (a wrong-type file
3331+
// and an over-size one) all show: the sentences of the same tick are joined.
33293332
const [attachmentNotice, setAttachmentNotice] = React.useState<string | null>(null);
3333+
const attachmentNoticeTickRef = React.useRef<string[] | null>(null);
33303334
const handlePromptInputError = React.useCallback(
33313335
(e: { code: string; message: string; files?: File[] }) => {
3336+
let sentence: string | null = null;
33323337
if (e.code === 'max_file_size' && e.files?.length) {
3333-
setAttachmentNotice(
3334-
tCount('chatbot.composer.fileTooLarge', {
3335-
files: e.files.map((f) => f.name).join(', '),
3336-
limit: formatSizeLimit(maxFileSize, composerLanguage),
3337-
defaultValue: 'Not attached, over the {{limit}} limit: {{files}}',
3338-
}),
3339-
);
3338+
sentence = tCount('chatbot.composer.fileTooLarge', {
3339+
files: e.files.map((f) => f.name).join(', '),
3340+
limit: formatSizeLimit(maxFileSize, composerLanguage),
3341+
defaultValue: 'Not attached, over the {{limit}} limit: {{files}}',
3342+
});
3343+
} else if (e.code === 'accept' && e.files?.length) {
3344+
const allowed = acceptedFileTypes
3345+
.split(',')
3346+
.map((s) => s.trim())
3347+
.filter(Boolean)
3348+
.join(', ');
3349+
sentence = tCount('fields.file.typeNotAccepted', {
3350+
name: e.files.map((f) => f.name).join(', '),
3351+
accept: allowed,
3352+
defaultValue: '"{{name}}" is not an accepted file type ({{accept}})',
3353+
});
3354+
}
3355+
if (sentence === null) {
3356+
console.warn('[plugin-chatbot] prompt-input error', e);
33403357
return;
33413358
}
3342-
console.warn('[plugin-chatbot] prompt-input error', e);
3359+
if (attachmentNoticeTickRef.current === null) {
3360+
const tick: string[] = [];
3361+
attachmentNoticeTickRef.current = tick;
3362+
queueMicrotask(() => {
3363+
if (attachmentNoticeTickRef.current === tick) attachmentNoticeTickRef.current = null;
3364+
});
3365+
}
3366+
attachmentNoticeTickRef.current.push(sentence);
3367+
setAttachmentNotice(attachmentNoticeTickRef.current.join(' '));
33433368
},
3344-
[tCount, maxFileSize, composerLanguage],
3369+
[tCount, maxFileSize, composerLanguage, acceptedFileTypes],
33453370
);
33463371
const handleSubmit = React.useCallback(
33473372
(payload: PromptInputMessage) => {

‎ui/packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.sendError.test.tsx‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* restores its own last typed submit and no chip text.
1313
* A file the composer refuses for size names itself and the limit in the same
1414
* band above the composer, and is not attached (objectstack#34463).
15+
* The accept list reads the HTML `accept` grammar (`.ext` / `type/*` / exact
16+
* MIME), and a file it refuses names itself and the accepted list in that same
17+
* band (objectstack#35276).
1518
*/
1619
import '@testing-library/jest-dom/vitest';
1720
import { describe, it, expect, vi, beforeEach } from 'vitest';
@@ -394,3 +397,120 @@ describe('ChatbotEnhanced composer — a file over maxFileSize is named to the u
394397
expect(notice).not.toHaveTextContent(enLead);
395398
});
396399
});
400+
401+
describe('ChatbotEnhanced composer — the accept list reads the HTML accept grammar, and a refused type is named to the user (objectstack#35276)', () => {
402+
const DEFAULT_ACCEPT_SHOWN = 'image/*, .pdf, .doc, .docx, .txt, .csv, .tsv, .xlsx, .xlsm';
403+
const file = (name: string, type: string, bytes = 10) => new File([new Uint8Array(bytes)], name, { type });
404+
405+
beforeEach(() => {
406+
// jsdom has no object URLs; the composer makes one per attached file.
407+
Object.defineProperty(URL, 'createObjectURL', { configurable: true, value: vi.fn(() => 'blob:attached') });
408+
Object.defineProperty(URL, 'revokeObjectURL', { configurable: true, value: vi.fn() });
409+
});
410+
411+
function pick(container: HTMLElement, files: File[]) {
412+
const input = container.querySelector('input[type="file"]') as HTMLInputElement;
413+
Object.defineProperty(input, 'files', { configurable: true, value: files });
414+
fireEvent.change(input);
415+
}
416+
417+
/** A non-image attachment chip shows the file name as its own text. */
418+
const attached = (name: string) => screen.queryByText(name, { selector: 'span' });
419+
420+
it('a CSV and a PDF picked with the default accept list attach, with no notice', () => {
421+
const { container } = render(<ChatbotEnhanced placeholder="Ask…" enableFileUpload />);
422+
pick(container, [file('data.csv', 'text/csv'), file('report.pdf', 'application/pdf')]);
423+
424+
expect(attached('data.csv')).toBeInTheDocument();
425+
expect(attached('report.pdf')).toBeInTheDocument();
426+
expect(screen.queryByTestId('chat-attachment-refused')).toBeNull();
427+
});
428+
429+
it('a `.ext` token matches the name case-insensitively, whatever type the browser reported', () => {
430+
const { container } = render(<ChatbotEnhanced placeholder="Ask…" enableFileUpload />);
431+
pick(container, [file('EXPORT.CSV', ''), file('Book.XLSX', 'application/octet-stream')]);
432+
433+
expect(attached('EXPORT.CSV')).toBeInTheDocument();
434+
expect(attached('Book.XLSX')).toBeInTheDocument();
435+
expect(screen.queryByTestId('chat-attachment-refused')).toBeNull();
436+
});
437+
438+
it('extension, wildcard and exact-MIME tokens each admit their own files and nothing else', () => {
439+
const { container } = render(
440+
<ChatbotEnhanced placeholder="Ask…" enableFileUpload acceptedFileTypes="image/*,.CSV,application/pdf" />,
441+
);
442+
pick(container, [
443+
file('photo.png', 'image/png'), // image/* — MIME prefix
444+
file('data.csv', 'text/csv'), // .CSV — extension, upper-case token
445+
file('doc.bin', 'application/pdf'), // application/pdf — exact MIME, the name does not matter
446+
file('clip.mp4', 'video/mp4'), // no token admits it
447+
file('scan.pdf', 'application/x-pdf'), // exact MIME is not a prefix and no `.pdf` token is listed
448+
]);
449+
450+
expect(screen.getByAltText('photo.png')).toBeInTheDocument();
451+
expect(attached('data.csv')).toBeInTheDocument();
452+
expect(attached('doc.bin')).toBeInTheDocument();
453+
expect(attached('clip.mp4')).toBeNull();
454+
expect(attached('scan.pdf')).toBeNull();
455+
const notice = screen.getByTestId('chat-attachment-refused');
456+
expect(notice).toHaveTextContent('clip.mp4');
457+
expect(notice).toHaveTextContent('scan.pdf');
458+
expect(notice).not.toHaveTextContent('photo.png');
459+
});
460+
461+
it('a refused type shows a notice naming the file and the accepted list, and is not attached', () => {
462+
const { container } = render(<ChatbotEnhanced placeholder="Ask…" enableFileUpload />);
463+
pick(container, [file('setup.exe', 'application/x-msdownload')]);
464+
465+
const notice = screen.getByTestId('chat-attachment-refused');
466+
expect(notice).toHaveAttribute('role', 'alert');
467+
expect(notice).toHaveTextContent('setup.exe');
468+
expect(notice).toHaveTextContent(DEFAULT_ACCEPT_SHOWN);
469+
expect(attached('setup.exe')).toBeNull();
470+
});
471+
472+
it('a mixed pick attaches the accepted file and names only the refused one', () => {
473+
const { container } = render(<ChatbotEnhanced placeholder="Ask…" enableFileUpload />);
474+
pick(container, [file('setup.exe', 'application/x-msdownload'), file('data.csv', 'text/csv')]);
475+
476+
expect(attached('data.csv')).toBeInTheDocument();
477+
const notice = screen.getByTestId('chat-attachment-refused');
478+
expect(notice).toHaveTextContent('setup.exe');
479+
expect(notice).not.toHaveTextContent('data.csv');
480+
});
481+
482+
it('one pick refused for type AND for size names both files', () => {
483+
const { container } = render(<ChatbotEnhanced placeholder="Ask…" enableFileUpload maxFileSize={1024} />);
484+
pick(container, [file('setup.exe', 'application/x-msdownload'), file('big.png', 'image/png', 1025)]);
485+
486+
const notice = screen.getByTestId('chat-attachment-refused');
487+
expect(notice).toHaveTextContent('setup.exe');
488+
expect(notice).toHaveTextContent('big.png');
489+
});
490+
491+
it('CONTROL: a .png picked with the default accept list attaches with no notice', () => {
492+
const { container } = render(<ChatbotEnhanced placeholder="Ask…" enableFileUpload />);
493+
pick(container, [file('small.png', 'image/png')]);
494+
495+
expect(screen.getByAltText('small.png')).toBeInTheDocument();
496+
expect(screen.queryByTestId('chat-attachment-refused')).toBeNull();
497+
});
498+
499+
it('under zh the notice is the zh pack sentence, not the English one', async () => {
500+
const zhLead = zh.fields.file.typeNotAccepted.split('{{name}}')[1].split('{{')[0];
501+
const enLead = en.fields.file.typeNotAccepted.split('{{name}}')[1].split('{{')[0];
502+
expect(zhLead).not.toBe(enLead);
503+
const { container } = render(
504+
<I18nProvider config={{ defaultLanguage: 'zh', detectBrowserLanguage: false }} persistLanguage={false}>
505+
<ChatbotEnhanced placeholder="Ask…" enableFileUpload />
506+
</I18nProvider>,
507+
);
508+
await screen.findByPlaceholderText('Ask…');
509+
pick(container, [file('setup.exe', 'application/x-msdownload')]);
510+
511+
const notice = await screen.findByTestId('chat-attachment-refused');
512+
expect(notice).toHaveTextContent(zhLead.trim());
513+
expect(notice).toHaveTextContent('setup.exe');
514+
expect(notice).not.toHaveTextContent(enLead.trim());
515+
});
516+
});

‎ui/packages/plugin-chatbot/src/elements/prompt-input.tsx‎

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,38 @@ export const PromptInputActionAddAttachments = ({
455455
);
456456
};
457457

458+
/**
459+
* Whether `file` is admitted by `accept`, read in the HTML `accept` grammar
460+
* the file picker itself uses: a `.ext` token matches the end of the file
461+
* NAME, a `type/*` token matches the MIME prefix, any other token matches the
462+
* MIME type exactly — all case-insensitive. An empty list admits everything.
463+
* A `.ext` token is never compared with `File.type`: no MIME type starts with
464+
* a dot.
465+
*/
466+
function fileMatchesAccept(
467+
file: { name: string; type: string },
468+
accept: string | undefined
469+
): boolean {
470+
const tokens = (accept ?? "")
471+
.split(",")
472+
.map((s) => s.trim().toLowerCase())
473+
.filter(Boolean);
474+
if (tokens.length === 0) {
475+
return true;
476+
}
477+
const name = file.name.toLowerCase();
478+
const mime = (file.type || "").toLowerCase();
479+
return tokens.some((token) => {
480+
if (token.startsWith(".")) {
481+
return name.endsWith(token);
482+
}
483+
if (token.endsWith("/*")) {
484+
return mime.startsWith(token.slice(0, -1)); // image/* -> image/
485+
}
486+
return mime === token;
487+
});
488+
}
489+
458490
export type PromptInputMessage = {
459491
text: string;
460492
files: FileUIPart[];
@@ -479,8 +511,9 @@ export type PromptInputProps = Omit<
479511
message: string;
480512
/**
481513
* The files this refusal turned away, so a host can name them to the
482-
* user. Set on `max_file_size`: every over-size file of the pick, whether
483-
* the rest of the pick attached or not.
514+
* user. Set on `max_file_size` (every over-size file of the pick) and on
515+
* `accept` (every file of the pick whose type `accept` does not admit),
516+
* whether the rest of the pick attached or not.
484517
*/
485518
files?: File[];
486519
}) => void;
@@ -525,36 +558,28 @@ export const PromptInput = ({
525558
}, []);
526559

527560
const matchesAccept = useCallback(
528-
(f: File) => {
529-
if (!accept || accept.trim() === "") {
530-
return true;
531-
}
532-
533-
const patterns = accept
534-
.split(",")
535-
.map((s) => s.trim())
536-
.filter(Boolean);
537-
538-
return patterns.some((pattern) => {
539-
if (pattern.endsWith("/*")) {
540-
const prefix = pattern.slice(0, -1); // e.g: image/* -> image/
541-
return f.type.startsWith(prefix);
542-
}
543-
return f.type === pattern;
544-
});
545-
},
561+
(f: File) => fileMatchesAccept(f, accept),
546562
[accept]
547563
);
548564

549565
const addLocal = useCallback(
550566
(fileList: File[] | FileList) => {
551567
const incoming = Array.from(fileList);
552568
const accepted = incoming.filter((f) => matchesAccept(f));
553-
if (incoming.length && accepted.length === 0) {
569+
const refused = incoming.filter((f) => !matchesAccept(f));
570+
// Report EVERY type-refused file, a mixed pick included, the same way
571+
// over-size files are reported below.
572+
if (refused.length > 0) {
554573
onError?.({
555574
code: "accept",
556-
message: "No files match the accepted types.",
575+
message:
576+
accepted.length === 0
577+
? "No files match the accepted types."
578+
: "Some files do not match the accepted types and were not added.",
579+
files: refused,
557580
});
581+
}
582+
if (accepted.length === 0) {
558583
return;
559584
}
560585
const withinSize = (f: File) =>

0 commit comments

Comments
 (0)