Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

style: show create option by default

Brad Barbine31ed89d20fd
diff --git a/packages/react/src/CreateableCombobox.tsx b/packages/react/src/CreateableCombobox.tsx
index 0ecbd78165..1b4339c648 100644
--- a/packages/react/src/CreateableCombobox.tsx
+++ b/packages/react/src/CreateableCombobox.tsx
@@ -82,6 +82,7 @@ const CreatableCombobox = forwardRef<HTMLButtonElement, CreatableComboboxProps>(
className="min-w-[260px] w-[--radix-popover-trigger-width] p-1"
>
<VirtualizedCommand
+ label={label}
options={options}
selected={selected}
value={value}
@@ -113,6 +114,7 @@ type VirtualizedCommandProps = {
options: CreatableComboboxProps["options"];
selected?: string[];
value?: string;
+ label?: string;
onChange?: (selected: string) => void;
onCreateOption?: (inputValue: string) => void;
itemHeight: number;
@@ -121,6 +123,7 @@ type VirtualizedCommandProps = {
function VirtualizedCommand({
options,
+ label,
selected,
value,
onChange,
@@ -140,21 +143,21 @@ function VirtualizedCommand({
})
: options;
- if (
- !options.some((option) =>
- [option.label.toLowerCase(), option.helper?.toLowerCase()].includes(
- search.toLowerCase()
- )
- ) &&
- search.trim() !== ""
- ) {
- filtered.push({
- label: `Create "${search}"`,
- value: "create",
- });
- }
+ const isExactMatch = options.some((option) =>
+ [option.label.toLowerCase(), option.helper?.toLowerCase()].includes(
+ search.toLowerCase()
+ )
+ );
- return filtered;
+ return isExactMatch
+ ? filtered
+ : [
+ ...filtered,
+ {
+ label: `Create`,
+ value: "create",
+ },
+ ];
}, [options, search]);
const virtualizer = useVirtualizer({
@@ -225,7 +228,7 @@ function VirtualizedCommand({
<>
<span>Create</span>
<span className="ml-1 font-bold line-clamp-1">
- {search}
+ {search.trim() === "" ? label : search}
</span>
</>
) : item.helper ? (
diff --git a/packages/react/src/CreateableMultiSelect.tsx b/packages/react/src/CreateableMultiSelect.tsx
index 26d00c9a96..01076414f0 100644
--- a/packages/react/src/CreateableMultiSelect.tsx
+++ b/packages/react/src/CreateableMultiSelect.tsx
@@ -130,6 +130,7 @@ const CreatableMultiSelect = forwardRef<
onCreateOption={onCreateOption}
itemHeight={itemHeight}
setOpen={setOpen}
+ label={label}
/>
</PopoverContent>
</Popover>
@@ -157,6 +158,7 @@ type VirtualizedCommandProps = {
onCreateOption?: (inputValue: string) => void;
itemHeight: number;
setOpen: (open: boolean) => void;
+ label?: string;
};
function VirtualizedCommand({
@@ -166,6 +168,7 @@ function VirtualizedCommand({
onCreateOption,
itemHeight,
setOpen,
+ label,
}: VirtualizedCommandProps) {
const [search, setSearch] = useState("");
const parentRef = useRef<HTMLDivElement>(null);
@@ -179,21 +182,21 @@ function VirtualizedCommand({
})
: options;
- if (
- !options.some((option) =>
- [option.label.toLowerCase(), option.helper?.toLowerCase()].includes(
- search.toLowerCase()
- )
- ) &&
- search.trim() !== ""
- ) {
- filtered.push({
- label: `Create "${search}"`,
- value: "create",
- });
- }
+ const isExactMatch = options.some((option) =>
+ [option.label.toLowerCase(), option.helper?.toLowerCase()].includes(
+ search.toLowerCase()
+ )
+ );
- return filtered;
+ return isExactMatch
+ ? filtered
+ : [
+ ...filtered,
+ {
+ label: `Create`,
+ value: "create",
+ },
+ ];
}, [options, search]);
const virtualizer = useVirtualizer({
@@ -268,7 +271,7 @@ function VirtualizedCommand({
<>
<span>Create</span>
<span className="ml-1 font-bold line-clamp-1">
- {search}
+ {search.trim() === "" ? label : search}
</span>
</>
) : item.helper ? (