mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
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.
This commit is contained in:
@@ -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%'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -149,13 +149,13 @@ describe('NativeChatQuestionCard', () => {
|
||||
// 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]!.className).not.toContain('border-primary')
|
||||
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]!.className).toContain('border-primary')
|
||||
expect(rows[0]!.className).not.toContain('border-primary')
|
||||
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('↵')
|
||||
|
||||
@@ -334,7 +334,7 @@ export function NativeChatQuestionCard({
|
||||
{questionAllowsOther ? (
|
||||
<div
|
||||
className={cn(
|
||||
'flex min-h-9 min-w-0 flex-1 gap-3 rounded-[10px] border border-question-option-border px-2.5 py-1.5 transition-colors focus-within:border-chat-focus-ring',
|
||||
'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'
|
||||
)}
|
||||
>
|
||||
@@ -363,7 +363,7 @@ export function NativeChatQuestionCard({
|
||||
onChange={(e) => setOther(index, e.target.value)}
|
||||
onClick={autoAdvance.cancel}
|
||||
placeholder={answerPlaceholder}
|
||||
className="scrollbar-sleek min-h-16 min-w-0 flex-1 resize-none bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-default disabled:opacity-50"
|
||||
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
|
||||
|
||||
@@ -21,7 +21,8 @@ export function NativeChatQuestionConfirmButton({
|
||||
disabled={disabled}
|
||||
onClick={onConfirm}
|
||||
className={cn(
|
||||
'inline-flex h-8 shrink-0 items-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',
|
||||
// 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'
|
||||
|
||||
@@ -27,8 +27,15 @@ 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}
|
||||
@@ -37,10 +44,8 @@ export function NativeChatQuestionOption({
|
||||
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(
|
||||
'flex w-full items-start gap-3 rounded-[10px] border 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
|
||||
? 'border-primary bg-foreground/8'
|
||||
: 'border-question-option-border hover:bg-foreground/5'
|
||||
'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
|
||||
@@ -62,10 +67,11 @@ export function NativeChatQuestionOption({
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
{/* Indented to the label column (padding + badge + gap) and pulled up against the description. */}
|
||||
{preview && selected ? (
|
||||
<pre
|
||||
ref={revealPreview}
|
||||
className="mt-1.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>
|
||||
|
||||
+2
-1
@@ -7,7 +7,8 @@ const PROMPT_CARD_FOCUS_TARGET_SELECTOR =
|
||||
|
||||
function focusPromptCard(card: HTMLElement): void {
|
||||
const target = card.querySelector<HTMLElement>(PROMPT_CARD_FOCUS_TARGET_SELECTOR) ?? card
|
||||
target.focus()
|
||||
// Show the ring even when a mouse click opened the card; number keys and Enter act on this row.
|
||||
target.focus({ focusVisible: true })
|
||||
}
|
||||
|
||||
/** 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