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
979 onValueChange={setBaseUrl}979 onValueChange={setBaseUrl}
980 options={baseUrlOptions}980 options={baseUrlOptions}
981 placeholder="https://api.example.com"981 placeholder="https://api.example.com"
982 emptyLabel="Use the custom URL you typed."
983 className="w-full"982 className="w-full"
984 inputClassName="font-mono text-sm"983 inputClassName="font-mono text-sm"
985 />984 />
packages/react/src/components/combobox.tsx+8−5
@@ -278,13 +278,16 @@ function FreeformCombobox(props: { · 277 unmodified lines
278 readonly inputClassName?: string;278 readonly inputClassName?: string;
279 readonly disabled?: boolean;279 readonly disabled?: boolean;
280}) {280}) {
281 const selectedValue = props.options.some((option) => option.value === props.value)281 const valueOption = props.value.trim();
282 ? props.value282 const options =
283 : null;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;
284 287
285 return (288 return (
286 <Combobox289 <Combobox
287 items={props.options.map((option) => option.value)}290 items={options.map((option) => option.value)}
288 inputValue={props.value}291 inputValue={props.value}
289 value={selectedValue}292 value={selectedValue}
290 onInputValueChange={props.onValueChange}293 onInputValueChange={props.onValueChange}
@@ -302,7 +305,7 @@ function FreeformCombobox(props: { · 11 unmodified lines
302 <ComboboxContent>305 <ComboboxContent>
303 <ComboboxEmpty>{props.emptyLabel ?? "No options"}</ComboboxEmpty>306 <ComboboxEmpty>{props.emptyLabel ?? "No options"}</ComboboxEmpty>
304 <ComboboxList>307 <ComboboxList>
305 {props.options.map((option) => (308 {options.map((option) => (
306 <ComboboxItem key={option.value} value={option.value}>309 <ComboboxItem key={option.value} value={option.value}>
307 <div className="min-w-0 flex-1">310 <div className="min-w-0 flex-1">
308 <div className="truncate">{option.label ?? option.value}</div>311 <div className="truncate">{option.label ?? option.value}</div>