Skip to content

Commit

Permalink
#2912 reproduce bug
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlaStarla authored and Nitvex committed Aug 9, 2023
1 parent 733c9b5 commit d669bfb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 34 deletions.
4 changes: 3 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"normalize.css": "^8.0.1",
"react": "^18.2.0",
"react-app-polyfill": "^2.0.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-modal": "^3.16.1"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.2",
Expand All @@ -53,6 +54,7 @@
"@types/node": "^16.11.12",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"@types/react-modal": "^3.16.0",
"@vitejs/plugin-react": "^4.0.0",
"@welldone-software/why-did-you-render": "^4.3.1",
"cross-env": "^7.0.3",
Expand Down
74 changes: 42 additions & 32 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
StructServiceProvider,
} from 'ketcher-core';
import { PolymerToggler } from './PolymerToggler';
import Modal from 'react-modal';

const getHiddenButtonsConfig = (): ButtonsConfig => {
const searchParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -48,47 +49,56 @@ const App = () => {
const hiddenButtonsConfig = getHiddenButtonsConfig();
const [hasError, setHasError] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [isOpen, setIsOpen] = useState(false);
const [showPolymerEditor, setShowPolymerEditor] = useState(false);

Modal.setAppElement('#root');
return showPolymerEditor ? (
<>
<PolymerEditor />
<PolymerToggler toggle={setShowPolymerEditor} />
</>
) : (
<>
<Editor
errorHandler={(message: string) => {
setHasError(true);
setErrorMessage(message.toString());
}}
buttons={hiddenButtonsConfig}
staticResourcesUrl={process.env.PUBLIC_URL}
structServiceProvider={structServiceProvider}
onInit={(ketcher: Ketcher) => {
window.ketcher = ketcher;
window.parent.postMessage(
{
eventType: 'init',
},
'*',
);
}}
/>
{enablePolymerEditor && <PolymerToggler toggle={setShowPolymerEditor} />}
{hasError && (
<InfoModal
message={errorMessage}
close={() => {
setHasError(false);
<button onClick={() => setIsOpen(true)}>open</button>
<Modal isOpen={isOpen}>
<div>
<button onClick={() => setIsOpen(false)}>close</button>
<Editor
errorHandler={(message: string) => {
setHasError(true);
setErrorMessage(message.toString());
}}
buttons={hiddenButtonsConfig}
staticResourcesUrl={process.env.PUBLIC_URL}
structServiceProvider={structServiceProvider}
onInit={(ketcher: Ketcher) => {
window.ketcher = ketcher;
window.parent.postMessage(
{
eventType: 'init',
},
'*',
);
}}
/>
{enablePolymerEditor && (
<PolymerToggler toggle={setShowPolymerEditor} />
)}
{hasError && (
<InfoModal
message={errorMessage}
close={() => {
setHasError(false);

// Focus on editor after modal is closed
const cliparea: HTMLElement | null =
document.querySelector('.cliparea');
cliparea?.focus();
}}
/>
)}
// Focus on editor after modal is closed
const cliparea: HTMLElement | null =
document.querySelector('.cliparea');
cliparea?.focus();
}}
/>
)}
</div>
</Modal>
</>
);
};
Expand Down
44 changes: 43 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d669bfb

Please sign in to comment.