Skip to content

Commit 39bb81c

Browse files
Respect existing file incrementation for uploaded files
1 parent aa6e498 commit 39bb81c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/new-lights-dig.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@obosbbl/grunnmuren-react": patch
3+
---
4+
5+
Fix file count incrementation in FileUpload.

packages/react/src/file-upload/file-upload.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ function uniqueFileNames(files: File[]) {
8585
const extension = fileName.match(/(\.[^.]+)$/)?.[0] || '';
8686

8787
if (!fileNameCounts[baseName]) {
88-
fileNameCounts[baseName] = 0;
88+
// Extract any number from the file name (if any, otherwise default to 0)
89+
const baseNameCount = Number.parseInt(
90+
fileName.match(/\((\d+)\)/)?.[1] ?? '0',
91+
);
92+
fileNameCounts[baseName] = baseNameCount;
8993
}
9094

9195
fileNameCounts[baseName]++;

0 commit comments

Comments
 (0)