Skip to content

Navigation with TabPanel  #45594

@tomalec

Description

@tomalec

What problem does this address?

What we have

Currently, the TabPanel component uses buttons, to manage dynamic tabbed content, without chaining the page (URL). This serves well for tiny widgets and toolboxes.

In many WooCommerce extensions, we would like to use the same UI element to navigate between pages and change URL.

So we would like to have an element, that looks the same, and behaves mostly the same, with a tiny difference it

  • has a role=navigation instead role=tabpanel and
  • changes the URL / uses <a href> instead of <button onClick>

The problem is TabPanel not only does not enable such a feature, it's also not extendable/composable enough to build such a feature on the top ourselves. (It gets a bit worse as we cannot even control/set the selected tab from the outside/as the consumers of the component: #27371, #45390)

What we're forced to do

Because of the above, we ended up introducing hacks & workarounds:

IMO, either workaround is fragile, bug-prone, and not sustainable. In one case, we waste a lot of effort to maintain a clone, test it, and eventually, it still may get diverged from the original impairing end-user experience.
On the other, we not only have to spend time to introduce this hack, but it may at any point, unexpectedly stop working, as we are not using public API, or desired use-case, but we're tempering with the details of its implementation, which are only a "manifestation" of its state.

What is your proposed solution?

I think it may be improved by different means.

Simplest for the consumers - new mode/component

The easiest for us - plugin/extension developers, would be to get a property to just change modes, like <TabPanel navigation=true>, or another component for such case - <TabNavigation>. But I guess it may be quite an effort to introduce and maintain a new API from @wordpress/components perspective.

Mid-way - make TabPanel extendable

This idea requires further design. But I imagine <tabPanel> could be redesigned (from a software perspective) or split into more composable parts. In a way, I as a consumer could configure or assemble what I need myself.

For example to have an element with just a visual layout and styles, then have an element that decorates a given element as "tab", then another high-level element that takes just JSON tabs setup and assembles it together. This way to achieve <NavigationTabPanel>, we would replace/extend only that high-level element.

Export styles

If @wordpress/components.TabPanel would expose just its styles. We, plugin developers, would still need to "redo" the <NavigationTabPanel>, but this time, we would be able to use exact same styles, reducing the risk of inconsistent look & feel for end customers.

It could be exported as Constructible StyleSheet, plain text, CSS Module, or whatever is usable.


I'm open for any other solution to this problem, or a path to actually use TabPanel for navigation.
//cc @ciampo

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions