Skip to content

Commit

Permalink
Fix keyboard events from map anchor children.
Browse files Browse the repository at this point in the history
OpenLayers 10 listens on the entire shadow root by default, which can be too broad.
  • Loading branch information
mbeckem committed Dec 5, 2024
1 parent 53dcc07 commit 7a5f1e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-ways-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@open-pioneer/map": patch
---

Fix keyboard events from map anchors after update to OpenLayers 10.
10 changes: 10 additions & 0 deletions src/packages/map/ui/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,23 @@ function registerMapTarget(mapModel: MapModel, target: HTMLDivElement): Resource
}

LOG.isDebug() && LOG.debug(`Setting target of map '${mapId}':`, target);
if (!("keyboardEventTarget_" in olMap)) {
throw new Error(
"Internal error: failed to override keyboard event target. The property is no longer present."
);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(olMap as any).keyboardEventTarget_ = target;
olMap.setTarget(target);

let unregistered = false;
return {
destroy() {
if (!unregistered) {
LOG.isDebug() && LOG.debug(`Removing target of map '${mapId}':`, target);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(olMap as any).keyboardEventTarget_ = undefined;
olMap.setTarget(undefined);
unregistered = true;
}
Expand Down

0 comments on commit 7a5f1e1

Please sign in to comment.