diff --git a/src/mapml/layers/MapMLLayer.js b/src/mapml/layers/MapMLLayer.js
index d5c282dc1..06f33e9fc 100644
--- a/src/mapml/layers/MapMLLayer.js
+++ b/src/mapml/layers/MapMLLayer.js
@@ -489,10 +489,10 @@ export var MapMLLayer = L.LayerGroup.extend({
map.featureIndex._sortIndex();
map.featureIndex.currentIndex =
map.featureIndex.inBoundFeatures.length - 1;
- map.featureIndex.inBoundFeatures[0].path.setAttribute('tabindex', -1);
+ map.featureIndex.inBoundFeatures[0]?.path.setAttribute('tabindex', -1);
map.featureIndex.inBoundFeatures[
map.featureIndex.currentIndex
- ].path.setAttribute('tabindex', 0);
+ ]?.path.setAttribute('tabindex', 0);
L.DomEvent.stop(e);
map.closePopup();
map._controlContainer.querySelector('A:not([hidden])').focus();
diff --git a/test/e2e/core/focusControls.html b/test/e2e/core/focusControls.html
new file mode 100644
index 000000000..760b59342
--- /dev/null
+++ b/test/e2e/core/focusControls.html
@@ -0,0 +1,35 @@
+
+
+
+
+ Query Popup Navigation test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/e2e/core/focusControls.test.js b/test/e2e/core/focusControls.test.js
new file mode 100644
index 000000000..b86e821f0
--- /dev/null
+++ b/test/e2e/core/focusControls.test.js
@@ -0,0 +1,24 @@
+import { test, expect, chromium } from '@playwright/test';
+
+test.describe('Playwright Keyboard Navigation + Query Layer Tests', () => {
+ let page;
+ let context;
+ test.beforeAll(async () => {
+ context = await chromium.launchPersistentContext('');
+ page =
+ context.pages().find((page) => page.url() === 'about:blank') ||
+ (await context.newPage());
+ await page.goto('focusControls.html');
+ await page.waitForTimeout(1000);
+ });
+
+ test.afterAll(async function () {
+ await context.close();
+ });
+
+ test('Focus Controls button after query focuses the zoom in control', async () => {
+ await page.getByTestId('viewer').click();
+ await page.getByTitle('Focus Controls').click();
+ await expect(page.getByTitle('Zoom in')).toBeFocused();
+ });
+});
diff --git a/test/e2e/data/tiles/cbmt/query-feature.mapml b/test/e2e/data/tiles/cbmt/query-feature.mapml
new file mode 100644
index 000000000..f1b72dde5
--- /dev/null
+++ b/test/e2e/data/tiles/cbmt/query-feature.mapml
@@ -0,0 +1,18 @@
+
+
+ A Feature, Returned by a Query
+
+
+
+
+
+ Test
+
+
+
+ -2826361 3009094 3788235 3009094 3788235 -3605502 -2826361 -3605502 -2826361 3009094
+
+
+
+
+
\ No newline at end of file