Skip to content

Commit 610776d

Browse files
(Picklist): make getPrevValue() and getNextValue() not wrap around
1 parent a4f0c44 commit 610776d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/scripts/Picklist.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
192192
if (!currentValue) return optionValues[0];
193193

194194
const currentIndex = optionValues.indexOf(currentValue);
195-
return optionValues[currentIndex + 1] || optionValues[0]; // wrap around
195+
return optionValues[
196+
Math.min(currentIndex + 1, optionValues.length - 1)
197+
]; // not wrap around
196198
},
197199
[getOptionValues]
198200
);
@@ -206,10 +208,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
206208
if (!currentValue) return optionValues[optionValues.length - 1];
207209

208210
const currentIndex = optionValues.indexOf(currentValue);
209-
return (
210-
optionValues[currentIndex - 1] ||
211-
optionValues[optionValues.length - 1]
212-
); // wrap around
211+
return optionValues[Math.max(currentIndex - 1, 0)]; // not wrap around
213212
},
214213
[getOptionValues]
215214
);

0 commit comments

Comments
 (0)