fix(ui): Enter on a selectable title opens it even with its words selected
endsTextSelection takes the click event and exempts a keyboard click (detail 0): Enter / Space ends no selection, so a title selected and then tabbed to opened nothing. All three callers (FocusSafeButton, the Plex caption, the video card title) go through it.
This commit is contained in:
@@ -31,10 +31,24 @@ describe("a selectable button", () => {
|
||||
const btn = screen.getByRole("button");
|
||||
expect(btn.classList.contains("select-text")).toBe(true);
|
||||
selectText(screen.getByText("Andor"));
|
||||
btn.click();
|
||||
fireEvent.click(btn, { detail: 1 }); // the mouseup that ended the drag-select
|
||||
expect(onClick).not.toHaveBeenCalled();
|
||||
window.getSelection()!.removeAllRanges();
|
||||
btn.click();
|
||||
fireEvent.click(btn, { detail: 1 });
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// E28 review H2: Enter / Space on a focused title with its words still selected (selected, then
|
||||
// tabbed to) did nothing — a keyboard click ends no selection; it carries no pointer at all.
|
||||
it("a keyboard click opens even with the title's words selected", () => {
|
||||
const onClick = vi.fn();
|
||||
render(
|
||||
<Pressable selectable onClick={onClick}>
|
||||
<span>Andor</span>
|
||||
</Pressable>,
|
||||
);
|
||||
selectText(screen.getByText("Andor"));
|
||||
fireEvent.click(screen.getByRole("button"), { detail: 0 });
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -80,11 +80,7 @@ export const FocusSafeButton = forwardRef<
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (
|
||||
selectable &&
|
||||
(endsTextSelection(e.currentTarget) || movedPastSlop(pressedAt.current, e))
|
||||
)
|
||||
return;
|
||||
if (selectable && (endsTextSelection(e) || movedPastSlop(pressedAt.current, e))) return;
|
||||
onClick?.(e);
|
||||
}}
|
||||
onMouseDown={(e) => {
|
||||
|
||||
Reference in New Issue
Block a user