👆 a11y: Show Hover-Revealed Actions to the Touchscreen on a 2-in-1 (#16943)

* fix: Keep Hover-Revealed Row Actions Visible Wherever a Finger Can Reach

* fix: Apply the Coarse-Pointer Reveal to the Composer Palette and Model Menu

* test: Assert the Reveal on an Earlier Reply, Not the Always-Visible Latest One

* test: Read the Timestamp From the Hovered Reply's Own Row

* fix: Hide Until Hover Only Where Hover Exists and No Pointer Is Coarse
This commit is contained in:
Marco Beretta 2026-10-10 00:20:56 +02:00 • committed by GitHub
parent e7484a223b
commit b2c635aa30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 449 additions and 51 deletions

View file

@ -59,11 +59,12 @@ const VIEWPORT_PADDING = 12;
const LIFT_MS = 200;
/** Ariakit portals to document.body by default, which puts the palette outside every landmark. */
const getMainLandmark = () => document.querySelector<HTMLElement>('main');
/** Hidden on hover-capable pointers until the row is hovered or focused.
* Touch keeps them visible. `transition-none` overrides IconButton's color
* fade so the reveal is an appear, not a tint. */
/** Hidden until the row is hovered or focused, wherever no pointer is coarse.
* Any touchscreen keeps them visible, including a 2-in-1's beside its hovering
* trackpad. `transition-none` overrides IconButton's color fade so the reveal
* is an appear, not a tint. */
const ROW_ACTION_REVEAL =
'transition-none opacity-100 group-focus-within/row:opacity-100 group-hover/row:opacity-100 [@media(hover:hover)]:opacity-0';
'transition-none opacity-100 group-focus-within/row:opacity-100 group-hover/row:opacity-100 no-touch:opacity-0';
/** How long the folded destinations take to fade before they give up their
* space; matches `.animate-composer-palette-row-out` in `style.css`. */
const ROW_FADE_MS = 110;

View file

@ -887,7 +887,7 @@ describe('Palette', () => {
expect(configure.parentElement).toHaveClass(
'transition-none',
'opacity-100',
'[@media(hover:hover)]:opacity-0',
'no-touch:opacity-0',
);
await waitFor(() => expect(screen.getByTestId('composer-palette-search')).toHaveFocus());
@ -912,7 +912,7 @@ describe('Palette', () => {
expect(favorite.parentElement).toHaveClass(
'transition-none',
'opacity-100',
'[@media(hover:hover)]:opacity-0',
'no-touch:opacity-0',
);
expect(favorite.parentElement).not.toHaveClass('transition-opacity');
expect(favorite.closest('[role="gridcell"]')).not.toHaveAttribute('id');

View file

@ -123,11 +123,12 @@ function EndpointModelItemComponent({
isFavorite
? 'visible'
: // Visible by default so it's tappable on touch (no hover to
// reveal it); only hidden-until-hover on hover-capable pointers.
// reveal it); only hidden-until-hover where no pointer is coarse,
// so a 2-in-1's touchscreen keeps it beside its hovering trackpad.
// A hover-gated child would otherwise make the whole item
// hover-dependent, so the first tap only reveals it and a second
// tap is needed to select (the iOS double-tap).
'group-focus-within:visible group-hover:visible group-data-[active-item]:visible [@media(hover:hover)]:invisible',
'no-touch:invisible group-focus-within:visible group-hover:visible group-data-[active-item]:visible',
)}
>
<MorphIcon icon={isFavorite ? PinOff : Pin} className="h-4 w-4" />

View file

@ -74,11 +74,12 @@ export function ModelSpecItem({ spec, isSelected, posInSet, setSize }: ModelSpec
isFavorite
? 'visible'
: // Visible by default so it's tappable on touch (no hover to
// reveal it); only hidden-until-hover on hover-capable pointers.
// reveal it); only hidden-until-hover where no pointer is coarse,
// so a 2-in-1's touchscreen keeps it beside its hovering trackpad.
// A hover-gated child would otherwise make the whole item
// hover-dependent, so the first tap only reveals it and a second
// tap is needed to select (the iOS double-tap).
'group-focus-within:visible group-hover:visible group-data-[active-item]:visible [@media(hover:hover)]:invisible',
'no-touch:invisible group-focus-within:visible group-hover:visible group-data-[active-item]:visible',
)}
>
<MorphIcon icon={isFavorite ? PinOff : Pin} className="h-4 w-4" />

View file

@ -41,7 +41,7 @@ describe('OutputRenderer', () => {
const copyButton = screen.getByTestId('copy-output');
expect(copyButton).toHaveClass('absolute', 'right-0', 'bottom-0');
expect(copyButton).toHaveClass('[@media(hover:hover)]:group-hover/copy:opacity-100');
expect(copyButton).toHaveClass('no-touch:group-hover/copy:opacity-100');
expect(copyButton.parentElement).toHaveClass('group/copy', 'relative');
expect(copyButton.parentElement).not.toHaveClass('pr-10');
});

View file

@ -40,7 +40,7 @@ export const FOLD_RAIL_CLASSES = 'relative pl-6';
/**
* A copy action laid over its pane (`group/copy`) instead of beside it, so it
* takes no width from the content. Hidden until the pane is hovered or the
* action holds keyboard focus; touch input, which cannot hover, always sees it.
* action holds keyboard focus; any touchscreen, even beside a trackpad, always sees it.
*/
export const PANE_COPY_REVEAL =
'[@media(hover:hover)]:opacity-0 [@media(hover:hover)]:focus-visible:opacity-100 [@media(hover:hover)]:group-hover/copy:opacity-100';
'no-touch:opacity-0 no-touch:focus-visible:opacity-100 no-touch:group-hover/copy:opacity-100';

View file

@ -230,9 +230,7 @@ const HoverButtons = ({
disabled={!canCopy}
className={cn(
'ml-0 flex items-center gap-1.5 text-xs',
isSubmitting && isCreatedByUser
? 'group-hover:opacity-100 [@media(hover:hover)]:opacity-0'
: '',
isSubmitting && isCreatedByUser ? 'no-touch:opacity-0 group-hover:opacity-100' : '',
)}
dataTestId={!isCreatedByUser ? 'copy-response-button' : undefined}
/>

View file

@ -311,7 +311,7 @@ describe('streaming hover actions', () => {
renderStreamingRow(structured);
expect(screen.getByRole('navigation', { name: 'com_ui_sibling_navigation' })).toHaveClass(
'[@media(hover:hover)]:opacity-0',
'no-touch:opacity-0',
);
});

View file

@ -1,6 +1,6 @@
import { hoverButtonClasses, revealOnRowHoverClasses } from '../styles';
const FADE = '[@media(hover:hover)]:opacity-0';
const FADE = 'no-touch:opacity-0';
/** The row-wide keyboard-focus condition, as two variants. It cannot be one
* `group-[&:is(...)]`: that form makes Tailwind emit a bare `.group$` rule

View file

@ -36,7 +36,7 @@ import { cn } from '~/utils';
* the hover tint would snap instead of fading.
*/
export const revealOnRowHoverClasses =
'transition-[opacity,color,background-color] duration-theme-normal ease-out group-hover:opacity-100 group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100 motion-reduce:transition-none [@media(hover:hover)]:opacity-0';
'transition-[opacity,color,background-color] duration-theme-normal ease-out group-hover:opacity-100 group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100 motion-reduce:transition-none no-touch:opacity-0';
/**
* The message footer, holding the height of its action row.

View file

@ -29,8 +29,9 @@ interface UnpinButtonProps {
* for in JS rather than through an `@media (hover: hover)` variant, the way the
* row's overflow trigger does it: a variant only ever loses or wins the cascade
* against the `group-hover` rules it has to override, and which way it goes
* differs per property. A pointer with no hover gets no gating at all, which is
* the only thing that makes the badge reachable by touch.
* differs per property. A device with any coarse pointer gets no gating at all,
* which is the only thing that makes the badge reachable by touch, including on
* a 2-in-1 whose trackpad answers `(hover: hover)`.
*/
export default function UnpinButton({
onClick,
@ -41,6 +42,7 @@ export default function UnpinButton({
}: UnpinButtonProps) {
const localize = useLocalize();
const hasHoverPointer = useMediaQuery('(hover: hover)');
const hasCoarsePointer = useMediaQuery('(any-pointer: coarse)');
return (
<TooltipAnchor
@ -55,10 +57,11 @@ export default function UnpinButton({
onClick={onClick}
onKeyDown={onKeyDown}
className={cn(
'shrink-0 text-text-secondary',
'text-text-secondary shrink-0',
hasHoverPointer &&
!hasCoarsePointer &&
!keepVisible &&
'pointer-events-none opacity-0 focus-visible:pointer-events-auto focus-visible:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100 group-hover:pointer-events-auto group-hover:opacity-100',
'pointer-events-none opacity-0 group-focus-within:pointer-events-auto group-focus-within:opacity-100 group-hover:pointer-events-auto group-hover:opacity-100 focus-visible:pointer-events-auto focus-visible:opacity-100',
className,
)}
>

View file

@ -396,8 +396,10 @@ p > small {
}
}
/* Show the message time when the row is hovered. Tailwind group-hover
loses to `[@media(hover:hover)]:opacity-0` (same specificity, :where()).
/* Show the message time when the row is hovered. Hidden only where hover
exists and no pointer is coarse: `(hover: hover)` alone is true on a 2-in-1,
whose trackpad hovers while its touchscreen cannot, and the coarse check
alone matches pointerless and print contexts, where nothing reveals it.
Keyboard focus reveals it too, but only `:focus-visible`: a pointer that
clicks a tool card or an expand toggle inside the row leaves focus sitting
@ -410,15 +412,17 @@ p > small {
match `:focus-visible` on a plain mouse click. See `revealOnRowHoverClasses`
in `components/Chat/Messages/styles.ts` for the full reasoning. */
@media (hover: hover) {
.message-render .message-timestamp {
opacity: 0;
}
@media not all and (any-pointer: coarse) {
.message-render .message-timestamp {
opacity: 0;
}
.message-render:hover .message-timestamp,
.message-render:focus-visible .message-timestamp,
.message-render:has(:focus-visible:not(:is(input, textarea, [contenteditable])))
.message-timestamp {
opacity: 1;
.message-render:hover .message-timestamp,
.message-render:focus-visible .message-timestamp,
.message-render:has(:focus-visible:not(:is(input, textarea, [contenteditable])))
.message-timestamp {
opacity: 1;
}
}
}

View file

@ -26,7 +26,7 @@ export const rowActionClasses = ({
cn(
buttonVariants({ variant: 'row-action-reveal', size: 'icon-xs' }),
open && 'bg-surface-active text-text-primary',
(visible || open) && 'opacity-100 [@media(hover:hover)]:opacity-100',
(visible || open) && 'opacity-100 no-touch:opacity-100',
);
/**
@ -37,16 +37,16 @@ export const rowActionClasses = ({
* no one can see. A slot that always reserved its width truncated text that had the
* room to be read, and the ellipsis then said the name was longer than it was.
*
* Where a pointer cannot hover there is no reveal to wait for, so the slot keeps its
* width and the actions stay reachable. Only the collapsed slot clips: once focus is
* Where any pointer is coarse there is no reveal a finger can wait for, so the slot keeps
* its width and the actions stay reachable, on a 2-in-1 whose trackpad hovers too. Only the collapsed slot clips: once focus is
* inside, the focused action's ring has to draw past the slot's edge.
*/
export const rowActionSlotClasses = ({ open = false }: { open?: boolean } = {}): string =>
cn(
'flex shrink-0 items-center gap-0.5',
!open && [
'[@media(hover:hover)]:w-0 [@media(hover:hover)]:overflow-hidden',
'[@media(hover:hover)]:group-hover:w-auto',
'[@media(hover:hover)]:group-focus-within:w-auto [@media(hover:hover)]:group-focus-within:overflow-visible',
'no-touch:w-0 no-touch:overflow-hidden',
'no-touch:group-hover:w-auto',
'no-touch:group-focus-within:w-auto no-touch:group-focus-within:overflow-visible',
],
);

View file

@ -0,0 +1,90 @@
import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import {
REPLY_TEXT,
createProject,
deleteChat,
deleteProject,
earlierReplyCopy,
paintedOpacity,
projectRow,
replyTimestamp,
seedReplyChat,
} from './reveal.helpers';
/**
* A mouse-only desktop keeps the reveal: message actions, the message timestamp and a project
* row's actions stay hidden while the pointer is elsewhere, and come back on hover and on
* keyboard focus. Every project runs this on a desktop context, since the mobile one has no hover
* to test.
*/
test.use({ hasTouch: false, isMobile: false, viewport: { width: 1280, height: 800 } });
test.describe.configure({ timeout: 120_000 });
test('a mouse desktop reveals message actions on hover and keyboard focus @scenario:mouse-desktop-message-actions-reveal', async ({
page,
}) => {
const conversationId = await seedReplyChat(`Mouse reveal ${randomUUID().slice(0, 8)}`);
try {
await page.goto(`/c/${conversationId}`, { timeout: 15000 });
expect(
await page.evaluate(
() => matchMedia('(hover: hover)').matches && !matchMedia('(any-pointer: coarse)').matches,
),
).toBe(true);
const reply = page.getByText(REPLY_TEXT, { exact: true }).first();
await expect(reply).toBeVisible({ timeout: 20000 });
const copy = earlierReplyCopy(page);
const timestamp = replyTimestamp(page);
await expect(copy).toBeAttached();
await expect(timestamp).toBeAttached();
await page.mouse.move(0, 0);
await expect.poll(() => paintedOpacity(copy)).toBe(0);
await expect.poll(() => paintedOpacity(timestamp)).toBe(0);
await reply.hover();
await expect.poll(() => paintedOpacity(copy)).toBe(1);
await expect.poll(() => paintedOpacity(timestamp)).toBe(1);
await page.mouse.move(0, 0);
await expect.poll(() => paintedOpacity(copy)).toBe(0);
await page.keyboard.press('Shift');
await copy.focus();
await expect.poll(() => paintedOpacity(copy)).toBe(1);
} finally {
await deleteChat(conversationId);
}
});
test('a mouse desktop reveals project row actions on hover and keyboard focus @scenario:mouse-desktop-project-row-actions-reveal', async ({
page,
}) => {
await page.addInitScript(() => localStorage.setItem('navVisible', 'true'));
await page.goto('/c/new', { timeout: 15000 });
const name = `Mouse project ${randomUUID().slice(0, 8)}`;
const projectId = await createProject(page, name);
try {
await page.reload();
const row = projectRow(page, name);
await expect(row).toBeVisible({ timeout: 20000 });
const options = row.getByRole('button', { name: 'More options', exact: true });
await page.mouse.move(0, 0);
await expect.poll(() => paintedOpacity(options)).toBe(0);
await row.hover();
await expect.poll(() => paintedOpacity(options)).toBe(1);
await page.mouse.move(0, 0);
await expect.poll(() => paintedOpacity(options)).toBe(0);
await page.keyboard.press('Shift');
await options.focus();
await expect.poll(() => paintedOpacity(options)).toBe(1);
await page.keyboard.press('Enter');
await expect(page.getByRole('menu')).toBeVisible();
await page.keyboard.press('Escape');
} finally {
await deleteProject(page, projectId);
}
});

View file

@ -0,0 +1,64 @@
import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import {
REPLY_TEXT,
createProject,
deleteChat,
deleteProject,
earlierReplyCopy,
paintedOpacity,
projectRow,
replyTimestamp,
seedReplyChat,
} from './reveal.helpers';
/**
* A device with no pointer and no hover, such as a keyboard-only setup. No coarse pointer exists
* there either, so a hiding rule gated only on its absence would hide controls that no hover can
* ever reveal. Described to Blink directly, the same way the 2-in-1 spec does.
*/
test.use({
hasTouch: false,
isMobile: false,
viewport: { width: 1280, height: 800 },
launchOptions: {
args: [
'--blink-settings=availablePointerTypes=1,primaryPointerType=1,availableHoverTypes=1,primaryHoverType=1',
],
},
});
test.describe.configure({ timeout: 120_000 });
test('a pointerless device shows message actions, the timestamp and project row actions @scenario:pointerless-reveal-controls-visible', async ({
page,
}) => {
await page.addInitScript(() => localStorage.setItem('navVisible', 'true'));
const conversationId = await seedReplyChat(`Pointerless reveal ${randomUUID().slice(0, 8)}`);
await page.goto(`/c/${conversationId}`, { timeout: 15000 });
const name = `Pointerless project ${randomUUID().slice(0, 8)}`;
const projectId = await createProject(page, name);
try {
expect(
await page.evaluate(() => ({
hover: matchMedia('(hover: hover)').matches,
coarse: matchMedia('(any-pointer: coarse)').matches,
})),
).toEqual({ hover: false, coarse: false });
await page.reload();
await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({
timeout: 20000,
});
expect(await paintedOpacity(earlierReplyCopy(page))).toBe(1);
expect(await paintedOpacity(replyTimestamp(page))).toBe(1);
const row = projectRow(page, name);
await expect(row).toBeVisible({ timeout: 20000 });
expect(
await paintedOpacity(row.getByRole('button', { name: 'More options', exact: true })),
).toBe(1);
} finally {
await deleteProject(page, projectId);
await deleteChat(conversationId);
}
});

View file

@ -0,0 +1,118 @@
import { randomUUID } from 'crypto';
import { expect } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import { deleteConversations, seedConversations, seedMessages } from '../db';
import { getAccessToken, requestJson } from '../helpers';
import { getE2EUser } from '../../../setup/user';
/**
* Shared by the hover-reveal scenarios: a seeded two-turn chat, a project in the
* sidebar, and the opacity a control actually paints with.
*/
export const REPLY_TEXT = 'Reveal scenario reply';
/** A chat with two turns, opened at its route. The latest reply always shows its actions, so the
* reveal is asserted on the earlier one, `REPLY_TEXT`. */
export async function seedReplyChat(title: string): Promise<string> {
const conversationId = randomUUID();
const { email } = getE2EUser();
await seedConversations(email, [{ conversationId, title, updatedAt: new Date() }]);
const [firstQuestion, firstReply, secondQuestion] = [randomUUID(), randomUUID(), randomUUID()];
await seedMessages(email, conversationId, [
{
messageId: firstQuestion,
parentMessageId: '00000000-0000-0000-0000-000000000000',
text: 'Reveal scenario question',
isCreatedByUser: true,
sender: 'User',
},
{
messageId: firstReply,
parentMessageId: firstQuestion,
text: REPLY_TEXT,
isCreatedByUser: false,
sender: 'Mock Provider A',
},
{
messageId: secondQuestion,
parentMessageId: firstReply,
text: 'Reveal scenario follow-up',
isCreatedByUser: true,
sender: 'User',
},
{
messageId: randomUUID(),
parentMessageId: secondQuestion,
text: 'Reveal scenario latest reply',
isCreatedByUser: false,
sender: 'Mock Provider A',
},
]);
return conversationId;
}
/** The copy action of the earlier reply, the one a reveal hides at rest. */
export const earlierReplyCopy = (page: Page): Locator =>
page.getByTestId('copy-response-button').first();
/** The timestamp in the earlier reply's own row, which its hover reveals. */
export const replyTimestamp = (page: Page): Locator =>
page
.locator('.message-render')
.filter({ hasText: REPLY_TEXT })
.first()
.locator('.message-timestamp')
.first();
export async function deleteChat(conversationId: string): Promise<void> {
await deleteConversations([conversationId]);
}
export async function createProject(page: Page, name: string): Promise<string> {
const token = await getAccessToken(page);
const body = await requestJson<{ _id?: string }>(page, {
path: '/api/projects',
token,
method: 'POST',
body: { name },
});
const id = body._id ?? '';
expect(id).not.toBe('');
return id;
}
export async function deleteProject(page: Page, id: string): Promise<void> {
const token = await getAccessToken(page);
await requestJson<unknown>(page, {
path: `/api/projects/${encodeURIComponent(id)}`,
token,
method: 'DELETE',
});
}
/** The sidebar row of a project, which carries its two trailing actions. */
export const projectRow = (page: Page, name: string): Locator =>
page.getByRole('button', { name, exact: true }).first().locator('..');
/** The opacity a control paints with: its own times every ancestor's, since any of them may be
* the one a reveal rule fades. */
export const paintedOpacity = (locator: Locator): Promise<number> =>
locator.evaluate((node) => {
let opacity = 1;
for (let element: Element | null = node; element; element = element.parentElement) {
opacity *= Number(getComputedStyle(element).opacity);
}
return opacity;
});
/** Whether a finger landing on the control's centre would reach the control itself. */
export const hitAtCenter = (locator: Locator): Promise<boolean> =>
locator.evaluate((node) => {
const box = node.getBoundingClientRect();
if (box.width === 0 || box.height === 0) {
return false;
}
const hit = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2);
return hit !== null && (hit === node || node.contains(hit));
});

View file

@ -0,0 +1,111 @@
import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import {
REPLY_TEXT,
createProject,
deleteChat,
deleteProject,
earlierReplyCopy,
hitAtCenter,
paintedOpacity,
projectRow,
replyTimestamp,
seedReplyChat,
} from './reveal.helpers';
/**
* A 2-in-1: a trackpad that hovers beside a touchscreen. Chromium's own touch emulation makes the
* primary pointer coarse and drops hover, which is a phone, so the device is described to Blink
* directly: fine and coarse pointers available, the fine one primary, and hover available. That
* is the case `(hover: hover)` answers "yes" for while a finger still cannot hover, and every
* reveal-on-hover control has to be visible and tappable without it.
*/
test.use({
hasTouch: false,
isMobile: false,
viewport: { width: 1280, height: 800 },
launchOptions: {
args: [
'--blink-settings=availablePointerTypes=6,primaryPointerType=4,availableHoverTypes=3,primaryHoverType=2',
],
},
});
test.describe.configure({ timeout: 120_000 });
async function expectTwoInOne(page: Page) {
const media = await page.evaluate(() => ({
hover: matchMedia('(hover: hover)').matches,
coarse: matchMedia('(any-pointer: coarse)').matches,
fine: matchMedia('(pointer: fine)').matches,
}));
expect(media).toEqual({ hover: true, coarse: true, fine: true });
}
/** A finger tap: touch events through the protocol, so no mouse hover precedes it. */
async function tap(page: Page, locator: Locator) {
const box = await locator.boundingBox();
expect(box).not.toBeNull();
const point = { x: box!.x + box!.width / 2, y: box!.y + box!.height / 2 };
const session = await page.context().newCDPSession(page);
await session.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [point] });
await session.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] });
await session.detach();
}
/** Opening the sidebar with a click would leave the mouse over it, so it is opened by default. */
async function openWithSidebar(page: Page, path: string) {
await page.addInitScript(() => localStorage.setItem('navVisible', 'true'));
await page.goto(path, { timeout: 15000 });
}
test('a 2-in-1 shows message actions and the timestamp without hover @scenario:two-in-one-message-actions-visible', async ({
page,
}) => {
const conversationId = await seedReplyChat(`2-in-1 reveal ${randomUUID().slice(0, 8)}`);
try {
await openWithSidebar(page, `/c/${conversationId}`);
await expectTwoInOne(page);
await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({
timeout: 20000,
});
const copy = earlierReplyCopy(page);
await expect(copy).toBeAttached();
expect(await paintedOpacity(copy)).toBe(1);
expect(await hitAtCenter(copy)).toBe(true);
const timestamp = replyTimestamp(page);
await expect(timestamp).toBeAttached();
expect(await paintedOpacity(timestamp)).toBe(1);
} finally {
await deleteChat(conversationId);
}
});
test('a 2-in-1 shows a project row action and opens it with a tap @scenario:two-in-one-project-row-actions-tappable', async ({
page,
}) => {
await openWithSidebar(page, '/c/new');
await expectTwoInOne(page);
const name = `2-in-1 project ${randomUUID().slice(0, 8)}`;
const projectId = await createProject(page, name);
try {
await page.reload();
const row = projectRow(page, name);
await expect(row).toBeVisible({ timeout: 20000 });
const options = row.getByRole('button', { name: 'More options', exact: true });
const newChat = row.getByRole('link', { name: `New chat in ${name}`, exact: true });
for (const action of [newChat, options]) {
expect(await paintedOpacity(action)).toBe(1);
expect(await hitAtCenter(action)).toBe(true);
}
await tap(page, options);
await expect(page.getByRole('menu')).toBeVisible();
await page.keyboard.press('Escape');
} finally {
await deleteProject(page, projectId);
}
});

View file

@ -145,9 +145,10 @@ const buttonVariantRecipe = cva(
*/
'row-action': 'rounded-md hover:bg-surface-hover-alt hover:text-text-primary',
/** A row action revealed by hover or keyboard focus, and kept visible
* while its dialog or menu is open. Touch users always see it. */
* while its dialog or menu is open. Any touchscreen, including the one on
* a 2-in-1 whose trackpad reports hover, always sees it. */
'row-action-reveal':
'shrink-0 rounded-md text-text-secondary transition-opacity hover:bg-surface-hover-alt hover:text-text-primary data-[open]:bg-surface-active data-[open]:text-text-primary data-[open]:opacity-100 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:focus-visible:opacity-100 [@media(hover:hover)]:group-focus-within:opacity-100 [@media(hover:hover)]:group-hover:opacity-100',
'shrink-0 rounded-md text-text-secondary transition-opacity hover:bg-surface-hover-alt hover:text-text-primary data-[open]:bg-surface-active data-[open]:text-text-primary data-[open]:opacity-100 no-touch:opacity-0 no-touch:focus-visible:opacity-100 no-touch:group-focus-within:opacity-100 no-touch:group-hover:opacity-100',
link: 'text-text-primary underline-offset-4 hover:underline',
/** A link-weight action in the accent color, such as the alternate way to confirm a sign-in. */
'link-accent':

View file

@ -279,9 +279,13 @@ describe('LibreChat Tailwind preset', () => {
/** `any-pointer`, not `pointer`: the floor has to apply to a 2-in-1's
* touchscreen while its trackpad is the primary device and reports `fine`. */
expect(variants.touch).toBe('@media (any-pointer: coarse)');
/** Its inverse gates hidden-until-hover states, so a 2-in-1's finger user —
* whose trackpad makes `(hover: hover)` true — never loses the control. */
expect(variants['no-touch']).toBe('@media not all and (any-pointer: coarse)');
/** It gates hidden-until-hover states: only where hover exists, so a
* pointerless or print context never hides what nothing can reveal, and
* never where any pointer is coarse, so a 2-in-1's finger user, whose
* trackpad makes `(hover: hover)` true, never loses the control. */
expect(variants['no-touch']).toEqual({
'@media (hover: hover)': { '@media not all and (any-pointer: coarse)': '@slot' },
});
expect(variants['high-contrast']).toBe('html.high-contrast &');
});

View file

@ -222,17 +222,19 @@ module.exports = {
addVariant('touch', '@media (any-pointer: coarse)');
/**
* The inverse of `touch`, for hiding something until hover: hover-gating
* alone strands the finger user of a 2-in-1, because `(hover: hover)` is
* true there — it describes the trackpad — while the touchscreen sits
* right next to it. Gating the hidden state on the absence of any coarse
* pointer keeps a reveal-on-hover affordance from ever hiding a control
* that only a tap can reach.
* For hiding something until hover. Hover-gating alone strands the finger
* user of a 2-in-1, because `(hover: hover)` is true there (it describes
* the trackpad) while the touchscreen sits right next to it, so the hidden
* state also needs the absence of any coarse pointer. The absence alone is
* not enough either: it matches a pointerless or print context, where no
* hover can ever reveal the control again, so both conditions nest.
*
* `not all and`, not the Media Queries Level 4 `not (...)`, because
* lightningcss lowers this for the production build's browser targets.
*/
addVariant('no-touch', '@media not all and (any-pointer: coarse)');
addVariant('no-touch', {
'@media (hover: hover)': { '@media not all and (any-pointer: coarse)': '@slot' },
});
},
],
};