Skip to content

Commit 8a21399

Browse files
Fix jumpy page on highlighting due to scrollbar (#49)
Fix jumpy page on highlighting due to scrollbar
2 parents 3230a08 + be24787 commit 8a21399

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed

src/adapter/adapter/highlight.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Renderer } from "../renderer";
22
import { render, h } from "preact";
33
import { getNearestElement, measureNode } from "../dom";
44
import { ID } from "../../view/store/types";
5-
import { Highlighter } from "../../view/components/Highlighter";
5+
import { Highlighter, style } from "../../view/components/Highlighter";
66

77
/**
88
* This module is responsible for displaying the transparent element overlay
@@ -35,7 +35,7 @@ export function createHightlighter(renderer: Renderer) {
3535
if (highlightRef == null) {
3636
highlightRef = document.createElement("div");
3737
highlightRef.id = "preact-devtools-highlighter";
38-
highlightRef.className = "foobar";
38+
highlightRef.className = style.outerContainer;
3939

4040
document.body.appendChild(highlightRef);
4141
}

src/examples/10/Highlighting.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { h } from "../vendor/preact-10";
2+
3+
function Inner() {
4+
return (
5+
<div
6+
style={`
7+
background: #aaa;
8+
width: 100vh;
9+
position: absolute;
10+
left: 0;
11+
top: 0;
12+
height: 15rem;
13+
`}
14+
>
15+
full width
16+
</div>
17+
);
18+
}
19+
20+
export function FullWidthHighlighter() {
21+
return (
22+
<div style="padding-top: 20rem">
23+
<Inner />
24+
</div>
25+
);
26+
}

src/examples/10/setup.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Stateful } from "./state";
77
import { createRenderer } from "../../adapter/10/renderer";
88
import { setupOptions } from "../../adapter/10/options";
99
import { Booleans, Complex } from "./DataTypes";
10+
import { FullWidthHighlighter } from "./Highlighting";
1011

1112
export function initPreact10(hook: DevtoolsHook) {
1213
if (hook.attachPreact) {
@@ -27,18 +28,25 @@ export function initPreact10(hook: DevtoolsHook) {
2728
export function renderExamples10(node: HTMLElement) {
2829
render(
2930
<div>
30-
<p>Todo list</p>
31-
<TodoList />
32-
<p>Legacy context</p>
33-
<LegacyContext />
34-
<p>Class state</p>
35-
<Stateful />
36-
<p>Data Types</p>
37-
<Booleans value={true} />
38-
<Complex />
39-
<p>Deep tree</p>
40-
<DeepTree />
41-
<br />
31+
{/* <FullWidthHighlighter /> */}
32+
<div style="padding: 2rem">
33+
<p>Highlight full width</p>
34+
<small>
35+
Uncomment all other components so that the vertical scrollbar is gone
36+
</small>
37+
<p>Todo list</p>
38+
<TodoList />
39+
<p>Legacy context</p>
40+
<LegacyContext />
41+
<p>Class state</p>
42+
<Stateful />
43+
<p>Data Types</p>
44+
<Booleans value={true} />
45+
<Complex />
46+
<p>Deep tree</p>
47+
<DeepTree />
48+
<br />
49+
</div>
4250
</div>,
4351
node,
4452
);

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ wrapper.style.cssText = `
4141
`;
4242
const container = div("container");
4343
container.style.cssText = `
44-
padding: 2rem;
4544
overflow: auto;
4645
`;
4746

4847
const examples10 = div("preact-10");
48+
examples10.style.cssText = "position: relative";
4949
document.body.appendChild(wrapper);
5050
wrapper.appendChild(container);
5151
wrapper.appendChild(devtools);

src/view/components/Highlighter.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@
7272
.fixed.fixedBottom {
7373
bottom: 1.5em;
7474
}
75+
76+
.outerContainer {
77+
position: absolute;
78+
top: 0;
79+
left: 0;
80+
right: 0;
81+
bottom: 0;
82+
overflow: hidden;
83+
}

src/view/components/Highlighter.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { h } from "preact";
22
import s from "./Highlighter.css";
33
import { Measurements } from "../../adapter/dom";
44

5+
export const style = s;
6+
57
export interface Props extends Measurements {
68
label: string;
79
}

0 commit comments

Comments
 (0)