The GenerateBlocks 2.0 release introduced a completely rebuilt tabs block, along with updates to all other blocks. While the new features are powerful, there are a few nuances that can trip you up if you’re not careful. I spent about an hour troubleshooting some issues with the tabs block, and I wanted to share my findings to save you time and frustration.
Everything you need to do is still possible, but there are a couple of key areas where you need to pay close attention. In this guide, I’ll walk you through the process of setting up tabs in GenerateBlocks 2.0, highlighting the potential pitfalls and how to avoid them.
Adding a Tabs Block: Options and Structure
When you add a tabs block in GenerateBlocks, you’ll see three layout options: horizontal tabs, vertical tabs, and button tabs. Personally, I’ve had the most success with button tabs, so that’s what I’ll focus on here.
Once you add a tabs block, the structure looks like this:
- Tabs Block: The main wrapper.
- Tabs Menu: Contains the menu items (buttons).
- Tabs Items: Contains the content for each tab.
Inside the Tabs Menu, you’ll find individual menu items, and inside the Tabs Items, you’ll find corresponding tab items. By default, these tab items contain a core paragraph block and a GenerateBlocks headline block, which control the label and content for each tab.
Styling the Tab Buttons
One of the first things you’ll notice is that the tab buttons don’t share styles by default. If you change the padding or spacing on one button, it won’t apply to the others. To fix this, you need to add a shared class to the tab buttons.
Steps to Style Tab Buttons Globally:
- Add a Class to the Tab Menu Item: Select the tab menu item (not the text block inside it) and add a class, such as
tab-button
. - Move Local Styles to the Class: When creating the class, move all local block styles (including hover and active styles) to the new class.
- Apply the Class to All Buttons: Go through each tab menu item and remove the local block styles, then apply the shared class.
Now, any changes you make to the tab-button
class will apply to all tab buttons. For example, if you set the padding to 80 pixels, it will affect every button uniformly.
Avoiding Issues with Tab Items
The tab items are where I ran into the most trouble. By default, GenerateBlocks uses classes to show and hide the content for each tab. If you change the display property of a tab item (e.g., to grid
), it overrides the default behavior, and all tab content becomes visible at once. This is definitely not what you want.
Correct Way to Style Tab Items:
- Don’t Change the Display Property of Tab Items: Leave the default display settings intact.
- Use a Container Inside the Tab Item: If you need a specific layout (e.g., a two-column grid), add a container inside the tab item and apply your styles to that container.
For example, if you want a two-column layout:
- Add a container inside the tab item.
- Apply a class to the container (e.g.,
tab-item-grid
). - Set the container’s display property to
grid
and define your grid template columns.
This approach ensures the tabs function correctly while allowing you to customize the layout inside each tab.
Adding New Tabs
When you add new tabs using the “Add Tab Item” button, GenerateBlocks automatically copies the structure and styles from the existing tabs. This is helpful if you want all tabs to have the same layout and styling. Simply update the content for each new tab, and you’re good to go.
Key Takeaways
Here are the two main points to remember when working with tabs in GenerateBlocks 2.0:
- Style Tab Buttons with a Shared Class: Add a class to the tab menu items and move all local styles to that class. This allows you to control all buttons globally without duplicating effort.
- Don’t Change the Display Property of Tab Items: If you need a custom layout, use a container inside the tab item and style that instead. Avoid touching the display property of the tab items themselves.
By following these guidelines, you can avoid the common pitfalls and set up tabs that work seamlessly.
Wrapping Up
The tabs block in GenerateBlocks 2.0 is a powerful tool, but it does require a bit of care to use effectively. If you follow the steps outlined here, you’ll save yourself time and frustration while creating clean, functional layouts.
Hopefully, this guide helps you navigate the quirks of the tabs block and get the most out of GenerateBlocks 2.0. Happy building!