Skip to content

Commit b5f692d

Browse files
committed
fix: prevent array mismatch in MultiPicker selections
- Truncate selections array to components.length before padding - Prevents index out-of-bounds crashes when selections is longer than components - Ensures selections and components arrays are always synchronized
1 parent 3e0f3a2 commit b5f692d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/components/SwiftUI/MultiPicker.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ export const MultiPicker = <T extends string>({
6363
[onChangeProp],
6464
);
6565

66-
// .map((selection) => String(selection) as T)
67-
const normalizedSelections = selections ? fillArray(selections, components.length, "" as T) : undefined;
66+
// Ensure selections array matches components length by truncating first, then padding
67+
const normalizedSelections = selections
68+
? fillArray(selections.slice(0, components.length), components.length, "" as T)
69+
: undefined;
6870
const normalizedComponents = useMemo(
6971
() =>
7072
components.map((component) => {

0 commit comments

Comments
 (0)