Skip to content

Commit dbc3ae0

Browse files
author
Maciej Warszawski
committed
force default pointer events when search enabled
1 parent 16a768e commit dbc3ae0

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

integration/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ namespace App {
106106
ReactDom.render(
107107
<App languages={['en', 'pl']}>
108108
<IntlNamespaceProvider namespace="App">
109-
<div style={{ margin: '20px' }}>
109+
<div style={{ margin: '20px', pointerEvents: 'none' }}>
110110
<Component1 />
111111
<FormattedMessage id="main-section" defaultMessage="App main section" />
112112
<div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body.searchEnabled * {
2+
pointer-events: auto !important;
3+
}

packages/react-intl-namespaces-locize-editor/src/Components/Editor.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ const options: Editor.RequiredProps = {
3333
};
3434
describe('Editor', () => {
3535
function createMocks() {
36+
const ClassListMock = jest.fn(() => ({
37+
add: jest.fn(),
38+
remove: jest.fn(),
39+
}));
40+
const classListMock = new ClassListMock();
41+
3642
const BodyMock = jest.fn<HTMLBodyElement>(() => ({
3743
addEventListener: jest.fn((type, listener) =>
3844
document.body.addEventListener(type, listener),
3945
),
4046
appendChild: jest.fn(newChild => document.body.appendChild(newChild)),
47+
classList: classListMock,
4148
removeChild: jest.fn(oldChild => document.body.removeChild(oldChild)),
4249
removeEventListener: jest.fn((type, ev, options) =>
4350
document.body.removeEventListener(type, ev, options),

packages/react-intl-namespaces-locize-editor/src/Components/Editor.tsx

+20-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { DOMHelpers } from '../DOMHelpers';
66
import { EditorPanel } from './EditorPanel';
77
import { EditorWindow } from './EditorWindow';
88

9+
import styles from './Editor.css';
10+
911
export class Editor extends React.Component<
1012
Editor.RequiredProps & Partial<Editor.OptionalProps>
1113
> {
@@ -18,13 +20,13 @@ export class EditorComponent extends React.Component<
1820
Editor.State
1921
> {
2022
private message: (ev: MessageEvent) => void;
21-
// prettier-ignore
23+
2224
private keypress: (ev: KeyboardEvent) => void;
23-
// prettier-ignore
25+
2426
private click: (e: MouseEvent) => void;
27+
2528
// prettier-ignore
2629
private postMessage!: Promise<EditorWindow.PostMessage>;
27-
// prettier-ignore
2830

2931
private editor: HTMLElement;
3032

@@ -53,6 +55,7 @@ export class EditorComponent extends React.Component<
5355
this.onToggleSearch();
5456
}
5557
};
58+
this.setSearchDomState(this.state.searchEnabled);
5659

5760
this.editor = DOMHelpers.Editor.createTargetElement(
5861
this.props.document,
@@ -101,8 +104,17 @@ export class EditorComponent extends React.Component<
101104
);
102105
}
103106
private onTogglePinned() {
104-
this.setState({ pinned: !this.state.pinned });
107+
const pinned = !this.state.pinned;
108+
this.setState({ pinned });
109+
}
110+
private setSearchDomState(searchEnabled: boolean) {
111+
DOMHelpers.Editor.toggleClass(
112+
this.props.document.body,
113+
searchEnabled,
114+
styles.searchEnabled,
115+
);
105116
}
117+
106118
private onShowIds() {
107119
const { showIds: oldShowIds, ...rest } = this.state;
108120
const showIds = !oldShowIds;
@@ -156,8 +168,10 @@ export class EditorComponent extends React.Component<
156168
}
157169

158170
private onToggleSearch() {
159-
const { searchEnabled } = this.state;
160-
this.setState({ searchEnabled: !searchEnabled });
171+
const searchEnabled = !this.state.searchEnabled;
172+
this.setState({ searchEnabled });
173+
174+
this.setSearchDomState(searchEnabled);
161175
}
162176
private onRefresh() {
163177
this.props.onRefresh();

packages/react-intl-namespaces-locize-editor/src/Components/__snapshots__/Editor.test.tsx.snap

+26
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ Object {
4747
],
4848
],
4949
},
50+
"classList": Object {
51+
"add": [MockFunction] {
52+
"calls": Array [
53+
Array [
54+
"searchEnabled",
55+
],
56+
],
57+
},
58+
"remove": [MockFunction] {
59+
"calls": Array [
60+
Array [
61+
"searchEnabled",
62+
],
63+
],
64+
},
65+
},
5066
"removeChild": [MockFunction] {
5167
"calls": Array [
5268
Array [
@@ -149,6 +165,16 @@ Object {
149165
],
150166
],
151167
},
168+
"classList": Object {
169+
"add": [MockFunction] {
170+
"calls": Array [
171+
Array [
172+
"searchEnabled",
173+
],
174+
],
175+
},
176+
"remove": [MockFunction],
177+
},
152178
"removeChild": [MockFunction] {
153179
"calls": Array [
154180
Array [

packages/react-intl-namespaces-locize-editor/src/DOMHelpers.ts

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ function delay(timeout: number = 0) {
66

77
export namespace DOMHelpers {
88
export namespace Editor {
9+
export function toggleClass(
10+
element: HTMLElement,
11+
state: boolean,
12+
cssClass: string,
13+
) {
14+
if (state) {
15+
element.classList.add(cssClass);
16+
} else {
17+
element.classList.remove(cssClass);
18+
}
19+
}
920
export function createTargetElement(document: Document, id: string) {
1021
let editor = document.getElementById(id);
1122
if (editor == null) {

0 commit comments

Comments
 (0)