-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
Tabs
in site-editor settings (#56959)
* take that, slot/fill! * panel margin style fix * style updates * e2e test updates * ensure canvas is in edit mode * fix tabpanel ids * update new playwright tests * disable `selectOnMove` * address tab flow race condition * implement feedback Co-authored-by: chad1008 <[email protected]> Co-authored-by: ciampo <[email protected]> Co-authored-by: andrewhayward <[email protected]> Co-authored-by: afercia <[email protected]> Co-authored-by: alexstine <[email protected]> Co-authored-by: joedolson <[email protected]>
- Loading branch information
1 parent
0b1de17
commit 15a5a88
Showing
7 changed files
with
165 additions
and
190 deletions.
There are no files selected for viewing
This file contains 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
88 changes: 25 additions & 63 deletions
88
packages/edit-site/src/components/sidebar-edit-mode/settings-header/index.js
This file contains 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 |
---|---|---|
@@ -1,82 +1,44 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { store as interfaceStore } from '@wordpress/interface'; | ||
import { privateApis as componentsPrivateApis } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { STORE_NAME } from '../../../store/constants'; | ||
import { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from '../constants'; | ||
import { unlock } from '../../../lock-unlock'; | ||
|
||
const SettingsHeader = ( { sidebarName } ) => { | ||
const { Tabs } = unlock( componentsPrivateApis ); | ||
|
||
const SettingsHeader = ( _, ref ) => { | ||
const postTypeLabel = useSelect( | ||
( select ) => select( editorStore ).getPostTypeLabel(), | ||
[] | ||
); | ||
|
||
const { enableComplementaryArea } = useDispatch( interfaceStore ); | ||
const openTemplateSettings = () => | ||
enableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE ); | ||
const openBlockSettings = () => | ||
enableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK ); | ||
|
||
const documentAriaLabel = | ||
sidebarName === SIDEBAR_TEMPLATE | ||
? // translators: ARIA label for the Template sidebar tab, selected. | ||
sprintf( __( '%s (selected)' ), postTypeLabel ) | ||
: postTypeLabel; | ||
|
||
/* Use a list so screen readers will announce how many tabs there are. */ | ||
return ( | ||
<ul> | ||
<li> | ||
<Button | ||
onClick={ openTemplateSettings } | ||
className={ classnames( | ||
'edit-site-sidebar-edit-mode__panel-tab', | ||
{ | ||
'is-active': sidebarName === SIDEBAR_TEMPLATE, | ||
} | ||
) } | ||
aria-label={ documentAriaLabel } | ||
data-label={ postTypeLabel } | ||
> | ||
{ postTypeLabel } | ||
</Button> | ||
</li> | ||
<li> | ||
<Button | ||
onClick={ openBlockSettings } | ||
className={ classnames( | ||
'edit-site-sidebar-edit-mode__panel-tab', | ||
{ | ||
'is-active': sidebarName === SIDEBAR_BLOCK, | ||
} | ||
) } | ||
aria-label={ | ||
sidebarName === SIDEBAR_BLOCK | ||
? // translators: ARIA label for the Block Settings Sidebar tab, selected. | ||
__( 'Block (selected)' ) | ||
: // translators: ARIA label for the Block Settings Sidebar tab, not selected. | ||
__( 'Block' ) | ||
} | ||
data-label={ __( 'Block' ) } | ||
> | ||
{ __( 'Block' ) } | ||
</Button> | ||
</li> | ||
</ul> | ||
<Tabs.TabList ref={ ref }> | ||
<Tabs.Tab | ||
tabId={ SIDEBAR_TEMPLATE } | ||
// Used for focus management in the SettingsSidebar component. | ||
data-tab-id={ SIDEBAR_TEMPLATE } | ||
> | ||
{ postTypeLabel } | ||
</Tabs.Tab> | ||
<Tabs.Tab | ||
tabId={ SIDEBAR_BLOCK } | ||
// Used for focus management in the SettingsSidebar component. | ||
data-tab-id={ SIDEBAR_BLOCK } | ||
> | ||
{ __( 'Block' ) } | ||
</Tabs.Tab> | ||
</Tabs.TabList> | ||
); | ||
}; | ||
|
||
export default SettingsHeader; | ||
export default forwardRef( SettingsHeader ); |
This file contains 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.