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
19 changes: 19 additions & 0 deletions src/internal/item-container/__tests__/item-container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DragAndDropData } from "../../../../lib/components/internal/dnd-control
import { ItemContainer, ItemContainerProps, useItemContext } from "../../../../lib/components/internal/item-container";
import { Coordinates } from "../../../../lib/components/internal/utils/coordinates";

import styles from "../../../../lib/components/internal/item-container/styles.css.js";

afterEach(cleanup);

vi.mock("../../../../lib/components/internal/dnd-controller/controller");
Expand Down Expand Up @@ -121,6 +123,23 @@ describe("keyboard interaction", () => {
expect(onKeyMoveMock).toBeCalledWith("up");
});
});

test("applies keyboardDragged class when keyboard drag transition is active", () => {
const { container } = render(<ItemContainer {...defaultProps} placed={true} />);

act(() => {
mockController.start({
interactionType: "keyboard",
operation: "reorder",
draggableItem: defaultProps.item,
collisionRect: { top: 0, bottom: 0, left: 0, right: 0 },
coordinates: new Coordinates({ x: 0, y: 0 }),
} as DragAndDropData);
});

const itemElement = container.querySelector('[data-item-id="ID"]');
expect(itemElement).toHaveClass(styles.keyboardDragged);
});
});

test("does not renders in portal when item in reorder state by a pointer", () => {
Expand Down
21 changes: 13 additions & 8 deletions src/internal/item-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,19 @@ function ItemContainerComponent(
itemTransitionClassNames.push(styles.inTransition);
}

if (transition && transition.interactionType === "pointer") {
// Adjust the dragged/resized item to the pointer's location.
itemTransitionClassNames.push(transition.operation === "resize" ? styles.resized : styles.dragged);
itemTransitionStyle.insetInlineStart = transition.positionTransform?.x;
itemTransitionStyle.insetBlockStart = transition.positionTransform?.y;
itemTransitionStyle.inlineSize = transition.sizeTransform?.width;
itemTransitionStyle.blockSize = transition.sizeTransform?.height;
itemTransitionStyle.pointerEvents = "none";
if (transition) {
if (transition.interactionType === "pointer") {
// Adjust the dragged/resized item to the pointer's location.
itemTransitionClassNames.push(transition.operation === "resize" ? styles.resized : styles.dragged);
itemTransitionStyle.insetInlineStart = transition.positionTransform?.x;
itemTransitionStyle.insetBlockStart = transition.positionTransform?.y;
itemTransitionStyle.inlineSize = transition.sizeTransform?.width;
itemTransitionStyle.blockSize = transition.sizeTransform?.height;
itemTransitionStyle.pointerEvents = "none";
}
if (transition.interactionType === "keyboard") {
itemTransitionClassNames.push(styles.keyboardDragged);
}
}

if (isHidden) {
Expand Down
3 changes: 3 additions & 0 deletions src/internal/item-container/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
z-index: 2000;
position: fixed;
}
.transformed.keyboardDragged {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why do we define it as .transformed.keyboardDragged and not just .keyboardDragged? That is not an issue, but is asymmetrical to the .dragged style above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because transformed is applied for all board items, not only for the one which is being moved by keyboard. So combining these classes gives you a way to distinguish the active one

z-index: 2000;
}
.resized {
z-index: 2000;
position: absolute;
Expand Down
Loading