Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions rust/perspective-viewer/src/rust/custom_elements/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::str::FromStr;

use ::perspective_js::utils::global;
use ::perspective_js::{Table, View};
use futures::future::join;
use js_sys::*;
Expand Down Expand Up @@ -399,7 +398,6 @@ impl PerspectiveViewerElement {
/// ```
pub fn restore(&self, update: JsValue) -> ApiFuture<()> {
tracing::info!("Restoring ViewerConfig");
global::document().blur_active_element();
let this = self.clone();
ApiFuture::new(async move {
let decoded_update = ViewerConfigUpdate::decode(&update)?;
Expand Down Expand Up @@ -790,7 +788,6 @@ impl PerspectiveViewerElement {
/// ```
#[wasm_bindgen]
pub fn toggleConfig(&self, force: Option<bool>) -> ApiFuture<JsValue> {
global::document().blur_active_element();
let root = self.root.clone();
ApiFuture::new(async move {
let force = force.map(SettingsUpdate::Update);
Expand Down
2 changes: 0 additions & 2 deletions rust/perspective-viewer/src/rust/utils/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

mod blob;
mod download;
mod focus;
mod request_animation_frame;
mod selection;

Expand All @@ -21,6 +20,5 @@ mod tests;

pub use blob::*;
pub use download::*;
pub use focus::*;
pub use request_animation_frame::*;
pub use selection::*;
19 changes: 19 additions & 0 deletions rust/perspective-viewer/test/html/superstore_with_input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
<script type="module" src="/node_modules/@finos/perspective-test/load-viewer-csv.js"></script>
<link rel="stylesheet" href="../css/demo.css" />
<link rel="stylesheet" href="/node_modules/@finos/perspective-viewer/dist/css/pro.css" />
<link rel="stylesheet" href="/node_modules/@fontsource/roboto-mono/400.css" />
<style>
perspective-viewer {
top: 50px !important;
}
</style>
</head>
<body>
<input />
<perspective-viewer></perspective-viewer>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,38 @@
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

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

/// Blur the current active elemnt, triggering any blur handlers in the
/// application (e.g. modals). This is often necessary when a DOM update will
/// invalidate something that has a `"blur"` event handler.
#[extend::ext]
pub impl Document {
fn blur_active_element(&self) {
self.active_element()
.unwrap()
.unchecked_into::<HtmlElement>()
.blur()
.unwrap();
}
}
test.describe("browser focus", async () => {
test.beforeEach(async function init({ page }) {
await page.goto(
"/node_modules/@finos/perspective-viewer/test/html/superstore_with_input.html"
);

await page.evaluate(async () => {
while (!window["__TEST_PERSPECTIVE_READY__"]) {
await new Promise((x) => setTimeout(x, 10));
}
});

await page.evaluate(async () => {
await document.querySelector("perspective-viewer").restore({
plugin: "Debug",
});
});
});

test("Focus is not lost on external widgets when a restore call takes place", async ({
page,
}) => {
const viewer = page.locator("perspective-viewer");
const tagName = await viewer.evaluate(async (viewer) => {
const input = document.querySelector("input");
input.focus();
await viewer.restore({ group_by: ["State"] });
return document.activeElement.tagName;
});

expect(tagName).toEqual("INPUT");
});
});
Loading