Skip to content

Commit b19f6b9

Browse files
Use trimmed value for duplicate check in createOptions (#77)
The `createOptions` function was using `inputValue` to check for existing options, but `trimmedValue` to create new ones. This caused duplicates when `inputValue` had trailing spaces (e.g. "foo ") because it wouldn't match "foo" but would then create "foo". Updates `exists` check to use `trimmedValue`, ensuring consistent behavior. Also add a release note in CHANGELOG.md.
1 parent cb48948 commit b19f6b9

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Fix a bug where `createOptions` could create duplicate options if the input
8+
value had trailing whitespace (e.g. "foo "). The existence check now uses the
9+
trimmed input value, consistent with the creation logic.
10+
311
## [0.15.0] - 2024-07-06
412

513
A focus on improving the ergonomics of `createOptions` to cover more use cases

src/create-options.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const createOptions = (
134134
if (config.createable !== undefined) {
135135
const trimmedValue = inputValue.trim();
136136
const exists = createdOptions.some((option) =>
137-
areEqualIgnoringCase(inputValue, option.text),
137+
areEqualIgnoringCase(trimmedValue, option.text),
138138
);
139139

140140
if (trimmedValue) {

0 commit comments

Comments
 (0)