-
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
Use TabPanel in edit settings sidebar header (#13587) #16663
Changes from 6 commits
2f5414b
a9124b9
bcf46a3
cff31f0
8733d7d
0686044
84ab486
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
.components-tab-panel__tabs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mapk are we fine with these styles to be the default look outside of the context of sidebar and WordPress in general? |
||
display: flex; | ||
align-items: stretch; | ||
background: $light-gray-200; | ||
border-bottom: 1px solid #e2e4e7; | ||
} | ||
|
||
.components-tab-panel__tabs-item { | ||
background: transparent; | ||
border: none; | ||
box-shadow: none; | ||
cursor: pointer; | ||
height: 50px; | ||
line-height: 42px; | ||
padding: 3px 15px; // Use padding to offset the is-active border, this benefits Windows High Contrast mode | ||
margin-left: 0; | ||
font-weight: 400; | ||
@include square-style__neutral; | ||
transition: box-shadow 0.1s linear; | ||
|
||
&:focus:enabled { | ||
color: $dark-gray-900; | ||
outline-offset: -1px; | ||
outline: 1px dotted $dark-gray-500; | ||
} | ||
|
||
&:focus:enabled, | ||
&.is-active { | ||
box-shadow: inset 0 -3px theme(outlines); | ||
font-weight: 600; | ||
position: relative; | ||
background: transparent; | ||
|
||
// This border appears in Windows High Contrast mode instead of the box-shadow. | ||
&::before { | ||
content: ""; | ||
position: absolute; | ||
top: 0; | ||
bottom: 1px; | ||
right: 0; | ||
left: 0; | ||
border-bottom: 3px solid transparent; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,54 +3,53 @@ | |
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { withDispatch } from '@wordpress/data'; | ||
import { TabPanel } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SidebarHeader from '../sidebar-header'; | ||
|
||
const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName } ) => { | ||
const blockLabel = __( 'Block' ); | ||
const [ documentAriaLabel, documentActiveClass ] = sidebarName === 'edit-post/document' ? | ||
const documentAriaLabel = sidebarName === 'edit-post/document' ? | ||
// translators: ARIA label for the Document sidebar tab, selected. | ||
[ __( 'Document (selected)' ), 'is-active' ] : | ||
__( 'Document (selected)' ) : | ||
// translators: ARIA label for the Document sidebar tab, not selected. | ||
[ __( 'Document' ), '' ]; | ||
( 'Document' ); | ||
|
||
const [ blockAriaLabel, blockActiveClass ] = sidebarName === 'edit-post/block' ? | ||
const blockAriaLabel = sidebarName === 'edit-post/block' ? | ||
// translators: ARIA label for the Settings Sidebar tab, selected. | ||
[ __( 'Block (selected)' ), 'is-active' ] : | ||
__( 'Block (selected)' ) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, the part which informs about the selected tab could be constructed inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice suggestion, this simplifies the settings header logic even further. |
||
// translators: ARIA label for the Settings Sidebar tab, not selected. | ||
[ __( 'Block' ), '' ]; | ||
__( 'Block' ); | ||
|
||
const tabs = [ | ||
{ | ||
name: 'edit-post/document__panel-tab', | ||
className: 'edit-post-sidebar__panel-tab', | ||
title: __( 'Document' ), | ||
ariaLabel: `${ documentAriaLabel }`, | ||
jffng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onSelect: openDocumentSettings, | ||
}, | ||
{ | ||
name: 'edit-post/block__panel-tab', | ||
className: 'edit-post-sidebar__panel-tab', | ||
title: __( 'Block' ), | ||
ariaLabel: `${ blockAriaLabel }`, | ||
onSelect: openBlockSettings, | ||
}, | ||
]; | ||
|
||
return ( | ||
<SidebarHeader | ||
className="edit-post-sidebar__panel-tabs" | ||
closeLabel={ __( 'Close settings' ) } | ||
> | ||
{ /* Use a list so screen readers will announce how many tabs there are. */ } | ||
<ul> | ||
<li> | ||
<button | ||
onClick={ openDocumentSettings } | ||
className={ `edit-post-sidebar__panel-tab ${ documentActiveClass }` } | ||
aria-label={ documentAriaLabel } | ||
data-label={ __( 'Document' ) } | ||
> | ||
{ __( 'Document' ) } | ||
</button> | ||
</li> | ||
<li> | ||
<button | ||
onClick={ openBlockSettings } | ||
className={ `edit-post-sidebar__panel-tab ${ blockActiveClass }` } | ||
aria-label={ blockAriaLabel } | ||
data-label={ blockLabel } | ||
> | ||
{ blockLabel } | ||
</button> | ||
</li> | ||
</ul> | ||
<TabPanel | ||
tabs={ tabs } | ||
controlledTabName={ sidebarName + '__panel-tab' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need to be explicitly set from outside or is it possible to append |
||
> | ||
</TabPanel> | ||
</SidebarHeader> | ||
); | ||
}; | ||
|
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.
This is a breaking change and can't be landed as is. It needs to provide a way which ensures that this code is backward compatible with a solid deprecation strategy which informs developers that there is a new way to handle this prop.
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.
Thanks for the review @gziolo, noted.
I added support for the
initialTabName
for backwards compatibility, as well deprecation notes in the README. However, I lack context as to the timing / version to officially deprecate this prop.This is also assuming that having a prop to control the active tab from a parent component is a good idea / not an anti-pattern.
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.
If we don't want to keep this param, we should rather remove it from docs and ensure that when used it works as close as possible as the new one.