diff --git a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java index 9a4052d454c..8388e017563 100644 --- a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java +++ b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java @@ -390,9 +390,9 @@ default void setDragImage(Component dragImage, int offsetX, int offsetY) { ComponentUtil.setData(getDragSourceComponent(), DndUtil.DRAG_SOURCE_IMAGE, dragImage); getDraggableElement().executeJs( - "window.Vaadin.Flow.dndConnector.setDragImage($0, $1, $2, $3)", + "window.Vaadin.Flow.dndConnector.setDragImage($0, $1, $2, this)", dragImage, (dragImage == null ? 0 : offsetX), - (dragImage == null ? 0 : offsetY), getDraggableElement()); + (dragImage == null ? 0 : offsetY)); } private void appendDragElement(Element dragElement) { diff --git a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/internal/DndUtil.java b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/internal/DndUtil.java index 8c50da58a5c..1ccb4dc9a90 100644 --- a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/internal/DndUtil.java +++ b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/internal/DndUtil.java @@ -109,8 +109,7 @@ private DndUtil() { public static void updateDragSourceActivation( DragSource dragSource) { Command command = () -> dragSource.getDraggableElement().executeJs( - "window.Vaadin.Flow.dndConnector.updateDragSource($0)", - dragSource.getDraggableElement()); + "window.Vaadin.Flow.dndConnector.updateDragSource(this)"); runOnAttachBeforeResponse(dragSource.getDragSourceComponent(), command); } @@ -128,8 +127,7 @@ public static void updateDragSourceActivation( public static void updateDropTargetActivation( DropTarget dropTarget) { Command command = () -> dropTarget.getElement().executeJs( - "window.Vaadin.Flow.dndConnector.updateDropTarget($0)", - dropTarget.getElement()); + "window.Vaadin.Flow.dndConnector.updateDropTarget(this)"); runOnAttachBeforeResponse(dropTarget.getDropTargetComponent(), command); diff --git a/flow-server/src/main/java/com/vaadin/flow/component/Focusable.java b/flow-server/src/main/java/com/vaadin/flow/component/Focusable.java index 7bde25cda69..28d78df7ab9 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/Focusable.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/Focusable.java @@ -139,27 +139,27 @@ default void focus(FocusOption... options) { if (json == null) { // No options, call focus() without arguments element.executeJs(""" - setTimeout(function(){ + setTimeout(() => { try { - $0._nextFocusIsFromClient = false; - $0.focus(); + this._nextFocusIsFromClient = false; + this.focus(); } finally { - $0._nextFocusIsFromClient = true; + this._nextFocusIsFromClient = true; } - },0) - """, element); + }, 0) + """); } else { // Call focus with options object passed as parameter element.executeJs(""" - setTimeout(function(){ + setTimeout(() => { try { - $0._nextFocusIsFromClient = false; - $0.focus($1); + this._nextFocusIsFromClient = false; + this.focus($0); } finally { - $0._nextFocusIsFromClient = true; + this._nextFocusIsFromClient = true; } - },0) - """, element, json); + }, 0) + """, json); } } @@ -190,15 +190,15 @@ default void focus() { */ default void blur() { getElement().executeJs(""" - setTimeout(function(){ + setTimeout(() => { try { - $0._nextBlurIsFromClient = false; - $0.blur(); + this._nextBlurIsFromClient = false; + this.blur(); } finally { - $0._nextBlurIsFromClient = true; + this._nextBlurIsFromClient = true; } - },0) - """, getElement()); + }, 0) + """); } /** diff --git a/flow-server/src/main/java/com/vaadin/flow/dom/Element.java b/flow-server/src/main/java/com/vaadin/flow/dom/Element.java index 71c7e86baa7..19d1c08735e 100644 --- a/flow-server/src/main/java/com/vaadin/flow/dom/Element.java +++ b/flow-server/src/main/java/com/vaadin/flow/dom/Element.java @@ -2148,10 +2148,9 @@ public Element scrollIntoView(ScrollIntoViewOption... options) { // Use setTimeout to work on newly created elements if (json == null) { - executeJs("setTimeout(function(){$0.scrollIntoView()},0)", this); + executeJs("setTimeout(() => this.scrollIntoView(), 0)"); } else { - executeJs("setTimeout(function(){$0.scrollIntoView($1)},0)", this, - json); + executeJs("setTimeout(() => this.scrollIntoView($0), 0)", json); } return getSelf(); diff --git a/flow-server/src/test/java/com/vaadin/flow/component/ComponentTest.java b/flow-server/src/test/java/com/vaadin/flow/component/ComponentTest.java index d44e4918a58..82f1115b0ea 100644 --- a/flow-server/src/test/java/com/vaadin/flow/component/ComponentTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/component/ComponentTest.java @@ -2071,12 +2071,12 @@ private void assertScrollIntoViewWithParams(String... expectedJsonParts) { // Verify it uses parameter passing String expression = inv.getExpression(); MatcherAssert.assertThat(expression, - CoreMatchers.containsString("$0.scrollIntoView($1)")); + CoreMatchers.containsString("this.scrollIntoView($0)")); // Verify parameters contain expected JSON parts List params = inv.getParameters(); - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); for (String expectedPart : expectedJsonParts) { MatcherAssert.assertThat(paramJson, CoreMatchers.containsString(expectedPart)); diff --git a/flow-server/src/test/java/com/vaadin/flow/component/FocusableTest.java b/flow-server/src/test/java/com/vaadin/flow/component/FocusableTest.java index d9746ca2745..59f22075957 100644 --- a/flow-server/src/test/java/com/vaadin/flow/component/FocusableTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/component/FocusableTest.java @@ -96,15 +96,15 @@ void focus_withFocusVisible_generatesCorrectJS() { String expression = invocations.get(0).getInvocation().getExpression(); assertTrue(expression.contains("setTimeout"), "Should contain setTimeout wrapper"); - assertTrue(expression.contains(".focus($1)"), + assertTrue(expression.contains(".focus($0)"), "Should contain focus call with parameter"); // Check the parameters List params = invocations.get(0).getInvocation() .getParameters(); - // First param is element, second param is the options object - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + // First param is the options object + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); assertTrue(paramJson.contains("\"focusVisible\":true"), "Should set focusVisible to true"); assertFalse(paramJson.contains("preventScroll"), @@ -123,15 +123,15 @@ void focus_withFocusNotVisible_generatesCorrectJS() { String expression = invocations.get(0).getInvocation().getExpression(); assertTrue(expression.contains("setTimeout"), "Should contain setTimeout wrapper"); - assertTrue(expression.contains(".focus($1)"), + assertTrue(expression.contains(".focus($0)"), "Should contain focus call with parameter"); // Check the parameters List params = invocations.get(0).getInvocation() .getParameters(); - // First param is element, second param is the options object - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + // First param is the options object + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); assertTrue(paramJson.contains("\"focusVisible\":false"), "Should set focusVisible to false"); } @@ -148,15 +148,15 @@ void focus_withPreventScrollEnabled_generatesCorrectJS() { String expression = invocations.get(0).getInvocation().getExpression(); assertTrue(expression.contains("setTimeout"), "Should contain setTimeout wrapper"); - assertTrue(expression.contains(".focus($1)"), + assertTrue(expression.contains(".focus($0)"), "Should contain focus call with parameter"); // Check the parameters List params = invocations.get(0).getInvocation() .getParameters(); - // First param is element, second param is the options object - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + // First param is the options object + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); assertTrue(paramJson.contains("\"preventScroll\":true"), "Should set preventScroll to true"); assertFalse(paramJson.contains("focusVisible"), @@ -175,15 +175,15 @@ void focus_withPreventScrollDisabled_generatesCorrectJS() { String expression = invocations.get(0).getInvocation().getExpression(); assertTrue(expression.contains("setTimeout"), "Should contain setTimeout wrapper"); - assertTrue(expression.contains(".focus($1)"), + assertTrue(expression.contains(".focus($0)"), "Should contain focus call with parameter"); // Check the parameters List params = invocations.get(0).getInvocation() .getParameters(); - // First param is element, second param is the options object - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + // First param is the options object + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); assertTrue(paramJson.contains("\"preventScroll\":false"), "Should set preventScroll to false"); } @@ -200,15 +200,15 @@ void focus_withBothOptions_generatesCorrectJS() { String expression = invocations.get(0).getInvocation().getExpression(); assertTrue(expression.contains("setTimeout"), "Should contain setTimeout wrapper"); - assertTrue(expression.contains(".focus($1)"), + assertTrue(expression.contains(".focus($0)"), "Should contain focus call with parameter"); // Check the parameters List params = invocations.get(0).getInvocation() .getParameters(); - // First param is element, second param is the options object - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + // First param is the options object + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); assertTrue(paramJson.contains("\"preventScroll\":true"), "Should set preventScroll to true"); assertTrue(paramJson.contains("\"focusVisible\":true"), @@ -227,15 +227,15 @@ void focus_withBothOptionsFalse_generatesCorrectJS() { String expression = invocations.get(0).getInvocation().getExpression(); assertTrue(expression.contains("setTimeout"), "Should contain setTimeout wrapper"); - assertTrue(expression.contains(".focus($1)"), + assertTrue(expression.contains(".focus($0)"), "Should contain focus call with parameter"); // Check the parameters List params = invocations.get(0).getInvocation() .getParameters(); - // First param is element, second param is the options object - assertTrue(params.size() >= 2, "Should have at least 2 parameters"); - String paramJson = params.get(1).toString(); + // First param is the options object + assertTrue(params.size() >= 1, "Should have at least 1 parameter"); + String paramJson = params.get(0).toString(); assertTrue(paramJson.contains("\"preventScroll\":false"), "Should set preventScroll to false"); assertTrue(paramJson.contains("\"focusVisible\":false"), @@ -257,13 +257,13 @@ void focus_withoutOptions_generatesCorrectJS() { "Should contain setTimeout wrapper"); assertTrue(expression.contains(".focus()"), "Should contain focus call without parameters"); - assertFalse(expression.contains(".focus($1)"), + assertFalse(expression.contains(".focus($0)"), "Should not contain focus call with parameter"); // Check the parameters List params = invocations.getFirst().getInvocation() .getParameters(); - assertEquals(2, params.size(), - "Should have exactly 1 parameter (the element node and wrapped parameter)"); + assertEquals(1, params.size(), + "Should have exactly 1 wrapped parameter (no user-provided parameters)"); } }