-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
New block/tabs #69256
base: trunk
Are you sure you want to change the base?
New block/tabs #69256
Conversation
…finements in the editor interface and overall cleanup.
…ion/element-grouping. Will come back in later this week to add key handlers
…tore for remembering the last active tab when i get back from vacation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
*/ | ||
get isActiveTab() { | ||
const context = getContext(); | ||
const { attributes } = getElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Now that I think about it, there’s really no reason to not give each tab iAPI context with its index value instead of relying on getElement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is fine. The only advantage of using context is that the child elements of the element in question can also access the index/id, whereas with the element's attribute, you need to know if you are in the element or in one of the children.
// using context in both the element and their children
get isActiveTab() {
const { activeTabIndex, tabIndex } = getContext();
return activeTabIndex === tabIndex;
}
// using an attribute, scoped to the element
get isActiveTab() {
const { activeTabIndex } = getContext();
const { attributes } = getElement();
return activeTabIndex === attributes['data-tab-index'];
}
// using an attribute, scoped to a child of the element
get isActiveTab() {
const { activeTabIndex } = getContext();
const { ref } = getElement();
return activeTabIndex === ref?.closest('[data-tab-index]').dataset.tabIndex;
}
// or joining both
get isActiveTab() {
const { activeTabIndex } = getContext();
const { ref, attributes } = getElement();
const tabIndex = attributes['data-tab-index'] || ref?.closest('[data-tab-index]').dataset.tabIndex
return activeTabIndex === tabIndex;
}
Remember also that ref
is null
during the first hydration (same as in React/Preact), so it usually causes problems for this type of case.
Added controls for setting the default starting tab index. The attribute for this resides in core/tabs, but I'm surfacing the control in each tab so it can set it's own index as the attribute value in the parent. CleanShot.2025-02-20.at.09.17.47.mp4 |
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-prc-block-tabs.wp-block { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the prc slug should probably be removed.
Thank you for the amazing work! Looking forward for this new block! Some feedback:
|
What?
This is Pew Research Center's approach to Tabs in the block editor and would fulfill much of the needs requested in #34079.
Before getting started with testing, some additional work is needed that I'll be following up with in a few weeks but I wanted to get this PR started.
Additional tasks:
This builds upon work started by @creativecoder in #63689 and expands on making this concept even more extensible for developers.
The major changes from this original concept are the following:
core/tab
block will allow it to degrade more gracefully by enabling thecore/tabs
block to control all Interactivity API adoption. If acore/tab
block is displayed outside ofcore/tabs
, it should simply show the tab content without any issues or modifications.tab-hash
found in the tab to the URL as...?activeTabIndex=TXkgc2Vjb25kIHRhYl9fMQ==
will open the second tab, as demonstrated in the screencast below.core/paragraph
andcore/heading
block binding variations to display the block label within each tab.Why?
As the block editor and the concept of "full site editing" matures, I'm a strong believer that some basic ui concepts and paradigms should be available in the block library. Tabs is one such basic ui concept, dialog/modals are another.
How?
Testing Instructions
Testing Instructions for Keyboard
TK, working on keyboard handlers next.
Screenshots or screencast
In WP env:
CleanShot.2025-02-19.at.18.45.08.mp4
This is a screencast of the tabs block in action on the upcoming RLS site. Here you'll see Tabs that are generated dynamically on the server. The tab block is placed and styled in the editor, but it's individual tabs and contents are generated by logic on the server. Making Tabs as extensible as possible was our main goal:
CleanShot.2025-02-19.at.18.51.55.mp4