History

Merge pull request #702 from RhysSullivan/codex/freeform-combobox-typed-option-first

[codex] Put typed base URL first in combobox

Rhys Sullivan committed 6 months ago

Commit 6f4fead2 parents 7f6cbce 62465122 files · +8 −6Browse files

Unified · Split

2 files
  1. packages/plugins/openapi/src/react/AddOpenApiSource.tsx +0 −1
  2. packages/react/src/components/combobox.tsx +8 −5
packages/plugins/openapi/src/react/AddOpenApiSource.tsx+0−1
@@ -979,7 +979,6 @@ export default function AddOpenApiSource(props: { · 978 unmodified lines
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+8−5
@@ -278,13 +278,16 @@ function FreeformCombobox(props: { · 277 unmodified lines
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: { · 11 unmodified lines
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>