Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

style(ui): format surface keyboard component and tests

Sameh Khamisbd6ba0787898
diff --git a/scripts/format-scope.json b/scripts/format-scope.json
index f2c1bd6c9..866a92dcf 100644
--- a/scripts/format-scope.json
+++ b/scripts/format-scope.json
@@ -120,5 +120,7 @@
"src/search/google.js",
"src/keylessGeocoder.js",
"src/standalone/placeSearch.js",
- "src/ui/panelDisclosure.js"
+ "src/ui/panelDisclosure.js",
+ "src/ui/surfaceKeyboard.js",
+ "src/ui/surfaceKeyboard.test.mjs"
]
diff --git a/src/ui/surfaceKeyboard.js b/src/ui/surfaceKeyboard.js
index e7eb07404..38417975a 100644
--- a/src/ui/surfaceKeyboard.js
+++ b/src/ui/surfaceKeyboard.js
@@ -34,8 +34,13 @@ export function createSurfaceKeyboard({
}
if (event.key !== 'Tab') return;
const order = [
- ...root.querySelectorAll('button, input, [href], [tabindex]:not([tabindex="-1"])'),
- ].filter((node) => !node.hasAttribute('disabled') && node.getClientRects().length > 0);
+ ...root.querySelectorAll(
+ 'button, input, [href], [tabindex]:not([tabindex="-1"])',
+ ),
+ ].filter(
+ (node) =>
+ !node.hasAttribute('disabled') && node.getClientRects().length > 0,
+ );
if (!order.length) return;
const first = order[0];
const last = order[order.length - 1];
diff --git a/src/ui/surfaceKeyboard.test.mjs b/src/ui/surfaceKeyboard.test.mjs
index 36a3d03b5..d9b8388cf 100644
--- a/src/ui/surfaceKeyboard.test.mjs
+++ b/src/ui/surfaceKeyboard.test.mjs
@@ -22,9 +22,16 @@ function fixture() {
hidden: false,
disabled: false,
focusCalls: [],
- hasAttribute(name) { return name === 'disabled' && this.disabled; },
- getClientRects() { return this.hidden ? [] : [{}]; },
- focus(options) { documentRef.activeElement = this; this.focusCalls.push(options); },
+ hasAttribute(name) {
+ return name === 'disabled' && this.disabled;
+ },
+ getClientRects() {
+ return this.hidden ? [] : [{}];
+ },
+ focus(options) {
+ documentRef.activeElement = this;
+ this.focusCalls.push(options);
+ },
});
const opener = node();
const fallback = node();
@@ -39,7 +46,9 @@ function fixture() {
};
let visible = true;
let escapes = 0;
- let onEscape = () => { escapes += 1; };
+ let onEscape = () => {
+ escapes += 1;
+ };
const controller = createSurfaceKeyboard({
root,
isActive: () => visible,
@@ -51,8 +60,12 @@ function fixture() {
key,
defaultPrevented: false,
stopped: false,
- preventDefault() { this.defaultPrevented = true; },
- stopPropagation() { this.stopped = true; },
+ preventDefault() {
+ this.defaultPrevented = true;
+ },
+ stopPropagation() {
+ this.stopped = true;
+ },
...extra,
});
const send = (key, extra) => {
@@ -60,10 +73,27 @@ function fixture() {
for (const listener of [...listeners]) listener(e);
return e;
};
- return { controller, listeners, documentRef, opener, fallback, first, middle, last, node, event, send,
- setVisible(value) { visible = value; },
- setControls(value) { controls = value; },
- setEscape(value) { onEscape = value; },
+ return {
+ controller,
+ listeners,
+ documentRef,
+ opener,
+ fallback,
+ first,
+ middle,
+ last,
+ node,
+ event,
+ send,
+ setVisible(value) {
+ visible = value;
+ },
+ setControls(value) {
+ controls = value;
+ },
+ setEscape(value) {
+ onEscape = value;
+ },
escapes: () => escapes,
};
}
@@ -97,7 +127,11 @@ test('Tab enters from outside in either direction and wraps only at an edge', ()
f.opener.focus();
f.send('Tab', { shiftKey: true });
assert.equal(f.documentRef.activeElement, f.last);
- assert.equal(f.last.focusCalls.at(-1), undefined, 'wrapping permits native scroll into view');
+ assert.equal(
+ f.last.focusCalls.at(-1),
+ undefined,
+ 'wrapping permits native scroll into view',
+ );
});
test('Tab uses current controls and skips hidden/disabled nodes without changing native middle movement', () => {