Skip to content

Commit 6f4fead

Browse files
authored
Merge pull request #702 from RhysSullivan/codex/freeform-combobox-typed-option-first
[codex] Put typed base URL first in combobox
2 parents 7f6cbce + 6246512 commit 6f4fead

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎packages/plugins/openapi/src/react/AddOpenApiSource.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,6 @@ export default function AddOpenApiSource(props: {
979979
onValueChange={setBaseUrl}
980980
options={baseUrlOptions}
981981
placeholder="https://api.example.com"
982-
emptyLabel="Use the custom URL you typed."
983982
className="w-full"
984983
inputClassName="font-mono text-sm"
985984
/>

‎packages/react/src/components/combobox.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,16 @@ function FreeformCombobox(props: {
278278
readonly inputClassName?: string;
279279
readonly disabled?: boolean;
280280
}) {
281-
const selectedValue = props.options.some((option) => option.value === props.value)
282-
? props.value
283-
: null;
281+
const valueOption = props.value.trim();
282+
const options =
283+
valueOption.length > 0 && !props.options.some((option) => option.value === valueOption)
284+
? [{ value: valueOption, label: valueOption }, ...props.options]
285+
: props.options;
286+
const selectedValue = options.some((option) => option.value === props.value) ? props.value : null;
284287

285288
return (
286289
<Combobox
287-
items={props.options.map((option) => option.value)}
290+
items={options.map((option) => option.value)}
288291
inputValue={props.value}
289292
value={selectedValue}
290293
onInputValueChange={props.onValueChange}
@@ -302,7 +305,7 @@ function FreeformCombobox(props: {
302305
<ComboboxContent>
303306
<ComboboxEmpty>{props.emptyLabel ?? "No options"}</ComboboxEmpty>
304307
<ComboboxList>
305-
{props.options.map((option) => (
308+
{options.map((option) => (
306309
<ComboboxItem key={option.value} value={option.value}>
307310
<div className="min-w-0 flex-1">
308311
<div className="truncate">{option.label ?? option.value}</div>

0 commit comments

Comments
 (0)