Skip to content

Logic error on click event causes entire page to scroll right #1901

@mstrelan

Description

@mstrelan

I'm experiencing an issue where clicking on a map scrolls the entire page to the right. This is due to the logic error below, where the x coordinate is incorrectly calculated from the y coordinate. This is only noticeable on pages that have a horizontal scrollbar.

I'm new to Leaflet so not sure the best way to supply this (patch, pull request, something else?) but here is the fix.

diff --git a/src/map/handler/Map.Keyboard.js b/src/map/handler/Map.Keyboard.js
index dabbc02..ddf6759 100644
--- a/src/map/handler/Map.Keyboard.js
+++ b/src/map/handler/Map.Keyboard.js
@@ -65,7 +65,7 @@ L.Map.Keyboard = L.Handler.extend({
        var body = document.body,
            docEl = document.documentElement,
            top = body.scrollTop || docEl.scrollTop,
-           left = body.scrollTop || docEl.scrollLeft;
+           left = body.scrollLeft || docEl.scrollLeft;

        this._map._container.focus();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions