Skip to content

Commit 6a15cc5

Browse files
authored
fix(codex-team#2036): scrolling issue with block hovering (codex-team#2042)
* fix scrolling issue caused by the popover.hide() * Update popover.ts * Update CHANGELOG.md * upd codeowners * naming of isShown improved
1 parent 8ae8823 commit 6a15cc5

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
* @neSpecc @gohabereg @khaydarov
1+
* @neSpecc @gohabereg @TatianaFomina @ilyamore88
2+

docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
- `Fix` — Scrolling issue when opening toolbox on mobile fixed
66
- `Fix` — Typo in toolbox empty placeholder fixed
7+
- `Fix` — The issue with scroll jumping on block hovering have fixed [2036](https://github.com/codex-team/editor.js/issues/2036)
78
- `Improvement`*Dev Example Page* - Add popup example page
9+
- `Improvement`*UI* - The Toolbox will restore the internal scroll on every opening
810

911
### 2.24.1
1012

src/components/utils/popover.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export default class Popover extends EventsDispatcher<PopoverEvent> {
5858
*/
5959
private readonly items: PopoverItem[];
6060

61+
/**
62+
* Stores the visibility state.
63+
*/
64+
private isShown = false;
65+
6166
/**
6267
* Created nodes
6368
*/
@@ -190,6 +195,12 @@ export default class Popover extends EventsDispatcher<PopoverEvent> {
190195
* Shows the Popover
191196
*/
192197
public show(): void {
198+
/**
199+
* Clear search and items scrolling
200+
*/
201+
this.search.clear();
202+
this.nodes.items.scrollTop = 0;
203+
193204
this.nodes.popover.classList.add(Popover.CSS.popoverOpened);
194205
this.nodes.overlay.classList.remove(Popover.CSS.popoverOverlayHidden);
195206
this.flipper.activate();
@@ -203,20 +214,31 @@ export default class Popover extends EventsDispatcher<PopoverEvent> {
203214
if (isMobileScreen()) {
204215
this.scrollLocker.lock();
205216
}
217+
218+
this.isShown = true;
206219
}
207220

208221
/**
209222
* Hides the Popover
210223
*/
211224
public hide(): void {
212-
this.search.clear();
225+
/**
226+
* If it's already hidden, do nothing
227+
* to prevent extra DOM operations
228+
*/
229+
if (!this.isShown) {
230+
return;
231+
}
232+
213233
this.nodes.popover.classList.remove(Popover.CSS.popoverOpened);
214234
this.nodes.overlay.classList.add(Popover.CSS.popoverOverlayHidden);
215235
this.flipper.deactivate();
216236

217237
if (isMobileScreen()) {
218238
this.scrollLocker.unlock();
219239
}
240+
241+
this.isShown = false;
220242
}
221243

222244
/**

0 commit comments

Comments
 (0)