Skip to content

Commit

Permalink
Add comma sepator
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Mar 20, 2024
1 parent 1a6948e commit a241764
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export function LemonInputSelect({
const [selectedIndex, setSelectedIndex] = useState(0)
const values = value ?? []

const separateOnComma = allowCustomValues && mode === 'multiple'

const visibleOptions = useMemo(() => {
const res: LemonInputSelectOption[] = []
const customValues = [...values]
Expand Down Expand Up @@ -90,6 +92,21 @@ export function LemonInputSelect({
}, [visibleOptions.length])

const setInputValue = (newValue: string): void => {
// Special case for multiple mode with custom values
if (separateOnComma && newValue.includes(',')) {
const newValues = [...values]

newValue.split(',').forEach((value) => {
const trimmedValue = value.trim()
if (trimmedValue && !values.includes(trimmedValue)) {
newValues.push(trimmedValue)
}
})

onChange?.(newValues)
newValue = ''
}

_setInputValue(newValue)
onInputChange?.(inputValue)
}
Expand Down

0 comments on commit a241764

Please sign in to comment.