Skip to content

PB-1054 : Remove mouse events from useMovableElement and replace with pointer events#1345

Merged
sami-nouidri-swisstopo merged 1 commit intodevelopfrom
bug-PB-1054-tooltip-touch-events
May 20, 2025
Merged

PB-1054 : Remove mouse events from useMovableElement and replace with pointer events#1345
sami-nouidri-swisstopo merged 1 commit intodevelopfrom
bug-PB-1054-tooltip-touch-events

Conversation

@sami-nouidri-swisstopo
Copy link
Contributor

@sami-nouidri-swisstopo sami-nouidri-swisstopo commented May 16, 2025

Mouse events have been removed in favour of pointer events for better compatibility with mobile devices and touch screens.

Test link

@github-actions github-actions bot added the bug label May 16, 2025
@cypress
Copy link

cypress bot commented May 16, 2025

web-mapviewer    Run #5356

Run Properties:  status check passed Passed #5356  •  git commit 54ae2d85af: PB-1054 : Remove mouse events from Movable and replace with pointer events
Project web-mapviewer
Branch Review bug-PB-1054-tooltip-touch-events
Run status status check passed Passed #5356
Run duration 06m 17s
Commit git commit 54ae2d85af: PB-1054 : Remove mouse events from Movable and replace with pointer events
Committer Sami Nouidri
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 20
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 251
View all changes introduced in this branch ↗︎

@sami-nouidri-swisstopo sami-nouidri-swisstopo force-pushed the bug-PB-1054-tooltip-touch-events branch from bead635 to 26912a7 Compare May 19, 2025 06:46
@sami-nouidri-swisstopo sami-nouidri-swisstopo force-pushed the bug-PB-1054-tooltip-touch-events branch from 26912a7 to 1a5b6de Compare May 19, 2025 07:26
pakb
pakb previously requested changes May 19, 2025
Copy link
Contributor

@pakb pakb left a comment

Choose a reason for hiding this comment

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

Good idea, but the outcome isn't there yet.

I've tested a bit on my phone (iPhone) and I can't "scroll" the content of a layer description anymore, as it tries to move it around.
So there's maybe something to do to not prevent scrolling

@sami-nouidri-swisstopo sami-nouidri-swisstopo force-pushed the bug-PB-1054-tooltip-touch-events branch 2 times, most recently from 2273721 to 5b61e0c Compare May 19, 2025 09:13
Comment on lines +91 to +104
const el = toValue(element)
const rect = el.getBoundingClientRect()
const newLeft = clamp(
el.offsetLeft + deltaX,
viewport.value.left,
viewport.value.right - rect.width
)
const newTop = clamp(
el.offsetTop + deltaY,
viewport.value.top,
viewport.value.bottom - rect.height
)

placeElementAt(newTop, newLeft, MovementSource.POINTER_DRAG)
Copy link
Contributor

Choose a reason for hiding this comment

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

except the presence of the deltaX / deltaY within the clamp, this is exactly the same as the constrainElementWithinViewport function.

I would either :

  • change the offsetLeft / offsetRight attributes from elem, then call constrainElementWithinViewport or
  • add the deltaX / deltaY to the function as optional parameters (defaulting to 0) and call the function with the parameter in this way :
    constrainElementWithinViewport(deltaX, deltaY)

Copy link
Contributor

Choose a reason for hiding this comment

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

that being said, I might be wrong about this... it's just that I like functions ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with the second option of adding delta arguments to constrainElementWithinViewport as offsetLeft
and offsetRight are getters only.

@sami-nouidri-swisstopo sami-nouidri-swisstopo force-pushed the bug-PB-1054-tooltip-touch-events branch 4 times, most recently from 343c9a9 to 4e4a795 Compare May 19, 2025 12:21
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

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

A small refinement here and there, but the functionality seems good to me

useMovableElement(popover.value, {
useMovableElement({
element: popover.value,
grabElement: popoverHeader,
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems to work, but maybe we need to be attentive to the fact that in other cases, we're using the reference's value (.value) When tackling #1309, you might want to remember this difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Setting this to grabElement.value would mean that we can get rid of all the toValue in the composable and simplify it, as well as ensuring we always give the same kind of variable when calling the function. I would take advantage of the situation and do it now :)

* @param element Reference to a DOM element
* @param options Options such as described below
* @param config {Object} Configuration object
* @param {HTMLElement} [options.grabElement] HTML element on which the user has to grab to start
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to update the comment :

  • it's no longer options.key but config.key.
  • also we need to add the element to the config doc here

initialPositionClasses = [],
} = config

if (!config.element || !config.grabElement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

offset is always defined, we should also enforce offset to have a value.

} = config

if (!config.element || !config.grabElement) {
throw new Error('Element/grabElement is required')
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make the error a bit more explicit :

[useMovableElement] Element, grabElement and offset are required to use a movable element. Received ${element} for element, ${grabElement} for grabElement and ${offset} for offset. or something like that.

MovementSource.WINDOW_RESIZE
)
}
function constrainElementWithinViewport(deltaX = 0, deltaY = 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not put default values here, and add the 0, 0 as parameter in the initialize call. This forces us to be explicit in tests and in the code.

I would also rework the comment a bit, as we now also handle placing an element and not only ensuring it's within bounds at startup.

@sami-nouidri-swisstopo sami-nouidri-swisstopo force-pushed the bug-PB-1054-tooltip-touch-events branch 3 times, most recently from 2695b72 to c90bc5d Compare May 19, 2025 14:27
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

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

One small last change :)

Comment on lines +82 to +83
element: windowElement.value,
grabElement: headerElement.value,
Copy link
Contributor

Choose a reason for hiding this comment

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

thos are already the values of windowRef or headerRef, no need for an extra value here.

…vents

Mouse events have been removed in favour of pointer events for better
compatibility with mobile devices and touch screens.
@sami-nouidri-swisstopo sami-nouidri-swisstopo force-pushed the bug-PB-1054-tooltip-touch-events branch from c90bc5d to 54ae2d8 Compare May 20, 2025 07:04
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

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

LGTM

@sami-nouidri-swisstopo sami-nouidri-swisstopo dismissed pakb’s stale review May 20, 2025 07:19

the problem will be solved in another ticket (PB-1309)

@sami-nouidri-swisstopo sami-nouidri-swisstopo merged commit 79e1aed into develop May 20, 2025
6 checks passed
@sami-nouidri-swisstopo sami-nouidri-swisstopo deleted the bug-PB-1054-tooltip-touch-events branch May 20, 2025 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants