Skip to content

Commit

Permalink
don't move toolbar by block-hover on mobile
Browse files Browse the repository at this point in the history
Resolves #1972
  • Loading branch information
neSpecc committed Mar 25, 2022
1 parent a9a06eb commit f9ae64c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ export default class Toolbar extends Module<ToolbarNodes> {
* Subscribe to the 'block-hovered' event
*/
this.eventsDispatcher.on(this.Editor.UI.events.blockHovered, (data: {block: Block}) => {
/**
* Do not move Toolbar by hover on mobile view
* @see https://github.com/codex-team/editor.js/issues/1972
*/
if (_.isMobile()) {
return;
}

/**
* Do not move toolbar if Block Settings or Toolbox opened
*/
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class Toolbox extends EventsDispatcher<ToolboxEvent> {
this.close();
});

if (_.isMobile) {
if (_.isMobile()) {
this.listeners.on(document, 'scroll', () => {
this.close();
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,4 +766,6 @@ export function cacheable<Target, Value, Arguments extends unknown[] = unknown[]
/**
* True if screen has mobile size
*/
export const isMobile = window.matchMedia('(max-width: 650px)').matches;
export function isMobile(): boolean {
return window.matchMedia('(max-width: 650px)').matches;
}

0 comments on commit f9ae64c

Please sign in to comment.