Make the add pickers searchable, on twui 0.1.13

Every InlineAddSelect now filters as you type, so a long list of
extensions, bots or workspaces is narrowed rather than scrolled.
InlineAddSelect remounts the field after adding, since SearchSelect
reads its value only on mount. twui 0.1.13 brings the portalled
search select list, which no modal can clip, and a dark low-opacity
shadow.
This commit is contained in:
2026-11-21 14:31:28 +01:00
parent 37bb3f0470
commit 739c1440a2
4 changed files with 54 additions and 14 deletions
+2 -2
View File
@@ -9,7 +9,7 @@
"@modelcontextprotocol/sdk": "^1.32.1",
"@moduletrace/bun-sqlite": "^1.3.0",
"@moduletrace/bunext": "^1.3.5",
"@moduletrace/twui": "^0.1.10",
"@moduletrace/twui": "^0.1.13",
"@tiptap/extension-bubble-menu": "3.32.0",
"@tiptap/extension-mention": "3.32.0",
"@tiptap/extension-placeholder": "3.32.0",
@@ -280,7 +280,7 @@
"@moduletrace/bunext": ["@moduletrace/[email protected]", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Fbunext/-/1.3.5/bunext-1.3.5.tgz", { "dependencies": { "@tailwindcss/postcss": "^4.3.3", "@types/bun": "1.3.14", "@types/node": "^24.10.0", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "bun-plugin-tailwind": "^0.1.2", "chalk": "^5.6.2", "chokidar": "^5.0.0", "commander": "^14.0.2", "esbuild": "^0.28.2", "lightningcss-wasm": "^1.32.0", "lodash": "^4.18.1", "ora": "^9.0.0", "postcss": "^8.5.30", "react": "^19.3.0", "react-dom": "^19.3.0", "tailwindcss": "^4.3.3", "typescript": "^5.0.0", "uuid": "^14.0.2" }, "bin": { "bunext": "dist/commands/index.js" } }, "sha512-Es59Dvq3/eF726+SOHPiKtlJ87UFmyJZI4gpeciW/fA/3ZwOWws2Mm3oD6eZnOj9BP/zlBKOWA9DPTl35IP3lg=="],
"@moduletrace/twui": ["@moduletrace/[email protected]0", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Ftwui/-/0.1.10/twui-0.1.10.tgz", { "dependencies": { "lodash": "^4.18.1", "tailwind-merge": "^3.7.0" }, "peerDependencies": { "ace-builds": "^1.40.0", "lucide-react": ">=0.577.0", "next-mdx-remote": "^6.0.0", "openai": ">=6.0.0", "react": ">=18", "react-dom": ">=18", "react-markdown": ">=9.0.0", "rehype-prism-plus": "^2.0.0", "remark-gfm": "^4.0.0", "tailwindcss": "^4" }, "optionalPeers": ["ace-builds", "next-mdx-remote", "openai", "react-markdown", "rehype-prism-plus", "remark-gfm"] }, "sha512-eShpG6jK7qr2+oG7Pq4PvHnvAOUPkbxMCf9BVfiuJqUdtuaQSo2jqcggGAonGDu4p8Nn/KWTd2KrypE/+W4wTg=="],
"@moduletrace/twui": ["@moduletrace/[email protected]3", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Ftwui/-/0.1.13/twui-0.1.13.tgz", { "dependencies": { "lodash": "^4.18.1", "tailwind-merge": "^3.7.0" }, "peerDependencies": { "ace-builds": "^1.40.0", "lucide-react": ">=0.577.0", "next-mdx-remote": "^6.0.0", "openai": ">=6.0.0", "react": ">=18", "react-dom": ">=18", "react-markdown": ">=9.0.0", "rehype-prism-plus": "^2.0.0", "remark-gfm": "^4.0.0", "tailwindcss": "^4" }, "optionalPeers": ["ace-builds", "next-mdx-remote", "openai", "react-markdown", "rehype-prism-plus", "remark-gfm"] }, "sha512-5Upw848jq0ZQaDBdBpQEmoU738D/koIaUHV4EI6BkhnQYzBlRRidnZSW/BiAREGIbaac1VKyb6rOUKOqTq5bmQ=="],
"@next/mdx": ["@next/[email protected]", "", { "dependencies": { "source-map": "^0.7.0" }, "peerDependencies": { "@mdx-js/loader": ">=0.15.0", "@mdx-js/react": ">=0.15.0" }, "optionalPeers": ["@mdx-js/loader", "@mdx-js/react"] }, "sha512-Vpfuf928ACvx4AOdDXWx/cj13Ak6xlvMn3QCkjvfQMmLnQWCesQTeY01CPDbIyZvjY+NOwP7bvbvJ2ghkj/3GA=="],
+1 -1
View File
@@ -46,7 +46,7 @@
"@modelcontextprotocol/sdk": "^1.32.1",
"@moduletrace/bun-sqlite": "^1.3.0",
"@moduletrace/bunext": "^1.3.5",
"@moduletrace/twui": "^0.1.10",
"@moduletrace/twui": "^0.1.13",
"@tiptap/extension-bubble-menu": "3.32.0",
"@tiptap/extension-mention": "3.32.0",
"@tiptap/extension-placeholder": "3.32.0",
@@ -0,0 +1,29 @@
import { expect, test } from "bun:test";
import { renderToString } from "react-dom/server";
import InlineAddSelect from "./inline-add-select";
test("the add picker is a search field listing every option", () => {
const html = renderToString(
<InlineAddSelect
id="add-bot"
noun="bot"
options={[
{ value: "1", title: "Alpha" },
{ value: "2", title: "Beta" },
]}
onAdd={() => {}}
/>,
);
expect(html).toContain("Pick a bot…");
expect(html).toContain('<option value="1">Alpha</option>');
expect(html).toContain('<option value="2">Beta</option>');
expect(html).toContain("Add the bot");
expect(html).toContain("disabled");
});
test("nothing left to add renders no picker", () => {
const html = renderToString(<InlineAddSelect id="add-bot" noun="bot" options={[]} onAdd={() => {}} />);
expect(html).toBe("");
});
+22 -11
View File
@@ -1,5 +1,5 @@
import { useState } from "react";
import Select from "@moduletrace/twui/form/Select";
import SearchSelect from "@moduletrace/twui/form/SearchSelect";
import Button from "@moduletrace/twui/layout/Button";
import Row from "@moduletrace/twui/layout/Row";
@@ -15,24 +15,35 @@ type Props = {
};
/**
* A select of things to add, and an Add button beside it.
* A searchable select of things to add, and an Add button beside it, so a
* long list (many tools, bots or workspaces) is narrowed by typing rather
* than scrolled.
*/
export default function InlineAddSelect({ id, noun, options, loading, onAdd }: Props) {
const [value, setValue] = useState("");
const [reset_key, setResetKey] = useState(0);
if (!options.length) return null;
const add = () => {
if (!value || loading) return;
onAdd({ value });
// The given one leaves `options`, and SearchSelect reads its value
// only on mount, so the field is remounted empty.
setValue("");
setResetKey((key) => key + 1);
};
return (
<Row className="w-full gap-2! flex-nowrap items-end">
<Select
<SearchSelect
key={reset_key}
id={id}
title={`Pick a ${noun}`}
aria-label={`Pick a ${noun}`}
options={[
{ value: "", title: `Pick a ${noun}…`, default: !value },
...options.map((option) => ({ ...option, default: option.value == value })),
]}
changeHandler={(next) => setValue(String(next))}
placeholder={`Pick a ${noun}…`}
options={options}
changeHandler={(next) => setValue(Array.isArray(next) ? next[0] || "" : next)}
wrapperWrapperProps={{ className: "grow min-w-0" }}
/>
<Button
@@ -43,11 +54,11 @@ export default function InlineAddSelect({ id, noun, options, loading, onAdd }: P
color="gray"
loading={loading}
disabled={!value || loading}
onClick={() => value && onAdd({ value })}
onClick={add}
className="shrink-0"
>
Add
</Button>
</Row>
);
}
}