Skip to content

Conversation

@ldez
Copy link
Contributor

@ldez ldez commented Sep 2, 2025

The current way to set up the tabs does not seem straightforward.

This PR allows setting up the name on each tab instead of on the tab group.

This is non-breaking: the previous behavior is still supported.

To understand how it works, you should know two things:

  1. The parameters of a parent shortcode are available in child shortcodes. (This is like a constructor, from root to leaves)
  2. The child shortcodes are called/render before calling the parent shortcode (evaluation from leaves to root):
    • The child shortcodes can access the parameters and the Store of the parent.
    • But the first child will always get an empty Store from the parent, because the render of the parent is called after the render of all the children.
    • The children can fill the parents' Store, and the parents will get the child's values from their Store.
    • But a parent shortcode cannot define a default value inside the Store (because it will be called after the children).
    • It must try to get the value from the Store (filled by children) before defining the default value.

This approach is powerful, but it also has some limitations (ex, the parent shortcode should always call .Inner or .InnerDeindent, but it's possible to store the .Inner inside an unused variable)

I also added the possibility to enable/disable synchronized tabs per page.

Before
{{< tabs items="JSON,YAML,TOML" defaultIndex="1" >}}
  {{< tab >}}**JSON**: JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.{{< /tab >}}
  {{< tab >}}**YAML**: YAML is a human-readable data serialization language.{{< /tab >}}
  {{< tab >}}**TOML**: TOML aims to be a minimal configuration file format that's easy to read due to obvious semantics.{{< /tab >}}
{{< /tabs >}}
After
{{< tabs >}}
  {{< tab name="JSON" >}}**JSON**: JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.{{< /tab >}}
  {{< tab name="YAML" selected=true >}}**YAML**: YAML is a human-readable data serialization language.{{< /tab >}}
  {{< tab name="TOML" >}}**TOML**: TOML aims to be a minimal configuration file format that's easy to read due to obvious semantics.{{< /tab >}}
{{< /tabs >}}

Demo: https://deploy-preview-815--hugo-hextra.netlify.app/docs/guide/shortcodes/tabs/

@netlify
Copy link

netlify bot commented Sep 2, 2025

Deploy Preview for hugo-hextra ready!

Name Link
🔨 Latest commit 89bb40b
🔍 Latest deploy log https://app.netlify.com/projects/hugo-hextra/deploys/68c1f5c8d05a7000085bdff0
😎 Deploy Preview https://deploy-preview-815--hugo-hextra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ldez ldez force-pushed the feat/revamp-tabs branch 2 times, most recently from 551cfff to 900c4b5 Compare September 2, 2025 14:49
@ldez ldez changed the title feat: revamp tabs feat(tabs): revamp tabs Sep 2, 2025
@imfing
Copy link
Owner

imfing commented Sep 3, 2025

Thanks for the detailed explanation! I skimmed through it on my phone and the interface looks great and more intuitive.

I’ll take a closer look at the implementations later.

@imfing imfing added this to the v0.12.0 milestone Sep 3, 2025
@imfing imfing merged commit ccb63d6 into imfing:main Sep 10, 2025
4 checks passed
@ldez ldez deleted the feat/revamp-tabs branch September 10, 2025 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants