Skip to content

Commit 99be4e7

Browse files
committed
Fix perspective_viewer::restore calls blurring
Signed-off-by: Andrew Stein <[email protected]>
1 parent e1ac495 commit 99be4e7

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

rust/perspective-viewer/src/rust/custom_elements/viewer.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::cell::RefCell;
1616
use std::rc::Rc;
1717
use std::str::FromStr;
1818

19-
use ::perspective_js::utils::global;
2019
use ::perspective_js::{Table, View};
2120
use futures::future::join;
2221
use js_sys::*;
@@ -399,7 +398,6 @@ impl PerspectiveViewerElement {
399398
/// ```
400399
pub fn restore(&self, update: JsValue) -> ApiFuture<()> {
401400
tracing::info!("Restoring ViewerConfig");
402-
global::document().blur_active_element();
403401
let this = self.clone();
404402
ApiFuture::new(async move {
405403
let decoded_update = ViewerConfigUpdate::decode(&update)?;
@@ -790,7 +788,6 @@ impl PerspectiveViewerElement {
790788
/// ```
791789
#[wasm_bindgen]
792790
pub fn toggleConfig(&self, force: Option<bool>) -> ApiFuture<JsValue> {
793-
global::document().blur_active_element();
794791
let root = self.root.clone();
795792
ApiFuture::new(async move {
796793
let force = force.map(SettingsUpdate::Update);

rust/perspective-viewer/src/rust/utils/browser/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
mod blob;
1414
mod download;
15-
mod focus;
1615
mod request_animation_frame;
1716
mod selection;
1817

@@ -21,6 +20,5 @@ mod tests;
2120

2221
pub use blob::*;
2322
pub use download::*;
24-
pub use focus::*;
2523
pub use request_animation_frame::*;
2624
pub use selection::*;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
5+
<script type="module" src="/node_modules/@finos/perspective-test/load-viewer-csv.js"></script>
6+
<link rel="stylesheet" href="../css/demo.css" />
7+
<link rel="stylesheet" href="/node_modules/@finos/perspective-viewer/dist/css/pro.css" />
8+
<link rel="stylesheet" href="/node_modules/@fontsource/roboto-mono/400.css" />
9+
<style>
10+
perspective-viewer {
11+
top: 50px !important;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<input />
17+
<perspective-viewer></perspective-viewer>
18+
</body>
19+
</html>

rust/perspective-viewer/src/rust/utils/browser/focus.rs renamed to rust/perspective-viewer/test/js/focus.spec.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,38 @@
1010
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

13-
use wasm_bindgen::JsCast;
14-
use web_sys::{Document, HtmlElement};
13+
import { test, expect } from "@finos/perspective-test";
1514

16-
/// Blur the current active elemnt, triggering any blur handlers in the
17-
/// application (e.g. modals). This is often necessary when a DOM update will
18-
/// invalidate something that has a `"blur"` event handler.
19-
#[extend::ext]
20-
pub impl Document {
21-
fn blur_active_element(&self) {
22-
self.active_element()
23-
.unwrap()
24-
.unchecked_into::<HtmlElement>()
25-
.blur()
26-
.unwrap();
27-
}
28-
}
15+
test.describe("browser focus", async () => {
16+
test.beforeEach(async function init({ page }) {
17+
await page.goto(
18+
"/node_modules/@finos/perspective-viewer/test/html/superstore_with_input.html"
19+
);
20+
21+
await page.evaluate(async () => {
22+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
23+
await new Promise((x) => setTimeout(x, 10));
24+
}
25+
});
26+
27+
await page.evaluate(async () => {
28+
await document.querySelector("perspective-viewer").restore({
29+
plugin: "Debug",
30+
});
31+
});
32+
});
33+
34+
test("Focus is not lost on external widgets when a restore call takes place", async ({
35+
page,
36+
}) => {
37+
const viewer = page.locator("perspective-viewer");
38+
const tagName = await viewer.evaluate(async (viewer) => {
39+
const input = document.querySelector("input");
40+
input.focus();
41+
await viewer.restore({ group_by: ["State"] });
42+
return document.activeElement.tagName;
43+
});
44+
45+
expect(tagName).toEqual("INPUT");
46+
});
47+
});

0 commit comments

Comments
 (0)