Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(flags): save the pasted distinct id when pressing enter (#120411)

Matheus Batistaa45828b22f9b
diff --git a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx
index 0577c968dd9e..17fe99b41cc2 100644
--- a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx
@@ -502,4 +502,30 @@ describe('LemonInputSelect', () => {
expect(onChange.mock.calls.map((call) => call[0])).toEqual(expectedSelections)
})
+
+ it.each(['single', 'multiple'] as const)(
+ '%s-select mode: pressing Enter on a typed option key picks it when filtering is disabled',
+ async (mode) => {
+ const onChange = jest.fn()
+
+ const { container } = render(
+ <LemonInputSelect<string>
+ mode={mode}
+ options={[
+ { key: 'anon-id', label: 'anon-id' },
+ { key: 'user-id', label: 'user-id' },
+ ]}
+ value={[]}
+ onChange={onChange}
+ allowCustomValues
+ disableFiltering
+ />
+ )
+
+ const input = await openDropdown(container)
+ await userEvent.type(input, 'user-id{Enter}')
+
+ expect(onChange).toHaveBeenLastCalledWith(['user-id'])
+ }
+ )
})
diff --git a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
index 0b33596a51ae..dc23620e024e 100644
--- a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
+++ b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
@@ -338,7 +338,12 @@ export function LemonInputSelect<T = string>({
const ret: LemonInputSelectOption<T>[] = []
// Show the input value if custom values are allowed and it's not in the list
if (inputValue && !stringKeys.includes(inputValue)) {
- if (allowCustomValues && !optionMaps.keySet.has(inputValue)) {
+ const exactMatch = optionMaps.keyToOption.get(inputValue)
+ if (exactMatch) {
+ // Enter commits the first row. With disableFiltering the caller sets the order, so
+ // the option the person typed can be anywhere in the list unless it goes first.
+ ret.push(exactMatch)
+ } else if (allowCustomValues) {
const unescapedInputValue = inputValue.replaceAll('\\,', ',') // Transform escaped commas to plain commas
ret.push({ key: unescapedInputValue, label: unescapedInputValue, __isInput: true })
}
@@ -362,8 +367,8 @@ export function LemonInputSelect<T = string>({
// We don't want to show the input-based option again. The check for __isInput covers the case the user types something that is already an option, but we want to keep the original option
continue
}
- if (mode === 'single' && ret[0]?.key === option.key) {
- // In single-select mode, we've already added the selected value to the top earlier
+ if (ret[0]?.key === option.key) {
+ // We've already added this option to the top earlier
continue
}
ret.push(option)