Skip to content

Commit

Permalink
Fix movable blocks when editor is readOnly (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard authored Apr 14, 2020
1 parent d5023de commit 1055019
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/components/MegadraftEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,20 @@ export default class MegadraftEditor extends Component {
for (let [blockType, data] of DefaultDraftBlockRenderMap.entrySeq()) {
r.set(blockType, {
...data,
wrapper: this.props.movableBlocks ? (
<MoveControl
wrapper={data.wrapper}
swapUp={this.swapUp}
swapDown={this.swapDown}
isFirstBlock={this.isFirstBlock}
isLastBlock={this.isLastBlock}
onAction={this.onAction}
isAtomic={blockType === "atomic"}
/>
) : (
<MegadraftBlock wrapper={data.wrapper} />
)
wrapper:
!this.props.readOnly && this.props.movableBlocks ? (
<MoveControl
wrapper={data.wrapper}
swapUp={this.swapUp}
swapDown={this.swapDown}
isFirstBlock={this.isFirstBlock}
isLastBlock={this.isLastBlock}
onAction={this.onAction}
isAtomic={blockType === "atomic"}
/>
) : (
<MegadraftBlock wrapper={data.wrapper} />
)
});
}
});
Expand Down
12 changes: 12 additions & 0 deletions tests/components/MegadraftEditor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,18 @@ describe("MegadraftEditor Component", () => {
);
};

it("should not render MoveControl when readOnly is present", () => {
const wrapper = mount(
<MegadraftEditor
editorState={testContext.editorState}
onChange={testContext.onChange}
readOnly
movableBlocks
/>
);
expect(wrapper.find(".move-control").exists()).toBeFalsy();
});

it("with the top block by clicking the up control", () => {
const expected = [
"block-kst0",
Expand Down

0 comments on commit 1055019

Please sign in to comment.