Skip to content

Commit

Permalink
feat: disable scroll when inspect on mobile (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjxxxxxxxxx authored Oct 15, 2023
1 parent 7b4f5d3 commit 54cab16
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-eagles-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@open-editor/client': minor
---

disable scroll when inspect on mobile
6 changes: 3 additions & 3 deletions packages/client/src/elements/defineInspectElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const CSS = postcss`
font-family: Menlo, Monaco, 'Courier New', monospace;
line-height: 1.5;
font-weight: 400;
cursor: default !important;
user-select: none !important;
-webkit-touch-callout: none !important;
cursor: default;
user-select: none;
-webkit-touch-callout: none;
}
:host {
all: initial !important;
Expand Down
11 changes: 11 additions & 0 deletions packages/client/src/elements/defineOverlayElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
off,
} from '../utils/document';
import { create_RAF } from '../utils/createRAF';
import { createStyleInject } from '../utils/createStyleInject';
import { InternalElements, captureOpts } from '../constants';
import type { HTMLTooltipElement } from './defineTooltipElement';

Expand Down Expand Up @@ -46,7 +47,15 @@ const CSS = postcss`
}
`;

const touchLockCSS = postcss`
html {
touch-action: none !important;
}
`;

export function defineOverlayElement() {
const touchLockStyle = createStyleInject(touchLockCSS);

class OverlayElement extends HTMLElement implements HTMLOverlayElement {
private tooltip: HTMLTooltipElement;

Expand Down Expand Up @@ -91,6 +100,7 @@ export function defineOverlayElement() {
}

open = () => {
touchLockStyle.insert();
applyStyle(this.posttion, {
display: 'block',
});
Expand All @@ -100,6 +110,7 @@ export function defineOverlayElement() {
};

close = () => {
touchLockStyle.remove();
applyStyle(this.posttion, {
display: 'none',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/elements/defineTreeElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const CSS = postcss`
`;

const scrollLockCSS = postcss`
body {
html {
overflow: hidden !important;
}
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/utils/safeArea.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createStyleGetter } from './createStyleGetter';
import { createStyleInject } from './createStyleInject';

const CSS = `
const CSS = postcss`
:root {
--sait: env(safe-area-inset-top);
--sair: env(safe-area-inset-right);
Expand Down

0 comments on commit 54cab16

Please sign in to comment.