Issue #3704✓ SolvedOpened August 13, 2021by throne19864 reactions

Load blocks closed by default?

Quick answerby artf4

That should be enough editor.Blocks.getCategories().forEach(ct => ct.set('open', false)) but categories are not created until the render of blocks (which happens, by default, when you click the Blocks tab) so you just need to execute that script once are rendered.

Read full answer below ↓

Question

I am using the following bit of code to collapse all the block categories, unfortunately, this is not working

const categories = editor.BlockManager.getCategories();
categories.each(category => {
	category.set('open', false).on('change:open', opened => {
		opened.get('open') && categories.each(category => {
            category !== opened && category.set('open', false)
        })
	})
})

live demo : https://jsfiddle.net/d4702yoh/2/

What is wrong here?

Answers (4)

👍 Most helpfulartfAugust 14, 2021

That should be enough editor.Blocks.getCategories().forEach(ct => ct.set('open', false)) but categories are not created until the render of blocks (which happens, by default, when you click the Blocks tab) so you just need to execute that script once are rendered.

ronaldohochAugust 13, 2021

Hello, i have made it to close all blocks in one plugin, try to adapt to you.:

throne1986August 14, 2021

still the same here jsfidle : https://jsfiddle.net/46mfqeht/

GJSBlockMay 17, 2026

Thanks for reporting this, @throne1986. Great question about load blocks closed by default?. The recommended approach with GrapesJS is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Most operations can be ac...

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.