Skip to content

Commit

Permalink
fix(readonly): toggle remounting (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz authored May 2, 2022
1 parent 843198f commit b4162bc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cypress/integration/Issues.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe("Issue", () => {
it("toggles read-only mode (#454)", () => {
cy.viewport(600, 1000).visit(
`/iframe.html?id=bug-reports-issues--issue-454`
);

// 1. it's editable
cy.get(".cm-content").should("have.attr", "contenteditable", "true");

// 2. click on button and set read-only as true
cy.get(".trigger").click();

// 3. it's not editable
cy.get(".cm-content").should("have.attr", "contenteditable", "false");

// 4. make sure the editor is mount
cy.get(".cm-editor").should("exist");
cy.get(".pre-placeholder").should("not.exist");
});
});
24 changes: 24 additions & 0 deletions sandpack-react/src/Issues.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useState } from "react";

import { Sandpack } from "./";

export default {
title: "Bug reports/Issues",
};

export const Issue454 = (): JSX.Element => {
const [readOnly, setReadOnly] = useState(false);

return (
<>
<button
className="trigger"
onClick={(): any => setReadOnly((prev) => !prev)}
>
click
</button>
<Sandpack options={{ readOnly }} />
</>
);
};
1 change: 1 addition & 0 deletions sandpack-react/src/components/CodeEditor/CodeMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export const CodeMirror = React.forwardRef<CodeMirrorRef, CodeMirrorProps>(
wrapContent,
themeId,
sortedDecorators,
readOnly,
]);

React.useEffect(() => {
Expand Down

0 comments on commit b4162bc

Please sign in to comment.