Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue #2495 #2664

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- `Fix` - Unexpected new line on Enter press with selected block without caret
- `Fix` - Search input autofocus loosing after Block Tunes opening
- `Fix` - Block removing while Enter press on Block Tunes
- `Fix` - Render the placeholder only if defined.
- `Fix` - Do not add empty block in readonly mode.

### 2.29.1

Expand Down
2 changes: 1 addition & 1 deletion src/components/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class Core {
* Initialize default Block to pass data to the Renderer
*/
if (_.isEmpty(this.config.data) || !this.config.data.blocks || this.config.data.blocks.length === 0) {
this.config.data = { blocks: [ defaultBlockData ] };
this.config.data = { blocks: this.config.placeholder ? [ defaultBlockData ] : [] };
}

this.config.readOnly = this.config.readOnly as boolean || false;
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default class Renderer extends Module {
return new Promise((resolve) => {
const { Tools, BlockManager } = this.Editor;

if (blocksData.length === 0) {
BlockManager.insert();
if (blocksData.length === 0 && this.config.readOnly === false) {
BlockManager.insert();
} else {
/**
* Create Blocks instances
Expand Down
4 changes: 4 additions & 0 deletions test/cypress/tests/initialization.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ describe('Editor basic initialization', () => {
});

it('should create editor without editing ability when true passed', () => {
/**
* Create readonly editor with a placeholder, to create a readonly paragraph block
*/
cy.createEditor({
readOnly: true,
placeholder: "readonly-test"
}).as('editorInstance');

cy.get('[data-cy=editorjs]')
Expand Down