-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New Block: core/tabs
#69789
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
Merged
Merged
New Block: core/tabs
#69789
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
fbfa318
Initial commit
sethrubenstein d26e8b7
Moving back to a manually constructed list in the parent block
sethrubenstein 6c020e0
Moving more toward iAPI for easier use
sethrubenstein d60a969
Moving more toward iAPI for easier use
sethrubenstein 2f30c9d
Some final cleanup before submitting pr
sethrubenstein 47c2063
Fixes php linting errors and forgot to hook on style functions for co…
sethrubenstein a9df24d
Adding fixtures/tests updating block library version number
sethrubenstein 2836077
Why is PHPCS reporting this as misformatted??
sethrubenstein cf93391
Whoops mis-replaced this file
sethrubenstein fed61c1
iAPI bug fix, merge artifact - ensuring dynamic styles generation wor…
sethrubenstein fa90dbe
iAPI bug fix, merge artifact - ensuring dynamic styles generation wor…
sethrubenstein 329f3a2
Fixing failed tabs fixtures and removing old readme files from prc-bl…
sethrubenstein 2ebfd35
PHPCS linting
sethrubenstein 863f737
I was really overthinking that, untill I was up late overthinking it.
sethrubenstein 88df184
Accessibility improvements and cleanup
sethrubenstein 8b21aee
Regen tabs fixtures
sethrubenstein 759836b
Cool, that slotfill key scoping solution from @Mamaduka works
sethrubenstein 9045eec
Moving tabs icons into icon library proper as requested by @Infinite-…
sethrubenstein 3d69321
Some updates for better keyboard handler support
sethrubenstein 598981a
#34079 Fixing accesibility on frontend tab render
sethrubenstein b38e279
Refactor tabs, pulling the latest out of prc-block-library/tabs for G…
sethrubenstein ef1eaaf
Update included context to match core block library pattern
sethrubenstein 6832705
Making tabs & tab blocks experimental
sethrubenstein cee89d3
Merge branch 'trunk' into core/tabs
sethrubenstein 9816923
Fix tabs experimental placement
sethrubenstein 9684714
Pull custom event. Per work on core/dialog
sethrubenstein b60598b
Resolving comments in review
sethrubenstein 779349c
Moving to requestAnimationFrame and cancelAnimationFrame for cleaning…
sethrubenstein b08e10b
alphabetical order
sethrubenstein 4e45b8c
alphabetical order
sethrubenstein be1830a
Merge branch 'trunk' into core/tabs
sethrubenstein 1402c06
Refactor color styles function to remove unnecessary parameter
sethrubenstein 0017090
Merge branch 'core/tabs' of github.com:pewresearch/gutenberg into cor…
sethrubenstein 9e734b9
List order
sethrubenstein d166b86
list order
sethrubenstein 98a3c55
Order
sethrubenstein 040fb5e
Order
sethrubenstein 0e596b5
Updates:
sethrubenstein bbf0700
Updates
sethrubenstein ea2322e
Updated to private store method that we implemented in core/dialog
sethrubenstein 907bf94
Fix initial mount of tabs and focusing on first tab richtext
sethrubenstein 62eb812
Cleanup
sethrubenstein 0510796
Cleanup
sethrubenstein 76c06bb
Remove tests for now
sethrubenstein 79e09d9
Cleanup
sethrubenstein 684d6bd
Cleanup for coding standards
sethrubenstein 1406cd3
Move away from slotfill, can restore if desired.
sethrubenstein 8b36b2f
Replaced dynamic tab label with sprintf, replaced hard coded formats …
sethrubenstein 3e8e4f5
Make markup render correctly when not focused in tabslist
sethrubenstein c4973ad
Add StaticLabel component to TabsList for improved tab label rendering
sethrubenstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }…` | ||
sethrubenstein marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| value={ decodeEntities( currentLabel ) } | ||
| onChange={ onLabelChange } | ||
| /> | ||
| ) : ( | ||
| <span> | ||
| { decodeEntities( siblingLabel ) || | ||
| __( 'Tab' ) + ` ${ index + 1 }` } | ||
| </span> | ||
| ) } | ||
| </button> | ||
| ); | ||
| } ) } | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.