Skip to content

Commit f478300

Browse files
committed
avoid dupe select box options
1 parent cbd0cc8 commit f478300

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/webviews/webview-side/selectInputSettings/SelectInputSettingsPanel.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,29 @@ export const SelectInputSettingsPanel: React.FC<ISelectInputSettingsPanelProps>
6060
};
6161

6262
const handleAddOption = () => {
63-
if (newOption.trim()) {
64-
setSettings((prev) => ({
65-
...prev,
66-
options: [...prev.options, newOption.trim()]
67-
}));
68-
setNewOption('');
63+
const trimmedValue = newOption.trim();
64+
65+
// Check if the trimmed value is non-empty
66+
if (!trimmedValue) {
67+
return;
68+
}
69+
70+
// Normalize for comparison (case-insensitive)
71+
const normalizedValue = trimmedValue.toLowerCase();
72+
73+
// Check if the normalized value is already present in options
74+
const isDuplicate = settings.options.some((option) => option.toLowerCase() === normalizedValue);
75+
76+
if (isDuplicate) {
77+
return;
6978
}
79+
80+
// Add the trimmed value and clear input
81+
setSettings((prev) => ({
82+
...prev,
83+
options: [...prev.options, trimmedValue]
84+
}));
85+
setNewOption('');
7086
};
7187

7288
const handleRemoveOption = (index: number) => {

0 commit comments

Comments
 (0)