Skip to content

Commit 19f21ea

Browse files
authored
feat: Add deactivate event for dev tools tabs (#17618)
1 parent 246553a commit 19f21ea

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

flow-tests/test-dev-mode/frontend/devtools-plugin.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ let devTools: DevToolsInterface;
1111

1212
@customElement('my-tool')
1313
export class MyTool extends LitElement implements MessageHandler {
14-
1514
@property({ type: Array })
1615
messages: string[] = [];
1716

@@ -45,6 +44,12 @@ export class MyTool extends LitElement implements MessageHandler {
4544
text: 'Hello from dev tools plugin'
4645
});
4746
}
47+
activate() {
48+
this.messages.push('activate called');
49+
}
50+
deactivate() {
51+
this.messages.push('deactivate called');
52+
}
4853
}
4954

5055
const plugin: DevToolsPlugin = {

flow-tests/test-dev-mode/src/test/java/com/vaadin/flow/uitest/ui/DevToolsPluginIT.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ public void devToolsPluginWorks() {
3636
devTools.showTab("Hello");
3737
TestBenchElement myTool = devTools.$("my-tool").first();
3838

39-
assertMessages(myTool, "plugin-init");
39+
assertMessages(myTool, "plugin-init", "activate called");
4040
myTool.$(NativeButtonElement.class).first().click();
41-
assertMessages(myTool, "plugin-init",
41+
assertMessages(myTool, "plugin-init", "activate called",
4242
"Response for Hello from dev tools plugin");
4343

4444
$(NativeButtonElement.class).id("refresh").click();
4545
Assert.assertEquals("Hello from dev tools plugin",
4646
$("div").id("injected").getText());
47+
48+
devTools.showTab("code");
49+
devTools.showTab("Hello");
50+
assertMessages(myTool, "plugin-init", "activate called",
51+
"Response for Hello from dev tools plugin", "deactivate called",
52+
"activate called");
53+
4754
}
4855

4956
private void assertMessages(TestBenchElement myTool, String... expected) {

vaadin-dev-server/frontend/vaadin-dev-tools.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,13 @@ export class VaadinDevTools extends LitElement {
13711371
})}
13721372
id="${tab.id}"
13731373
@click=${() => {
1374+
const currentTab = this.tabs.find((tab) => tab.id === this.activeTab);
1375+
if (currentTab && currentTab.element) {
1376+
const deactivateMethod = (currentTab.element as any)?.deactivate;
1377+
if (deactivateMethod) {
1378+
deactivateMethod.call(currentTab.element);
1379+
}
1380+
}
13741381
this.activeTab = tab.id;
13751382
const activateMethod = (tab.element as any).activate;
13761383
if (activateMethod) {

0 commit comments

Comments
 (0)