Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion integrations/tests/tests/pointer-interactions.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,46 @@ test.describe("pointer interactions", () => {
});

test.describe("focus", () => {
for (const returnToStart of [false, true]) {
test(`should blur after dragging${returnToStart ? " back to the starting point" : ""}`, async ({
page: mainPage
}) => {
const page = await goToUrl(
mainPage,
<Group>
<Panel id="left" />
<Separator />
<Panel id="right" />
</Group>
);
const separator = page.getByRole("separator");
const { x, y } = getCenterCoordinates((await separator.boundingBox())!);

await page.mouse.move(x, y);
await page.mouse.down();
await expect(separator).toBeFocused();
await page.mouse.move(x + 25, y);
if (returnToStart) {
await page.mouse.move(x, y);
}
await page.mouse.up();
await expect(separator).not.toBeFocused();
const valueAfterDrag = await separator.getAttribute("aria-valuenow");
await page.keyboard.press("ArrowRight");
await expect(separator).toHaveAttribute(
"aria-valuenow",
valueAfterDrag!
);

// A subsequent click should still retain focus and support keyboard resizing.
await separator.click();
await expect(separator).toBeFocused();
const value = await separator.getAttribute("aria-valuenow");
await page.keyboard.press("ArrowRight");
await expect(separator).not.toHaveAttribute("aria-valuenow", value!);
});
}

test("should update focus to the nearest separator", async ({
page: mainPage
}) => {
Expand Down Expand Up @@ -563,7 +603,8 @@ test.describe("pointer interactions", () => {
await expect(separator).toHaveAttribute("data-separator", "active");

await page.mouse.up();
await expect(separator).toHaveAttribute("data-separator", "focus");
await expect(separator).not.toBeFocused();
await expect(separator).not.toHaveAttribute("data-separator", "active");

await page.mouse.move(0, 0);
await page.mouse.down();
Expand Down
1 change: 1 addition & 0 deletions lib/components/group/ResizePreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ describe("separator previews", () => {
let interaction: InteractionActive = {
state: "active",
cursorFlags: 0,
didPointerMove: false,
hitRegions: [],
initialLayoutMap: new Map(),
previewLayoutMap: new Map(),
Expand Down
1 change: 1 addition & 0 deletions lib/global/event-handlers/onDocumentPointerDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function onDocumentPointerDown(event: PointerEvent) {

updateInteractionState({
cursorFlags: 0,
didPointerMove: false,
hitRegions,
initialLayoutMap,
pointerDownAtPoint: { x: event.clientX, y: event.clientY },
Expand Down
1 change: 1 addition & 0 deletions lib/global/mutable-state/interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test("removing a group preserves the other group in a shared drag", () => {

updateInteractionState({
cursorFlags: 0,
didPointerMove: false,
hitRegions,
initialLayoutMap,
pointerDownAtPoint: { x: 100, y: 100 },
Expand Down
21 changes: 20 additions & 1 deletion lib/global/mutable-state/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export function subscribeToInteractionState(
export function updateCursorFlags(
cursorFlags: number,
previews: ResizePreview[] = [],
previewLayoutMap?: InteractionActive["previewLayoutMap"]
previewLayoutMap?: InteractionActive["previewLayoutMap"],
didPointerMove = false
) {
const prev = state;

const next = { ...state };
next.cursorFlags = cursorFlags;
if (next.state === "active") {
next.didPointerMove ||= didPointerMove;
next.previews = previews;
if (previewLayoutMap) {
next.previewLayoutMap = previewLayoutMap;
Expand All @@ -60,6 +62,23 @@ export function updateInteractionState(next: InteractionState) {

state = next;

// Keep click-to-focus behavior, but release keyboard focus after a drag.
// This also handles interactions completed by the missed-pointerup fallback.
if (
prev.state === "active" &&
next.state !== "active" &&
prev.didPointerMove
) {
prev.hitRegions.forEach(({ separator }) => {
if (
separator &&
separator.element.ownerDocument.activeElement === separator.element
) {
separator.element.blur();
}
});
}

eventEmitter.emit("change", {
prev,
next
Expand Down
1 change: 1 addition & 0 deletions lib/global/mutable-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type ResizePreview = {

export type InteractionActive = {
cursorFlags: number;
didPointerMove: boolean;
hitRegions: HitRegion[];
initialLayoutMap: Map<RegisteredGroup, Layout>;
pointerDownAtPoint: Point;
Expand Down
2 changes: 2 additions & 0 deletions lib/global/utils/updateActiveHitRegion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("updateActiveHitRegions preview bounds", () => {

updateInteractionState({
cursorFlags: 0,
didPointerMove: false,
hitRegions,
initialLayoutMap,
pointerDownAtPoint,
Expand Down Expand Up @@ -121,6 +122,7 @@ describe("updateActiveHitRegions preview bounds", () => {
updateInteractionState({
state: "active",
cursorFlags: 0,
didPointerMove: false,
hitRegions,
initialLayoutMap,
pointerDownAtPoint,
Expand Down
7 changes: 6 additions & 1 deletion lib/global/utils/updateActiveHitRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ export function updateActiveHitRegions({
cursorFlags |= nextCursorFlags & CURSOR_FLAGS_VERTICAL;
}

updateCursorFlags(cursorFlags, previews, previewLayoutMap);
const didPointerMove =
interaction.state === "active" &&
(event.clientX !== interaction.pointerDownAtPoint.x ||
event.clientY !== interaction.pointerDownAtPoint.y);

updateCursorFlags(cursorFlags, previews, previewLayoutMap, didPointerMove);
updateCursorStyle(document);
}
Loading