mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 11:24:37 +00:00
feat(native-chat): answer card as separate option tiles (#41602)
* feat(native-chat): answer card as separate option tiles (variant C) - Card on the composer surface: 14px radius, its own edge, one 14px gutter for the question, option tiles and footer. - Each option is a bordered tile (new --question-option-border token); a picked tile gets a primary border, 8% fill and a filled check badge. - Keyboard focus is an inset --chat-focus-ring ring, never the selected fill, so option 1's initial focus no longer reads as picked; descriptions stay muted at 13px. - Footer: the answer field is a bordered box; Skip is an outlined button that turns into a filled Submit with an Enter hint. - Fixtures for keyboard focus, multi-step and a 400px pane. * fix(native-chat): answer card edges follow chat colors; bare multiline field - Derive the card and option border tokens from --chat-source-foreground so tiles keep their edges when chat follows the terminal's colors. - Use the bare ImeTextarea for the multiline answer inside the shared box instead of overriding the Textarea primitive. - Show the Enter hint only where Enter confirms (single-select, single-line). - Skip/Submit text follows the chat UI size; focus offset uses the card surface; footer bottom-aligns beside a multiline field. - Move Skip/Submit into NativeChatQuestionConfirmButton. * fix(native-chat): preview inside the picked tile; steady footer; scheme-aware edges - The tile wraps the row and its preview; the preview is indented to the label column without its own border, and a 1px inset gap separates the focus ring from a picked tile's border. - Skip/Submit gets a min width that fits 'Submit ↵', so the answer field keeps its width. - The answer box shows keyboard focus as the same 2px inset ring as options; the multiline field grows with its content up to 12 lines. - Card and option border mixes follow the chat's own scheme when it takes the terminal's colors. - Focus the card's first target with focusVisible so the ring shows even when a mouse click opened the card. * fix(native-chat): force the focus ring only on a prompt card's focus target The card-level fallback (approval cards, a question card with every target disabled) keeps the browser's keyboard heuristic, so mouse-opened approval cards do not draw a ring around the whole card.
This commit is contained in:
@@ -101,6 +101,9 @@
|
||||
--color-agent-question: var(--agent-question);
|
||||
--color-agent-working: var(--agent-working);
|
||||
--color-agent-question-text: var(--agent-question-text);
|
||||
--color-question-card-border: var(--question-card-border);
|
||||
--color-question-option-border: var(--question-option-border);
|
||||
--color-chat-focus-ring: var(--chat-focus-ring);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-3: var(--chart-3);
|
||||
@@ -262,6 +265,9 @@
|
||||
--agent-working: var(--color-yellow-500);
|
||||
/* Legible weight for text/glyphs on a tinted --agent-question surface. */
|
||||
--agent-question-text: var(--color-orange-700);
|
||||
/* Answer card edge and the outline shared by its option tiles, badges, answer field and Skip. */
|
||||
--question-card-border-mix: 14%;
|
||||
--question-option-border-mix: 16%;
|
||||
/* Keep PR-state hues stable across theme changes. */
|
||||
--workspace-status-done: #c7a594;
|
||||
--workspace-status-review: #16a34a;
|
||||
@@ -379,6 +385,8 @@
|
||||
--ai-action-accent: var(--color-violet-400);
|
||||
--agent-question: var(--color-orange-500);
|
||||
--agent-question-text: var(--color-orange-300);
|
||||
--question-card-border-mix: 16%;
|
||||
--question-option-border-mix: 12%;
|
||||
--workspace-status-done: #c7a594;
|
||||
--workspace-status-review: #16a34a;
|
||||
--workspace-status-progress: #d4a300;
|
||||
@@ -743,6 +751,17 @@ body[data-modal-overlay-open]
|
||||
var(--chat-source-foreground) var(--chat-composer-border-mix),
|
||||
transparent
|
||||
);
|
||||
/* From the chat's own foreground, so the edges stay visible when chat follows the terminal's colors. */
|
||||
--question-card-border: color-mix(
|
||||
in srgb,
|
||||
var(--chat-source-foreground) var(--question-card-border-mix),
|
||||
transparent
|
||||
);
|
||||
--question-option-border: color-mix(
|
||||
in srgb,
|
||||
var(--chat-source-foreground) var(--question-option-border-mix),
|
||||
transparent
|
||||
);
|
||||
/* Mixed toward the foreground so each clears text contrast on the canvas in either scheme. */
|
||||
--chat-focus-ring: color-mix(in srgb, var(--chat-source-foreground) 50%, var(--chat-canvas));
|
||||
--chat-warning: color-mix(in srgb, var(--status-warning) 70%, var(--chat-source-foreground));
|
||||
|
||||
@@ -143,7 +143,9 @@ function applyTerminalChatColors(
|
||||
'--chat-inline-code-border-mix': light ? '9%' : '8%',
|
||||
'--chat-composer-mix': light ? '0%' : '4%',
|
||||
'--chat-composer-base': light ? 'var(--chat-canvas)' : 'transparent',
|
||||
'--chat-composer-border-mix': light ? '11%' : '9%'
|
||||
'--chat-composer-border-mix': light ? '11%' : '9%',
|
||||
'--question-card-border-mix': light ? '14%' : '16%',
|
||||
'--question-option-border-mix': light ? '16%' : '12%'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ export const pendingAnswer = defineFixture({
|
||||
option.click()
|
||||
await new Promise(requestAnimationFrame)
|
||||
;[...frame.querySelectorAll<HTMLButtonElement>('button')]
|
||||
.find((button) => button.textContent === 'Submit')
|
||||
.find((button) => button.textContent?.startsWith('Submit'))
|
||||
?.click()
|
||||
await new Promise(requestAnimationFrame)
|
||||
}
|
||||
@@ -272,3 +272,61 @@ export const previews = defineFixture({
|
||||
await new Promise(requestAnimationFrame)
|
||||
}
|
||||
})
|
||||
|
||||
const dispatchOptions = [
|
||||
{
|
||||
label: 'Yes, investigate and report',
|
||||
description: "I'll find the config and summarize it."
|
||||
},
|
||||
{
|
||||
label: 'No, I know what it is',
|
||||
description: "You're already aware of it; I'll leave it alone."
|
||||
},
|
||||
{
|
||||
label: 'Ask me later',
|
||||
description: 'Keep the dispatches running for now.'
|
||||
}
|
||||
]
|
||||
|
||||
function FocusedQuestion({ steps = 1 }: { steps?: number }) {
|
||||
return (
|
||||
<div
|
||||
className="native-chat-appearance bg-chat-canvas p-4"
|
||||
style={nativeChatAppearanceStyle({})}
|
||||
>
|
||||
<NativeChatQuestionCard
|
||||
prompt={{
|
||||
questions: Array.from({ length: steps }, (_, i) => ({
|
||||
question:
|
||||
i === 0
|
||||
? 'I found active dispatches from an automation I do not recognize. Should I look into it?'
|
||||
: 'Where should the report go?',
|
||||
header: i === 0 ? 'Investigate' : 'Report',
|
||||
multiSelect: false,
|
||||
options: dispatchOptions
|
||||
}))
|
||||
}}
|
||||
onAnswer={() => {}}
|
||||
onCancel={() => {}}
|
||||
onCollapse={() => {}}
|
||||
shouldFocus
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Keyboard focus lands on option 1 as the card opens; it must not look picked.
|
||||
export const keyboardFocus = defineFixture({
|
||||
width: 720,
|
||||
render: () => <FocusedQuestion />
|
||||
})
|
||||
|
||||
export const multiStep = defineFixture({
|
||||
width: 720,
|
||||
render: () => <FocusedQuestion steps={2} />
|
||||
})
|
||||
|
||||
export const narrow = defineFixture({
|
||||
width: 400,
|
||||
render: () => <FocusedQuestion />
|
||||
})
|
||||
|
||||
@@ -126,4 +126,44 @@ describe('NativeChatQuestionCard', () => {
|
||||
pressKey({ key: 'Enter' }, rows[1]!)
|
||||
expect(onAnswer).toHaveBeenCalledWith([{ indices: [1], other: '' }])
|
||||
})
|
||||
it('opens with focus on option 1 without picking it, and Skip turns into Submit once picked', () => {
|
||||
vi.useFakeTimers()
|
||||
container.setAttribute('data-native-chat-root', 'true')
|
||||
act(() => {
|
||||
root.render(
|
||||
<NativeChatQuestionCard
|
||||
prompt={tabsOrSpaces}
|
||||
onAnswer={() => {}}
|
||||
onCancel={() => {}}
|
||||
shouldFocus
|
||||
/>
|
||||
)
|
||||
})
|
||||
act(() => vi.runAllTimers())
|
||||
const rows = container.querySelectorAll<HTMLButtonElement>('button[aria-pressed]')
|
||||
const confirmButton = (): HTMLButtonElement =>
|
||||
[...container.querySelectorAll<HTMLButtonElement>('button')].find((button) =>
|
||||
/^(Skip|Submit)/.test(button.textContent ?? '')
|
||||
)!
|
||||
expect(document.activeElement).toBe(rows[0])
|
||||
// Focus is a ring only; the picked look (primary border, fill) is reserved for aria-pressed rows.
|
||||
expect(rows[0]!.getAttribute('aria-pressed')).toBe('false')
|
||||
expect(rows[0]!.className).not.toMatch(/(^|\s)(focus:)?bg-accent(\s|$)/)
|
||||
expect(rows[0]!.parentElement!.className).not.toContain('border-primary')
|
||||
expect(confirmButton().textContent).toBe('Skip')
|
||||
|
||||
act(() => rows[1]!.click())
|
||||
expect(rows[1]!.getAttribute('aria-pressed')).toBe('true')
|
||||
expect(rows[1]!.parentElement!.className).toContain('border-primary')
|
||||
expect(rows[0]!.parentElement!.className).not.toContain('border-primary')
|
||||
// The Enter hint is decoration; the button's name stays "Submit".
|
||||
const submit = confirmButton()
|
||||
expect(submit.querySelector('[aria-hidden]')?.textContent).toBe('↵')
|
||||
expect(
|
||||
[...submit.childNodes]
|
||||
.filter((node) => !(node instanceof Element && node.hasAttribute('aria-hidden')))
|
||||
.map((node) => node.textContent)
|
||||
.join('')
|
||||
).toBe('Submit')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ImeTextarea } from '@/lib/text-input/ime/ime-text-field'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { useRef, useState, type RefObject } from 'react'
|
||||
import { Check, Pencil, X } from 'lucide-react'
|
||||
import { cn } from '@/lib/class-names'
|
||||
@@ -7,6 +6,7 @@ import { translate } from '@/i18n/i18n'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { NativeChatQuestionText } from './NativeChatQuestionText'
|
||||
import { NativeChatQuestionOption } from './NativeChatQuestionOption'
|
||||
import { NativeChatQuestionConfirmButton } from './NativeChatQuestionConfirmButton'
|
||||
import type { AskAnswerSelection } from '../../../../../shared/native-chat/input/native-chat-ask-answer'
|
||||
import type { AskPrompt } from '../../../../../shared/native-chat/input/native-chat-ask-types'
|
||||
import { NativeChatPromptCollapseToggle } from './NativeChatPromptCollapse'
|
||||
@@ -283,12 +283,13 @@ export function NativeChatQuestionCard({
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="overflow-hidden rounded-lg border border-input bg-card shadow-xs">
|
||||
{/* One 14px gutter (px-3.5) for the question, option tiles and footer, so their edges line up. */}
|
||||
<div className="overflow-hidden rounded-[14px] border border-question-card-border bg-chat-composer-surface shadow-sm">
|
||||
<div className="flex items-start gap-2 px-3.5 py-2.5">
|
||||
<NativeChatQuestionText
|
||||
data-testid="native-chat-question-card-title"
|
||||
content={q.question}
|
||||
className="min-w-0 flex-1 break-words text-sm font-semibold text-foreground [&_p]:my-0 [&_p+p]:mt-2"
|
||||
className="min-w-0 flex-1 break-words text-sm font-medium text-foreground [&_p]:my-0 [&_p+p]:mt-2"
|
||||
/>
|
||||
{collapse ? (
|
||||
<NativeChatPromptCollapseToggle
|
||||
@@ -308,7 +309,8 @@ export function NativeChatQuestionCard({
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="max-h-[50vh] divide-y divide-border/60 overflow-y-auto border-t border-border scrollbar-sleek">
|
||||
{/* Option rings are inset, so the scroll clip cannot cut them. */}
|
||||
<div className="flex max-h-[50vh] flex-col gap-1.5 overflow-y-auto px-3.5 pb-3 scrollbar-sleek">
|
||||
{q.options.map((opt, i) => (
|
||||
<NativeChatQuestionOption
|
||||
key={`${i}:${opt.label}`}
|
||||
@@ -322,95 +324,105 @@ export function NativeChatQuestionCard({
|
||||
onSelect={() => pickOption(i)}
|
||||
/>
|
||||
))}
|
||||
<div className="flex items-center gap-3 px-3.5 py-2.5">
|
||||
{questionAllowsOther ? (
|
||||
<>
|
||||
<span
|
||||
className={cn(
|
||||
'flex size-6 shrink-0 items-center justify-center rounded-md',
|
||||
currentTypedAnswerChosen
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'bg-muted text-muted-foreground'
|
||||
)}
|
||||
>
|
||||
{currentTypedAnswerChosen ? (
|
||||
<Check className="size-3.5" strokeWidth={3} />
|
||||
) : (
|
||||
<Pencil className="size-3.5" />
|
||||
)}
|
||||
</span>
|
||||
{/* Deliver free text verbatim as a tool result; composer slash commands and autocomplete do not apply. */}
|
||||
{freeTextInput?.multiline ? (
|
||||
<Textarea
|
||||
data-native-chat-answer-field
|
||||
data-native-chat-prompt-card-focus-target={fieldTakesFocus}
|
||||
disabled={isSubmitting}
|
||||
value={otherText[index]}
|
||||
onChange={(e) => setOther(index, e.target.value)}
|
||||
onClick={autoAdvance.cancel}
|
||||
placeholder={answerPlaceholder}
|
||||
/>
|
||||
) : (
|
||||
<ImeTextarea
|
||||
ref={answerInputRef}
|
||||
rows={1}
|
||||
data-native-chat-answer-field
|
||||
data-native-chat-prompt-card-focus-target={fieldTakesFocus}
|
||||
disabled={isSubmitting}
|
||||
value={otherText[index]}
|
||||
// Enter submits, so a line break becomes a space; edit in place so a mid-draft paste keeps the caret.
|
||||
onChange={(e) => {
|
||||
const field = e.target
|
||||
const oneLine = field.value.replace(LINE_BREAKS, ' ')
|
||||
if (oneLine !== field.value) {
|
||||
const { selectionStart, selectionEnd } = field
|
||||
field.value = oneLine
|
||||
field.setSelectionRange(selectionStart, selectionEnd)
|
||||
}
|
||||
setOther(index, oneLine)
|
||||
}}
|
||||
// Select typed text on click; tabbing toward Submit must not replace a picked option.
|
||||
onClick={() => {
|
||||
autoAdvance.cancel()
|
||||
if ((otherText[index] ?? '').trim().length > 0) {
|
||||
chooseTypedAnswer(index)
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
confirm(true)
|
||||
}
|
||||
}}
|
||||
placeholder={answerPlaceholder}
|
||||
className={cn(
|
||||
'scrollbar-sleek max-h-[6lh] min-w-0 flex-1 resize-none overflow-y-auto bg-transparent text-sm outline-none [field-sizing:content] placeholder:text-muted-foreground disabled:cursor-default disabled:opacity-50',
|
||||
currentTypedAnswerChosen || !otherText[index]
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground'
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<span className="flex-1" />
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
disabled={isSubmitting}
|
||||
onClick={() => confirm()}
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
'flex gap-2.5 px-3.5 pb-3.5',
|
||||
freeTextInput?.multiline ? 'items-end' : 'items-center'
|
||||
)}
|
||||
>
|
||||
{questionAllowsOther ? (
|
||||
<div
|
||||
className={cn(
|
||||
'shrink-0 whitespace-nowrap rounded-md px-3 py-1 text-xs font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default disabled:opacity-50',
|
||||
currentAnswered
|
||||
? 'bg-primary text-primary-foreground hover:bg-primary/90'
|
||||
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'
|
||||
'flex min-h-9 min-w-0 flex-1 gap-3 rounded-[10px] border border-question-option-border px-2.5 py-1.5 has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-inset has-[:focus-visible]:ring-chat-focus-ring',
|
||||
freeTextInput?.multiline ? 'items-start' : 'items-center'
|
||||
)}
|
||||
>
|
||||
{isSubmitting
|
||||
<span
|
||||
className={cn(
|
||||
'flex size-5.5 shrink-0 items-center justify-center rounded-md border',
|
||||
currentTypedAnswerChosen
|
||||
? 'border-primary bg-primary text-primary-foreground'
|
||||
: 'border-question-option-border text-muted-foreground'
|
||||
)}
|
||||
>
|
||||
{currentTypedAnswerChosen ? (
|
||||
<Check className="size-3.5" strokeWidth={3} />
|
||||
) : (
|
||||
<Pencil className="size-3.5" />
|
||||
)}
|
||||
</span>
|
||||
{/* Deliver free text verbatim as a tool result; composer slash commands and autocomplete do not apply. */}
|
||||
{freeTextInput?.multiline ? (
|
||||
// The box draws the field's edge, so the bare field (not the bordered Textarea primitive) sits inside it.
|
||||
<ImeTextarea
|
||||
data-native-chat-answer-field
|
||||
data-native-chat-prompt-card-focus-target={fieldTakesFocus}
|
||||
disabled={isSubmitting}
|
||||
value={otherText[index]}
|
||||
onChange={(e) => setOther(index, e.target.value)}
|
||||
onClick={autoAdvance.cancel}
|
||||
placeholder={answerPlaceholder}
|
||||
className="scrollbar-sleek max-h-[12lh] min-h-16 min-w-0 flex-1 resize-none overflow-y-auto bg-transparent [field-sizing:content] text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-default disabled:opacity-50"
|
||||
/>
|
||||
) : (
|
||||
<ImeTextarea
|
||||
ref={answerInputRef}
|
||||
rows={1}
|
||||
data-native-chat-answer-field
|
||||
data-native-chat-prompt-card-focus-target={fieldTakesFocus}
|
||||
disabled={isSubmitting}
|
||||
value={otherText[index]}
|
||||
// Enter submits, so a line break becomes a space; edit in place so a mid-draft paste keeps the caret.
|
||||
onChange={(e) => {
|
||||
const field = e.target
|
||||
const oneLine = field.value.replace(LINE_BREAKS, ' ')
|
||||
if (oneLine !== field.value) {
|
||||
const { selectionStart, selectionEnd } = field
|
||||
field.value = oneLine
|
||||
field.setSelectionRange(selectionStart, selectionEnd)
|
||||
}
|
||||
setOther(index, oneLine)
|
||||
}}
|
||||
// Select typed text on click; tabbing toward Submit must not replace a picked option.
|
||||
onClick={() => {
|
||||
autoAdvance.cancel()
|
||||
if ((otherText[index] ?? '').trim().length > 0) {
|
||||
chooseTypedAnswer(index)
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
confirm(true)
|
||||
}
|
||||
}}
|
||||
placeholder={answerPlaceholder}
|
||||
className={cn(
|
||||
'scrollbar-sleek max-h-[6lh] min-w-0 flex-1 resize-none overflow-y-auto bg-transparent text-sm outline-none [field-sizing:content] placeholder:text-muted-foreground disabled:cursor-default disabled:opacity-50',
|
||||
currentTypedAnswerChosen || !otherText[index]
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground'
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<span className="flex-1" />
|
||||
)}
|
||||
<NativeChatQuestionConfirmButton
|
||||
label={
|
||||
isSubmitting
|
||||
? t('components.native-chat.question.sending', 'Sending…')
|
||||
: CONFIRM_LABEL[askConfirmLabel(currentAnswered, isLast)]()}
|
||||
</button>
|
||||
</div>
|
||||
: CONFIRM_LABEL[askConfirmLabel(currentAnswered, isLast)]()
|
||||
}
|
||||
answered={currentAnswered}
|
||||
enterHint={
|
||||
currentAnswered && !isSubmitting && !q.multiSelect && !freeTextInput?.multiline
|
||||
}
|
||||
disabled={isSubmitting}
|
||||
onConfirm={() => confirm()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { cn } from '@/lib/class-names'
|
||||
|
||||
/** Outlined Skip until there is an answer, then a filled Submit/Next. */
|
||||
export function NativeChatQuestionConfirmButton({
|
||||
label,
|
||||
answered,
|
||||
enterHint,
|
||||
disabled,
|
||||
onConfirm
|
||||
}: {
|
||||
label: string
|
||||
answered: boolean
|
||||
/** Only where Enter confirms: it adds a line in a multiline answer and toggles a multi-select row. */
|
||||
enterHint: boolean
|
||||
disabled: boolean
|
||||
onConfirm: () => void
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={onConfirm}
|
||||
className={cn(
|
||||
// min-w fits 'Submit ↵', so the answer field keeps its width when Skip turns into Submit.
|
||||
'inline-flex h-8 min-w-23 shrink-0 items-center justify-center whitespace-nowrap rounded-lg border px-3.5 text-[length:calc(var(--chat-ui-size,var(--text-sm))*13/14)] font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-chat-focus-ring focus-visible:ring-offset-1 focus-visible:ring-offset-chat-composer-surface disabled:cursor-default disabled:opacity-50',
|
||||
answered
|
||||
? 'border-primary bg-primary text-primary-foreground hover:bg-primary/90'
|
||||
: 'border-question-option-border text-foreground hover:bg-foreground/5'
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{enterHint ? (
|
||||
<span aria-hidden className="ml-1.5 text-2xs font-medium opacity-70">
|
||||
↵
|
||||
</span>
|
||||
) : null}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -27,49 +27,51 @@ export function NativeChatQuestionOption({
|
||||
onSelect: () => void
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
// The tile wraps the row and its preview, so the preview reads as part of the picked option.
|
||||
// One root whether or not the preview shows, so selecting never remounts the focused row.
|
||||
<div>
|
||||
// p-px leaves a 1px gap between the inset focus ring and the tile's border.
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-[10px] border p-px transition-colors',
|
||||
selected ? 'border-primary bg-foreground/8' : 'border-question-option-border'
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={onSelect}
|
||||
aria-pressed={selected}
|
||||
data-native-chat-prompt-card-focus-target={initialFocus || undefined}
|
||||
// Focus is an inset ring, never the selected fill, so the row that opens focused does not read as picked.
|
||||
className={cn(
|
||||
'group/option flex w-full items-start gap-3 px-3.5 py-2.5 text-left text-foreground transition-colors focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none',
|
||||
selected
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'hover:bg-accent hover:text-accent-foreground'
|
||||
'flex w-full items-start gap-3 rounded-[8px] px-3 py-2.5 text-left text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-chat-focus-ring disabled:pointer-events-none',
|
||||
!selected && 'hover:bg-foreground/5'
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'flex size-6 shrink-0 items-center justify-center rounded-md text-xs font-medium',
|
||||
selected ? 'bg-primary text-primary-foreground' : 'bg-muted text-muted-foreground'
|
||||
'flex size-5.5 shrink-0 items-center justify-center rounded-md border text-xs font-medium',
|
||||
selected
|
||||
? 'border-primary bg-primary text-primary-foreground'
|
||||
: 'border-question-option-border text-foreground'
|
||||
)}
|
||||
>
|
||||
{selected ? <Check className="size-3.5" strokeWidth={3} /> : badge}
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block break-words text-sm">{label}</span>
|
||||
<span className="block break-words text-sm font-medium">{label}</span>
|
||||
{description ? (
|
||||
<span
|
||||
className={cn(
|
||||
'block whitespace-pre-wrap break-words text-xs',
|
||||
selected
|
||||
? 'text-accent-foreground'
|
||||
: 'text-muted-foreground group-hover/option:text-accent-foreground group-focus/option:text-accent-foreground'
|
||||
)}
|
||||
>
|
||||
<span className="mt-px block whitespace-pre-wrap break-words text-[length:calc(var(--text-sm)*13/14)] leading-snug text-muted-foreground">
|
||||
{description}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
{/* Indented to the label column (padding + badge + gap) and pulled up against the description. */}
|
||||
{preview && selected ? (
|
||||
<pre
|
||||
ref={revealPreview}
|
||||
className="mx-3.5 mb-2.5 max-h-56 overflow-auto whitespace-pre rounded-md border border-chat-code-border bg-chat-code-surface px-2.5 py-2 font-mono text-chat-code leading-snug text-chat-foreground scrollbar-sleek"
|
||||
className="-mt-2 mr-3 mb-2.5 ml-[calc(var(--spacing)*11.5)] max-h-56 overflow-auto whitespace-pre rounded-md bg-chat-code-surface px-2.5 py-2 font-mono text-chat-code leading-snug text-chat-foreground scrollbar-sleek"
|
||||
>
|
||||
{preview}
|
||||
</pre>
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ describe('async question send ownership', () => {
|
||||
).toBe(false)
|
||||
act(() =>
|
||||
[...container.querySelectorAll('button')]
|
||||
.find((node) => node.textContent === 'Submit')!
|
||||
.find((node) => node.textContent?.startsWith('Submit'))!
|
||||
.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
||||
)
|
||||
act(() => completions[0]!())
|
||||
|
||||
+8
-2
@@ -6,8 +6,14 @@ const PROMPT_CARD_FOCUS_TARGET_SELECTOR =
|
||||
'[data-native-chat-prompt-card-focus-target]:not(:disabled)'
|
||||
|
||||
function focusPromptCard(card: HTMLElement): void {
|
||||
const target = card.querySelector<HTMLElement>(PROMPT_CARD_FOCUS_TARGET_SELECTOR) ?? card
|
||||
target.focus()
|
||||
const target = card.querySelector<HTMLElement>(PROMPT_CARD_FOCUS_TARGET_SELECTOR)
|
||||
if (target) {
|
||||
// Show the ring even when a mouse click opened the card; number keys and Enter act on this row.
|
||||
target.focus({ focusVisible: true })
|
||||
return
|
||||
}
|
||||
// The card itself is only a key sink; leave its ring to the browser's keyboard heuristic.
|
||||
card.focus()
|
||||
}
|
||||
|
||||
/** Focus the shown card requesting it unless keep already names a control inside it; return false when ineligible. */
|
||||
|
||||
Reference in New Issue
Block a user