fix(webui): remove composer placeholder tooltip

This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-06 13:47:41 +08:00
1 parent f5a8a41b15
commit 11f738f0fe
2 files changed
+4 -83

No files matched your search

+2 -19
View File
@@ -149,7 +149,7 @@ test("idle voice and ready send remain distinct from the composer in both themes
}); });
test("a compact mobile placeholder keeps the full hint available without shifting the composer", async ({ browser, baseURL }) => { test("a compact mobile composer preserves its placeholder, focus, and sizing", async ({ browser, baseURL }) => {
const context = await browser.newContext({ baseURL, viewport: { width: 314, height: 844 }, hasTouch: true, isMobile: true, reducedMotion: "reduce" }); const context = await browser.newContext({ baseURL, viewport: { width: 314, height: 844 }, hasTouch: true, isMobile: true, reducedMotion: "reduce" });
try { try {
const page = await context.newPage(); const page = await context.newPage();
@@ -162,41 +162,24 @@ test("a compact mobile placeholder keeps the full hint available without shiftin
await expect.poll(() => input.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true); await expect.poll(() => input.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);
const placeholder = (await input.getAttribute("aria-description"))!; const placeholder = (await input.getAttribute("aria-description"))!;
expect(placeholder).toContain("compétences"); expect(placeholder).toContain("compétences");
await expect(page.getByRole("tooltip")).toHaveCount(0);
const before = (await action.boundingBox())!; const before = (await action.boundingBox())!;
const initialHeight = await input.evaluate(node => node.clientHeight); const initialHeight = await input.evaluate(node => node.clientHeight);
await input.tap(); await input.tap();
const hint = page.getByRole("tooltip"); await expect(input).toBeFocused();
await expect(hint).toHaveText(placeholder);
const hintSurface = page.locator('[data-radix-popper-content-wrapper] [data-side]').first();
const composer = page.locator(".thread-composer-form");
await expect.poll(async () => {
const [hintBox, composerBox] = await Promise.all([hintSurface.boundingBox(), composer.boundingBox()]);
return !!hintBox && !!composerBox && (hintBox.y + hintBox.height <= composerBox.y || hintBox.y >= composerBox.y + composerBox.height);
}).toBe(true);
expect(await action.boundingBox()).toEqual(before); expect(await action.boundingBox()).toEqual(before);
await input.fill("Bonjour"); await input.fill("Bonjour");
await expect(hint).toHaveCount(0);
expect(await action.boundingBox()).toEqual(before); expect(await action.boundingBox()).toEqual(before);
await input.fill("Première ligne\nDeuxième ligne\nTroisième ligne"); await input.fill("Première ligne\nDeuxième ligne\nTroisième ligne");
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBeGreaterThan(initialHeight); await expect.poll(() => input.evaluate(node => node.clientHeight)).toBeGreaterThan(initialHeight);
await input.fill(""); await input.fill("");
await expect(hint).toHaveText(placeholder);
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBe(initialHeight); await expect.poll(() => input.evaluate(node => node.clientHeight)).toBe(initialHeight);
expect(await action.boundingBox()).toEqual(before); expect(await action.boundingBox()).toEqual(before);
await input.press("Escape");
await expect(hint).toHaveCount(0);
await page.locator(".thread-composer-footer button").first().focus(); await page.locator(".thread-composer-footer button").first().focus();
await page.keyboard.press("Shift+Tab"); await page.keyboard.press("Shift+Tab");
await expect(input).toBeFocused(); await expect(input).toBeFocused();
await expect(hint).toHaveText(placeholder);
const box = (await input.boundingBox())!;
await page.mouse.move(box.x + 5, box.y + 5);
await page.mouse.move(1, 800);
await expect(hint).toHaveCount(0);
} finally { } finally {
await context.close(); await context.close();
} }
+2 -64
View File
@@ -831,9 +831,6 @@ export function ThreadComposer({
const [value, setValue] = useState(initialDraft?.text ?? ""); const [value, setValue] = useState(initialDraft?.text ?? "");
const [composerFocused, setComposerFocused] = useState(false); const [composerFocused, setComposerFocused] = useState(false);
const [compactPlaceholder, setCompactPlaceholder] = useState(false); const [compactPlaceholder, setCompactPlaceholder] = useState(false);
const [placeholderHintRequested, setPlaceholderHintRequested] = useState(false);
const [placeholderHintOpen, setPlaceholderHintOpen] = useState(false);
const [placeholderHintBottomGap, setPlaceholderHintBottomGap] = useState(0);
const blurFrame = useRef<number | null>(null); const blurFrame = useRef<number | null>(null);
const [boundSessionMentions, setBoundSessionMentions] = useState<SessionMention[]>( const [boundSessionMentions, setBoundSessionMentions] = useState<SessionMention[]>(
initialDraft?.sessionMentions ?? [], initialDraft?.sessionMentions ?? [],
@@ -952,21 +949,8 @@ export function ThreadComposer({
const placeholderMeasureRef = useRef<HTMLSpanElement>(null); const placeholderMeasureRef = useRef<HTMLSpanElement>(null);
const mentionOverlayRef = useRef<HTMLDivElement>(null); const mentionOverlayRef = useRef<HTMLDivElement>(null);
const formRef = useRef<HTMLFormElement>(null); const formRef = useRef<HTMLFormElement>(null);
const tabFocusRequested = useRef(false);
const [compactControls, setCompactControls] = useState(false); const [compactControls, setCompactControls] = useState(false);
useEffect(() => {
// Automatic session focus should not open the hint; keyboard navigation should.
const onKeyDown = (event: KeyboardEvent) => { tabFocusRequested.current = event.key === "Tab"; };
const onPointerDown = () => { tabFocusRequested.current = false; };
document.addEventListener("keydown", onKeyDown, true);
document.addEventListener("pointerdown", onPointerDown, true);
return () => {
document.removeEventListener("keydown", onKeyDown, true);
document.removeEventListener("pointerdown", onPointerDown, true);
};
}, []);
useLayoutEffect(() => { useLayoutEffect(() => {
const form = formRef.current; const form = formRef.current;
if (!form) return; if (!form) return;
@@ -1628,26 +1612,6 @@ export function ThreadComposer({
if (input) autosizeTextarea(input); if (input) autosizeTextarea(input);
}, [readingTextSize, customReadingTextSize]); }, [readingTextSize, customReadingTextSize]);
useLayoutEffect(() => {
const input = textareaRef.current;
if (!input || document.activeElement !== input || !placeholderHintRequested || input.value || !input.placeholder) {
setPlaceholderHintOpen(false);
return;
}
const form = formRef.current!;
const measure = () => {
setPlaceholderHintOpen(showCompactPlaceholder || input.scrollWidth > input.clientWidth);
setPlaceholderHintBottomGap(form.getBoundingClientRect().bottom - input.getBoundingClientRect().bottom);
};
measure();
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
observer?.observe(input);
observer?.observe(form);
let active = true;
void document.fonts?.ready.then(() => { if (active) measure(); });
return () => { active = false; observer?.disconnect(); };
}, [placeholderHintRequested, mentionInput.value, resolvedPlaceholder, showCompactPlaceholder, sessionDragPreview, readingTextSize, customReadingTextSize]);
// Runs before paint so switching sessions never flashes stale draft text. // Runs before paint so switching sessions never flashes stale draft text.
useLayoutEffect(() => { useLayoutEffect(() => {
if (previousPendingQueueKeyRef.current === pendingQueueKey) return; if (previousPendingQueueKeyRef.current === pendingQueueKey) return;
@@ -2459,33 +2423,19 @@ export function ThreadComposer({
: null} : null}
/> />
) : null} ) : null}
<TooltipProvider>
<Tooltip open={placeholderHintOpen}>
<TooltipTrigger asChild>
<textarea <textarea
ref={textareaRef} ref={textareaRef}
value={mentionInput.value} value={mentionInput.value}
onFocus={(event) => { onFocus={() => {
if (tabFocusRequested.current && !event.currentTarget.value) setPlaceholderHintRequested(true);
tabFocusRequested.current = false;
if (compactWhenIdle) setComposerFocused(true); if (compactWhenIdle) setComposerFocused(true);
}} }}
onBlur={() => {
if (placeholderHintRequested) setPlaceholderHintRequested(false);
}}
onPointerLeave={(event) => {
if (event.pointerType === "mouse" && placeholderHintRequested) setPlaceholderHintRequested(false);
}}
onChange={mentionInput.onChange} onChange={mentionInput.onChange}
onCompositionStart={mentionInput.onCompositionStart} onCompositionStart={mentionInput.onCompositionStart}
onCompositionEnd={mentionInput.onCompositionEnd} onCompositionEnd={mentionInput.onCompositionEnd}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
onKeyUp={() => setCursorPosition(rawSelection().start)} onKeyUp={() => setCursorPosition(rawSelection().start)}
onSelect={() => setCursorPosition(rawSelection().start)} onSelect={() => setCursorPosition(rawSelection().start)}
onClick={(event) => { onClick={() => setCursorPosition(rawSelection().start)}
setCursorPosition(rawSelection().start);
if (!event.currentTarget.value) setPlaceholderHintRequested(true);
}}
onCopy={mentionInput.onCopy} onCopy={mentionInput.onCopy}
onCut={mentionInput.onCut} onCut={mentionInput.onCut}
onScroll={(e) => { onScroll={(e) => {
@@ -2506,18 +2456,6 @@ export function ThreadComposer({
hasInlineDecorations && "text-transparent selection:bg-primary/20", hasInlineDecorations && "text-transparent selection:bg-primary/20",
)} )}
/> />
</TooltipTrigger>
{placeholderHintOpen ? (
<TooltipContent side="top" align="start" onEscapeKeyDown={() => {
setPlaceholderHintOpen(false);
setPlaceholderHintRequested(false);
}} style={{ "--placeholder-hint-bottom-gap": `${placeholderHintBottomGap}px` } as CSSProperties}
className="pointer-events-none max-w-[min(24rem,calc(100vw-2rem))] whitespace-normal break-words text-sm data-[side=bottom]:mt-[var(--placeholder-hint-bottom-gap)]">
{resolvedPlaceholder}
</TooltipContent>
) : null}
</Tooltip>
</TooltipProvider>
</div> </div>
{inlineError ? ( {inlineError ? (
<div <div