fix(webui): remove composer placeholder tooltip
This commit is contained in:
1 parent
f5a8a41b15
commit
11f738f0fe
2 files changed
+35
-114
No files matched your search
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,65 +2423,39 @@ export function ThreadComposer({
|
|||||||
: null}
|
: null}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<TooltipProvider>
|
<textarea
|
||||||
<Tooltip open={placeholderHintOpen}>
|
ref={textareaRef}
|
||||||
<TooltipTrigger asChild>
|
value={mentionInput.value}
|
||||||
<textarea
|
onFocus={() => {
|
||||||
ref={textareaRef}
|
if (compactWhenIdle) setComposerFocused(true);
|
||||||
value={mentionInput.value}
|
}}
|
||||||
onFocus={(event) => {
|
onChange={mentionInput.onChange}
|
||||||
if (tabFocusRequested.current && !event.currentTarget.value) setPlaceholderHintRequested(true);
|
onCompositionStart={mentionInput.onCompositionStart}
|
||||||
tabFocusRequested.current = false;
|
onCompositionEnd={mentionInput.onCompositionEnd}
|
||||||
if (compactWhenIdle) setComposerFocused(true);
|
onKeyDown={onKeyDown}
|
||||||
}}
|
onKeyUp={() => setCursorPosition(rawSelection().start)}
|
||||||
onBlur={() => {
|
onSelect={() => setCursorPosition(rawSelection().start)}
|
||||||
if (placeholderHintRequested) setPlaceholderHintRequested(false);
|
onClick={() => setCursorPosition(rawSelection().start)}
|
||||||
}}
|
onCopy={mentionInput.onCopy}
|
||||||
onPointerLeave={(event) => {
|
onCut={mentionInput.onCut}
|
||||||
if (event.pointerType === "mouse" && placeholderHintRequested) setPlaceholderHintRequested(false);
|
onScroll={(e) => {
|
||||||
}}
|
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = e.currentTarget.scrollTop;
|
||||||
onChange={mentionInput.onChange}
|
}}
|
||||||
onCompositionStart={mentionInput.onCompositionStart}
|
onPaste={onPaste}
|
||||||
onCompositionEnd={mentionInput.onCompositionEnd}
|
rows={1}
|
||||||
onKeyDown={onKeyDown}
|
enterKeyHint={hasCoarsePointer ? "enter" : undefined}
|
||||||
onKeyUp={() => setCursorPosition(rawSelection().start)}
|
placeholder={sessionDragPreview ? "" : displayedPlaceholder}
|
||||||
onSelect={() => setCursorPosition(rawSelection().start)}
|
disabled={interactionDisabled}
|
||||||
onClick={(event) => {
|
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
|
||||||
setCursorPosition(rawSelection().start);
|
aria-description={sessionDragPreview ? undefined : resolvedPlaceholder}
|
||||||
if (!event.currentTarget.value) setPlaceholderHintRequested(true);
|
className={cn(
|
||||||
}}
|
inputTextClasses,
|
||||||
onCopy={mentionInput.onCopy}
|
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
|
||||||
onCut={mentionInput.onCut}
|
"focus:outline-none focus-visible:outline-none",
|
||||||
onScroll={(e) => {
|
"disabled:cursor-not-allowed",
|
||||||
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = e.currentTarget.scrollTop;
|
hasInlineDecorations && "text-transparent selection:bg-primary/20",
|
||||||
}}
|
)}
|
||||||
onPaste={onPaste}
|
/>
|
||||||
rows={1}
|
|
||||||
enterKeyHint={hasCoarsePointer ? "enter" : undefined}
|
|
||||||
placeholder={sessionDragPreview ? "" : displayedPlaceholder}
|
|
||||||
disabled={interactionDisabled}
|
|
||||||
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
|
|
||||||
aria-description={sessionDragPreview ? undefined : resolvedPlaceholder}
|
|
||||||
className={cn(
|
|
||||||
inputTextClasses,
|
|
||||||
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
|
|
||||||
"focus:outline-none focus-visible:outline-none",
|
|
||||||
"disabled:cursor-not-allowed",
|
|
||||||
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
|
||||||
|
|||||||
Reference in new issue
Block a user