Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
fbfa318
Initial commit
sethrubenstein Mar 30, 2025
d26e8b7
Moving back to a manually constructed list in the parent block
sethrubenstein Mar 30, 2025
6c020e0
Moving more toward iAPI for easier use
sethrubenstein Apr 1, 2025
d60a969
Moving more toward iAPI for easier use
sethrubenstein Apr 1, 2025
2f30c9d
Some final cleanup before submitting pr
sethrubenstein Apr 1, 2025
47c2063
Fixes php linting errors and forgot to hook on style functions for co…
sethrubenstein Apr 1, 2025
a9df24d
Adding fixtures/tests updating block library version number
sethrubenstein Apr 1, 2025
2836077
Why is PHPCS reporting this as misformatted??
sethrubenstein Apr 1, 2025
cf93391
Whoops mis-replaced this file
sethrubenstein Apr 1, 2025
fed61c1
iAPI bug fix, merge artifact - ensuring dynamic styles generation wor…
sethrubenstein Apr 1, 2025
fa90dbe
iAPI bug fix, merge artifact - ensuring dynamic styles generation wor…
sethrubenstein Apr 1, 2025
329f3a2
Fixing failed tabs fixtures and removing old readme files from prc-bl…
sethrubenstein Apr 1, 2025
2ebfd35
PHPCS linting
sethrubenstein Apr 1, 2025
863f737
I was really overthinking that, untill I was up late overthinking it.
sethrubenstein Apr 2, 2025
88df184
Accessibility improvements and cleanup
sethrubenstein Apr 2, 2025
8b21aee
Regen tabs fixtures
sethrubenstein Apr 2, 2025
759836b
Cool, that slotfill key scoping solution from @Mamaduka works
sethrubenstein Apr 9, 2025
9045eec
Moving tabs icons into icon library proper as requested by @Infinite-…
sethrubenstein Apr 9, 2025
3d69321
Some updates for better keyboard handler support
sethrubenstein Apr 14, 2025
598981a
#34079 Fixing accesibility on frontend tab render
sethrubenstein Apr 23, 2025
b38e279
Refactor tabs, pulling the latest out of prc-block-library/tabs for G…
sethrubenstein Sep 10, 2025
ef1eaaf
Update included context to match core block library pattern
sethrubenstein Sep 10, 2025
6832705
Making tabs & tab blocks experimental
sethrubenstein Sep 22, 2025
cee89d3
Merge branch 'trunk' into core/tabs
sethrubenstein Sep 22, 2025
9816923
Fix tabs experimental placement
sethrubenstein Sep 22, 2025
9684714
Pull custom event. Per work on core/dialog
sethrubenstein Sep 22, 2025
b60598b
Resolving comments in review
sethrubenstein Sep 25, 2025
779349c
Moving to requestAnimationFrame and cancelAnimationFrame for cleaning…
sethrubenstein Sep 25, 2025
b08e10b
alphabetical order
sethrubenstein Sep 25, 2025
4e45b8c
alphabetical order
sethrubenstein Sep 25, 2025
be1830a
Merge branch 'trunk' into core/tabs
sethrubenstein Sep 25, 2025
1402c06
Refactor color styles function to remove unnecessary parameter
sethrubenstein Sep 25, 2025
0017090
Merge branch 'core/tabs' of github.com:pewresearch/gutenberg into cor…
sethrubenstein Sep 25, 2025
9e734b9
List order
sethrubenstein Sep 25, 2025
d166b86
list order
sethrubenstein Sep 25, 2025
98a3c55
Order
sethrubenstein Sep 25, 2025
040fb5e
Order
sethrubenstein Sep 25, 2025
0e596b5
Updates:
sethrubenstein Oct 23, 2025
bbf0700
Updates
sethrubenstein Oct 23, 2025
ea2322e
Updated to private store method that we implemented in core/dialog
sethrubenstein Oct 23, 2025
907bf94
Fix initial mount of tabs and focusing on first tab richtext
sethrubenstein Oct 23, 2025
62eb812
Cleanup
sethrubenstein Oct 23, 2025
0510796
Cleanup
sethrubenstein Oct 23, 2025
76c06bb
Remove tests for now
sethrubenstein Oct 23, 2025
79e09d9
Cleanup
sethrubenstein Oct 23, 2025
684d6bd
Cleanup for coding standards
sethrubenstein Oct 23, 2025
1406cd3
Move away from slotfill, can restore if desired.
sethrubenstein Oct 23, 2025
8b36b2f
Replaced dynamic tab label with sprintf, replaced hard coded formats …
sethrubenstein Oct 24, 2025
3e8e4f5
Make markup render correctly when not focused in tabslist
sethrubenstein Oct 24, 2025
c4973ad
Add StaticLabel component to TabsList for improved tab label rendering
sethrubenstein Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 20 additions & 52 deletions packages/block-library/src/tab/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
getTypographyClassesAndStyles as useTypographyProps,
__experimentalUseColorProps as useColorProps,
store as blockEditorStore,
RichText,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import {
Expand All @@ -23,13 +22,12 @@ import {
useCallback,
useState,
} from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import { TabFill, TabsListSlot } from './slotfill';
import Controls from './controls';
import slugFromLabel from './slug-from-label';
import TabsList from './tabs-list';

const TEMPLATE = [
[
Expand Down Expand Up @@ -107,6 +105,7 @@ export default function Edit( {
forceDisplay,
isTabsClientSelected,
isDefaultTab,
siblingTabs,
} = useSelect(
( select ) => {
const {
Expand All @@ -115,6 +114,7 @@ export default function Edit( {
isBlockSelected,
hasSelectedInnerBlock,
getBlockAttributes,
getBlocks,
} = select( blockEditorStore );

// Get data from core/tabs.
Expand All @@ -132,6 +132,9 @@ export default function Edit( {
true
);

// Get all sibling tabs from parent.
const _siblingTabs = getBlocks( rootClientId );

return {
blockIndex: _blockIndex,
hasInnerBlocksSelected: _hasInnerBlocksSelected,
Expand All @@ -141,6 +144,7 @@ export default function Edit( {
isTabsClientSelected: _isTabsClientSelected,
isDefaultTab: _isDefaultTab,
tabsAttributes: rootAttributes,
siblingTabs: _siblingTabs,
};
},
[ clientId ]
Expand Down Expand Up @@ -216,61 +220,25 @@ export default function Edit( {
blockIndex={ blockIndex }
isDefaultTab={ isDefaultTab }
/>
<TabFill tabsClientId={ tabsClientId }>
<button
aria-controls={ tabPanelId }
aria-selected={ isSelectedTab }
id={ tabLabelId }
role="tab"
className={ clsx(
'tabs__tab-label',
tabItemColorProps.className
) }
style={ {
...tabItemColorProps.style,
} }
tabIndex={ -1 }
onClick={ ( event ) => {
event.preventDefault();
selectBlock( clientId );
} }
onKeyDown={ ( event ) => {
// If shift is also pressed, do not select the block.
if ( event.key === 'Enter' && ! event.shiftKey ) {
event.preventDefault();
selectBlock( clientId );
focusRef.current = requestAnimationFrame(
() => {
labelElementRef.current?.focus();
}
);
}
} }
>
<RichText
ref={ labelRef }
tagName="span"
allowedFormats={ [
'core/bold',
'core/italic',
'core/strikethrough',
] }
placeholder={
__( 'Tab' ) + ` ${ blockIndex + 1 }…`
}
value={ decodeEntities( label ) }
onChange={ ( value ) =>
{ isSelectedTab && (
<>
<TabsList
siblingTabs={ siblingTabs }
currentClientId={ clientId }
currentBlockIndex={ blockIndex }
currentLabel={ label }
tabItemColorProps={ tabItemColorProps }
onSelectTab={ selectBlock }
onLabelChange={ ( value ) =>
setAttributes( {
label: value,
anchor: slugFromLabel( value, blockIndex ),
} )
}
labelRef={ labelRef }
focusRef={ focusRef }
labelElementRef={ labelElementRef }
/>
</button>
</TabFill>
{ isSelectedTab && (
<>
<TabsListSlot tabsClientId={ tabsClientId } />
<section { ...innerBlocksProps } />
</>
) }
Expand Down
29 changes: 0 additions & 29 deletions packages/block-library/src/tab/slotfill.js

This file was deleted.

104 changes: 104 additions & 0 deletions packages/block-library/src/tab/tabs-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { RichText } from '@wordpress/block-editor';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import slugFromLabel from './slug-from-label';

export default function TabsList( {
siblingTabs,
currentClientId,
currentBlockIndex,
currentLabel,
tabItemColorProps,
onSelectTab,
onLabelChange,
labelRef,
focusRef,
labelElementRef,
} ) {
return (
<div role="tablist" className="tabs__list">
{ siblingTabs.map( ( tab, index ) => {
const isCurrentTab = tab.clientId === currentClientId;
const isSiblingTabActive = index === currentBlockIndex;
const tabAttributes = tab.attributes || {};
const siblingLabel = tabAttributes.label || '';
const siblingAnchor =
tabAttributes.anchor ||
slugFromLabel( siblingLabel, index );
const siblingTabPanelId = siblingAnchor;
const siblingTabLabelId = `${ siblingTabPanelId }--tab`;

return (
<button
key={ tab.clientId }
aria-controls={ siblingTabPanelId }
aria-selected={ isSiblingTabActive }
id={ siblingTabLabelId }
role="tab"
className={ clsx(
'tabs__tab-label',
tabItemColorProps.className
) }
style={ {
...tabItemColorProps.style,
} }
tabIndex={ isSiblingTabActive ? 0 : -1 }
onClick={ ( event ) => {
event.preventDefault();
onSelectTab( tab.clientId );
} }
onKeyDown={ ( event ) => {
// If shift is also pressed, do not select the block.
if ( event.key === 'Enter' && ! event.shiftKey ) {
event.preventDefault();
onSelectTab( tab.clientId );
if ( isCurrentTab ) {
const { requestAnimationFrame } = window;
focusRef.current = requestAnimationFrame(
() => {
labelElementRef.current?.focus();
}
);
}
}
} }
>
{ isCurrentTab ? (
<RichText
ref={ labelRef }
tagName="span"
allowedFormats={ [
'core/bold',
'core/italic',
'core/strikethrough',
] }
placeholder={
__( 'Tab' ) + ` ${ currentBlockIndex + 1 }…`
}
value={ decodeEntities( currentLabel ) }
onChange={ onLabelChange }
/>
) : (
<span>
{ decodeEntities( siblingLabel ) ||
__( 'Tab' ) + ` ${ index + 1 }` }
</span>
) }
</button>
);
} ) }
</div>
);
}
9 changes: 9 additions & 0 deletions packages/block-library/src/tabs/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import {
__experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import AddTabToolbarControl from '../tab/add-tab-toolbar-control';

function ContrastCheckerMatrix( { attributes } ) {
const {
className,
Expand Down Expand Up @@ -134,6 +139,10 @@ export default function Controls( {

return (
<>
<AddTabToolbarControl
tabsClientId={ clientId }
attributes={ attributes }
/>
<InspectorControls>
<PanelBody title={ __( 'Tabs Settings' ) }>
<ToggleControl
Expand Down
9 changes: 1 addition & 8 deletions packages/block-library/src/tabs/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import clsx from 'clsx';
import {
useBlockProps,
useInnerBlocksProps,
InnerBlocks,
withColors,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { TabFill } from '../tab/slotfill';
import StyleEngine from './style-engine';
import Controls from './controls';

Expand Down Expand Up @@ -68,18 +66,13 @@ function Edit( {
clientId,
orientation,
template: TABS_TEMPLATE,
renderAppender: false, // We handle this via a slotfill.
renderAppender: false, // Appender is rendered by individual tab blocks.
} );

return (
<>
<div { ...innerBlockProps }>
{ innerBlockProps.children }
<TabFill tabsClientId={ clientId }>
<div className="wp-block-tabs__tab-item__inserter">
<InnerBlocks.ButtonBlockAppender />
</div>
</TabFill>
<StyleEngine attributes={ attributes } clientId={ clientId } />
<Controls
{ ...{
Expand Down
Loading