Skip to content

Commit 456a7bd

Browse files
authored
Merge pull request #301 from magjac/fix-fullscreen-button-steals-keyboard-focus-away-from-the-canvas
2 parents 5eeae29 + a705d45 commit 456a7bd

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

cypress/e2e/fullscreen_graph.spec.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,76 @@ describe('Show graph only mode', function () {
6666
cy.toolbar().should('exist');
6767
cy.canvas().invoke('width').should('be.lt', viewportWidth / 2)
6868
});
69+
70+
it('Shows the graph only when the open in full button is clicked and shows the full application again when the \'f\' key is pressed', function () {
71+
cy.startCleanApplication();
72+
cy.clearAndRenderDotSource('digraph {Alice -> Bob}');
73+
74+
cy.node(1).should('exist');
75+
cy.node(2).should('exist');
76+
cy.edge(1).should('exist');
77+
78+
cy.node(1).shouldHaveName('Alice');
79+
cy.node(2).shouldHaveName('Bob');
80+
cy.edge(1).shouldHaveName('Alice->Bob');
81+
82+
cy.nodes().should('have.length', 2);
83+
cy.edges().should('have.length', 1);
84+
85+
cy.textEditorWrapper().should('be.visible');
86+
cy.toolbar().should('exist');
87+
cy.canvas().invoke('width').should('be.lt', viewportWidth / 2)
88+
89+
cy.canvas().click();
90+
cy.fullscreenButton().click();
91+
92+
cy.textEditorWrapper().should('not.be.visible');
93+
cy.toolbar().should('not.exist');
94+
cy.canvas().invoke('width').should('be.eq', viewportWidth)
95+
96+
cy.get('body').type('f');
97+
98+
cy.textEditorWrapper().should('be.visible');
99+
cy.toolbar().should('exist');
100+
cy.canvas().invoke('width').should('be.lt', viewportWidth / 2)
101+
});
102+
103+
it('Shows the graph only when the \'f\' key is pressed after a previous fullscreen has been disabled by clicking the open in full button', function () {
104+
cy.startCleanApplication();
105+
cy.clearAndRenderDotSource('digraph {Alice -> Bob}');
106+
107+
cy.node(1).should('exist');
108+
cy.node(2).should('exist');
109+
cy.edge(1).should('exist');
110+
111+
cy.node(1).shouldHaveName('Alice');
112+
cy.node(2).shouldHaveName('Bob');
113+
cy.edge(1).shouldHaveName('Alice->Bob');
114+
115+
cy.nodes().should('have.length', 2);
116+
cy.edges().should('have.length', 1);
117+
118+
cy.textEditorWrapper().should('be.visible');
119+
cy.toolbar().should('exist');
120+
cy.canvas().invoke('width').should('be.lt', viewportWidth / 2)
121+
122+
cy.canvas().click();
123+
cy.get('body').type('f');
124+
125+
cy.textEditorWrapper().should('not.be.visible');
126+
cy.toolbar().should('not.exist');
127+
cy.canvas().invoke('width').should('be.eq', viewportWidth)
128+
129+
cy.fullscreenButton().click();
130+
131+
cy.textEditorWrapper().should('be.visible');
132+
cy.toolbar().should('exist');
133+
cy.canvas().invoke('width').should('be.lt', viewportWidth / 2)
134+
135+
cy.get('body').type('f');
136+
137+
cy.textEditorWrapper().should('not.be.visible');
138+
cy.toolbar().should('not.exist');
139+
cy.canvas().invoke('width').should('be.eq', viewportWidth)
140+
});
69141
});

src/pages/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,10 @@ class Index extends React.Component {
686686
}
687687

688688
handleToggleFullscreen = () => {
689+
// return focus to the document body. This remove focus from the fullscreen
690+
// icon button and allows keyboard shortcuts in the graph to continue to
691+
// work.
692+
document.activeElement.blur();
689693
this.setState((state) => ({
690694
fullscreen: !state.fullscreen,
691695
}));

0 commit comments

Comments
 (0)