Merge pull request #102 from bizzkoot/fix/question-tool-ux-improvements
fix(ui): Improve Question Tool UX (Enter Key & Auto-focus)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createMemo, Show, For, type Accessor } from "solid-js"
|
import { createMemo, Show, For, createEffect, type Accessor } from "solid-js"
|
||||||
import type { ToolState } from "@opencode-ai/sdk"
|
import type { ToolState } from "@opencode-ai/sdk"
|
||||||
import type { QuestionRequest } from "@opencode-ai/sdk/v2"
|
import type { QuestionRequest } from "@opencode-ai/sdk/v2"
|
||||||
import { useI18n } from "../../lib/i18n"
|
import { useI18n } from "../../lib/i18n"
|
||||||
@@ -28,6 +28,13 @@ export type QuestionToolBlockProps = {
|
|||||||
|
|
||||||
export function QuestionToolBlock(props: QuestionToolBlockProps) {
|
export function QuestionToolBlock(props: QuestionToolBlockProps) {
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
let firstInputRef: HTMLInputElement | undefined
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (props.active() && firstInputRef) {
|
||||||
|
firstInputRef.focus()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const requestId = createMemo(() => {
|
const requestId = createMemo(() => {
|
||||||
const state = props.toolState()
|
const state = props.toolState()
|
||||||
@@ -206,7 +213,7 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) {
|
|||||||
|
|
||||||
<div class="mt-3 flex flex-col gap-1">
|
<div class="mt-3 flex flex-col gap-1">
|
||||||
<For each={q?.options ?? []}>
|
<For each={q?.options ?? []}>
|
||||||
{(opt) => {
|
{(opt, optIndex) => {
|
||||||
const checked = () => selected().includes(opt.label)
|
const checked = () => selected().includes(opt.label)
|
||||||
return (
|
return (
|
||||||
<label
|
<label
|
||||||
@@ -214,6 +221,9 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) {
|
|||||||
title={opt.description}
|
title={opt.description}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
ref={(el) => {
|
||||||
|
if (i() === 0 && optIndex() === 0) firstInputRef = el
|
||||||
|
}}
|
||||||
type={inputType()}
|
type={inputType()}
|
||||||
name={groupName()}
|
name={groupName()}
|
||||||
checked={checked()}
|
checked={checked()}
|
||||||
@@ -234,6 +244,9 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) {
|
|||||||
title={t("toolCall.question.custom.title")}
|
title={t("toolCall.question.custom.title")}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
ref={(el) => {
|
||||||
|
if (i() === 0 && (q?.options?.length ?? 0) === 0) firstInputRef = el
|
||||||
|
}}
|
||||||
type={inputType()}
|
type={inputType()}
|
||||||
name={groupName()}
|
name={groupName()}
|
||||||
checked={customChecked()}
|
checked={customChecked()}
|
||||||
@@ -266,6 +279,13 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) {
|
|||||||
toggleFromCustomInput(i(), e.currentTarget)
|
toggleFromCustomInput(i(), e.currentTarget)
|
||||||
}}
|
}}
|
||||||
onInput={(e) => handleCustomTyping(i(), e.currentTarget)}
|
onInput={(e) => handleCustomTyping(i(), e.currentTarget)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" && !e.isComposing) {
|
||||||
|
if (!submitDisabled()) {
|
||||||
|
props.onSubmit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user