Skip to content

Commit f3c971e

Browse files
committed
[FIX] web: ignore !important % width/height on dragged elements
This commit fixes an issue in draggable_hook_builder where elements with !important percentage-based width or height styles would be incorrectly sized when dragged. The sizing would be computed relative to the document rather than the style computed by the hook. To address this, the hook now applies max-width and max-height styles explicitly. This helps enforce correct sizing and prevents !important rules from interfering with the visual consistency of dragged elements. The issue was first spotted in the actions kanban view present in the automation rules form view. task-4891808 closes odoo#220565 X-original-commit: fd2dee1 Signed-off-by: Bruno Boi (boi) <boi@odoo.com>
1 parent 66265b4 commit f3c971e

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

addons/web/static/src/core/utils/draggable_hook_builder.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,15 +500,14 @@ export function makeDraggableHook(hookParams) {
500500
state.willDrag = false;
501501

502502
// Compute scrollable parent
503-
const isDocumentScrollingElement = ctx.current.container
504-
=== ctx.current.container.ownerDocument.scrollingElement;
503+
const isDocumentScrollingElement =
504+
ctx.current.container === ctx.current.container.ownerDocument.scrollingElement;
505505
// If the container is the "ownerDocument.scrollingElement",
506506
// there is no need to get the scroll parent as it is the
507507
// scrollable element itself.
508508
// TODO: investigate if "getScrollParents" should not consider
509509
// the "ownerDocument.scrollingElement" directly.
510-
[ctx.current.scrollParentX, ctx.current.scrollParentY] =
511-
isDocumentScrollingElement
510+
[ctx.current.scrollParentX, ctx.current.scrollParentY] = isDocumentScrollingElement
512511
? [ctx.current.container, ctx.current.container]
513512
: getScrollParents(ctx.current.container);
514513

@@ -525,6 +524,9 @@ export function makeDraggableHook(hookParams) {
525524
dom.addStyle(ctx.current.element, {
526525
width: `${width}px`,
527526
height: `${height}px`,
527+
// Limit the impact of width and height !important on the dragged element
528+
"max-width": `${width}px`,
529+
"max-height": `${height}px`,
528530
position: "fixed !important",
529531
});
530532

addons/web/static/tests/core/utils/draggable.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ test("Dragging element with touch event: initiation delay can be overrided", asy
341341
});
342342

343343
test.tags("desktop");
344-
test("Elements are confined within their container", async () => {
344+
test("Elements are confined within their container and keep their initial width and height", async () => {
345345
class List extends Component {
346346
static template = xml`
347-
<div t-ref="root" class="root">
347+
<div t-ref="root" class="root" style="width: 800px; height: 600px;">
348348
<ul class="list list-unstyled m-0 d-flex flex-column">
349-
<li t-foreach="[1, 2, 3]" t-as="i" t-key="i" t-esc="i" class="item w-50" />
349+
<li t-foreach="[1, 2, 3]" t-as="i" t-key="i" t-esc="i" class="item w-50 h-100" />
350350
</ul>
351351
</div>
352352
`;
@@ -363,6 +363,7 @@ test("Elements are confined within their container", async () => {
363363
await mountWithCleanup(List);
364364

365365
const containerRect = queryRect(".root");
366+
const { width: initialWidth, height: initialHeight } = queryRect(".item:first");
366367

367368
const { moveTo, drop } = await contains(".item:first").drag({
368369
initialPointerMoveDistance: 0,
@@ -384,6 +385,11 @@ test("Elements are confined within their container", async () => {
384385
y: containerRect.y + containerRect.height - queryRect(".item:first").height,
385386
});
386387

388+
expect(".item:first").toHaveRect({
389+
width: initialWidth,
390+
height: initialHeight,
391+
});
392+
387393
await moveTo(".item:last-child", {
388394
position: { x: 9999, y: 9999 },
389395
});

0 commit comments

Comments
 (0)