Skip to content

Build your personal knowledge base with Trilium Notes

chore(llm): use FormDropdownList

Elian Dorand8c00ed6c0a6
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css
index bb1f7d52fd..a66761fd73 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css
+++ b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css
@@ -318,7 +318,11 @@
font-size: 1rem;
}
-.llm-chat-model-select {
+.llm-chat-model-selector .dropdown {
+ display: flex;
+}
+
+.llm-chat-model-select.select-button {
padding: 0.25rem 0.5rem;
border: 1px solid var(--main-border-color);
border-radius: 4px;
@@ -327,14 +331,16 @@
font-family: inherit;
font-size: 0.85rem;
cursor: pointer;
+ min-width: 140px;
+ text-align: left;
}
-.llm-chat-model-select:focus {
+.llm-chat-model-select.select-button:focus {
outline: none;
border-color: var(--main-selection-color);
}
-.llm-chat-model-select:disabled {
+.llm-chat-model-select.select-button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx
index fb6412541c..6f2bedd9d4 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx
+++ b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx
@@ -4,6 +4,7 @@ import { t } from "../../../services/i18n.js";
import { getAvailableModels, streamChatCompletion } from "../../../services/llm_chat.js";
import { randomString } from "../../../services/utils.js";
import { useEditorSpacedUpdate } from "../../react/hooks.js";
+import FormDropdownList from "../../react/FormDropdownList.js";
import { TypeWidgetProps } from "../type_widget.js";
import ChatMessage from "./ChatMessage.js";
import "./LlmChat.css";
@@ -303,8 +304,7 @@ export default function LlmChat({ note, ntxId, noteContext }: TypeWidgetProps) {
setShouldSave(true);
}, []);
- const handleModelChange = useCallback((e: Event) => {
- const newModel = (e.target as HTMLSelectElement).value;
+ const handleModelChange = useCallback((newModel: string) => {
setSelectedModel(newModel);
setShouldSave(true);
}, []);
@@ -380,18 +380,15 @@ export default function LlmChat({ note, ntxId, noteContext }: TypeWidgetProps) {
<div className="llm-chat-options">
<div className="llm-chat-model-selector">
<span className="bx bx-chip" />
- <select
- value={selectedModel}
+ <FormDropdownList
+ values={availableModels}
+ keyProperty="id"
+ titleProperty="name"
+ currentValue={selectedModel}
onChange={handleModelChange}
disabled={isStreaming}
- className="llm-chat-model-select"
- >
- {availableModels.map(model => (
- <option key={model.id} value={model.id}>
- {model.name}
- </option>
- ))}
- </select>
+ buttonClassName="llm-chat-model-select"
+ />
</div>
<label className="llm-chat-toggle">
<input