Skip to content

Context menu breaks when switching between small and large screen layout #203

Closed

Description

@easbar
  1. right click the map -> context menu opens
  2. close the context menu (using the new x button, or choose something like 'Center map here')
  3. press F12 to open the dev tools
  4. right click the map again -> the default browser context menu opens (Save page as... etc.), we can no longer open the GH maps context menu

Activity

  1. added
    bug
    firefox
    on Aug 31, 2022
  2. easbar commented on Oct 5, 2022

    @easbar
    MemberAuthor

    Apparently this was fixed somewhere, or at least I can no longer reproduce this.

  3. reopened this on Nov 10, 2022
  4. easbar commented on Nov 10, 2022

    @easbar
    MemberAuthor

    The context menu still breaks when I

    1. open the app
    2. reduce the window size until it switches to the small screen layout
    3. right-click the map -> I see the default (browser) context menu, instead of the app context menu

    And it even happens in Chrome too.

  5. changed the title [-]Context menu breaks when opening dev tools in Firefox[/-] [+]Context menu breaks[/+] on Nov 10, 2022
  6. changed the title [-]Context menu breaks[/-] [+]Context menu breaks when switching between small and large screen layout[/+] on Nov 10, 2022
  7. easbar commented on Nov 10, 2022

    @easbar
    MemberAuthor

    I think this is because we register the click listeners on the container element, which changes once we switch between the small & large layout:

    map.once('change:target', () => {
    // we cannot listen to right-click simply using map.on('contextmenu') and need to add the listener to
    // the map container instead
    // https://github.com/openlayers/openlayers/issues/12512#issuecomment-879403189
    map.getTargetElement().addEventListener('contextmenu', openContextMenu)
    map.getTargetElement().addEventListener('touchstart', e => longTouchHandler.onTouchStart(e))
    map.getTargetElement().addEventListener('touchmove', () => longTouchHandler.onTouchEnd())
    map.getTargetElement().addEventListener('touchend', () => longTouchHandler.onTouchEnd())
    map.getTargetElement().addEventListener('click', closeContextMenu)
    })
    return () => {
    map.getTargetElement().removeEventListener('contextmenu', openContextMenu)
    map.getTargetElement().removeEventListener('click', closeContextMenu)
    map.removeOverlay(overlay)
    }
    }, [map])

    Changing map.once to map.on seems to fix it. I'm just not sure if we need to clean up the listeners somehow then?

  8. easbar commented on Nov 10, 2022

    @easbar
    MemberAuthor

    Changing map.once to map.on seems to fix it. I'm just not sure if we need to clean up the listeners somehow then?

    Apparently no. I used this function that lists all event listeners and switched there and back between the small and the large layout. The number of listeners did not increase with every switch: https://gist.github.com/tkafka/1c5174ed5b446de7dfa4c04a3b09c95f

  9. karussell commented on Nov 10, 2022

    @karussell
    Member

    Oh, nice. Thank you!

  10. added a commit that references this issue on Nov 12, 2024
    a959f4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfirefox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions