Skip to content

Commit 4b30de0

Browse files
committed
fix tab bug
Pressing tab focused an element in the panel, moving the viewport of the body element so the panel was in view. Because the body has hidden overflow, it's not possible to scroll back. The panel *appears* to be permanently open. The fix is to actually remove the panels from the render tree after hiding them, so they can't receive tab focus.
1 parent 5a405cf commit 4b30de0

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

Diff for: index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>Oh dear!</h1>
1818
>
1919
</canvas>
2020

21-
<div id="constant-force-panel" class="panel panel-closed">
21+
<div id="constant-force-panel" class="panel panel-closed hide">
2222
<div class="panel-header">
2323
<h2>Constant force</h2>
2424
<button type="button" class="delete">Delete</button>
@@ -36,7 +36,7 @@ <h2>Constant force</h2>
3636
<button class="close" type="button">Close</button>
3737
</div>
3838

39-
<div id="radial-force-panel" class="panel panel-closed">
39+
<div id="radial-force-panel" class="panel panel-closed hide">
4040
<div class="panel-header">
4141
<h2>Radial force</h2>
4242
<button type="button" class="delete">Delete</button>
@@ -50,7 +50,7 @@ <h2>Radial force</h2>
5050
<button class="close" type="button">Close</button>
5151
</div>
5252

53-
<div id="emitter-panel" class="panel panel-closed">
53+
<div id="emitter-panel" class="panel panel-closed hide">
5454
<div class="panel-header">
5555
<h2>Emitter</h2>
5656
<button type="button" class="delete">Delete</button>
@@ -104,4 +104,4 @@ <h2>Keyboard controls</h2>
104104

105105
<script src="js/main.js" type="module"></script>
106106
</body>
107-
</html>
107+
</html>

Diff for: js/animation.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function onTransitionEnd(el, fn) {
2+
if (!('ontransitionend' in el)) {
3+
fn();
4+
return;
5+
}
6+
const listener = function (event) {
7+
fn(event);
8+
el.removeEventListener(listener);
9+
};
10+
11+
el.addEventListener('transitionend', listener);
12+
}
13+
14+
export const rAF = requestAnimationFrame;

Diff for: js/panels.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import bindEvents from './bind-events.js';
2+
import { onTransitionEnd, rAF } from './animation.js';
23

34
function sensiblePrecision(number) {
45
number = Number(number);
@@ -60,7 +61,8 @@ class Panel {
6061
}
6162

6263
open(item) {
63-
this.el.classList.toggle('panel-closed', false);
64+
this.el.classList.remove('hide');
65+
rAF(() => this.el.classList.remove('panel-closed'));
6466
this.item = item;
6567
for (const setting of this.settings) {
6668
setting.inputEl.value = item[setting.attr];
@@ -69,7 +71,8 @@ class Panel {
6971
}
7072

7173
close() {
72-
this.el.classList.toggle('panel-closed', true);
74+
this.el.classList.add('panel-closed');
75+
onTransitionEnd(this.el, () => this.el.classList.add('hide'));
7376
this.item = null;
7477
}
7578

Diff for: style.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ button:hover {
147147
padding: .5em 1em;
148148
background-color: #c23;
149149
color: white;
150-
}
150+
}
151+
152+
.hide {
153+
display: none;
154+
}

0 commit comments

Comments
 (0)