Skip to content
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

Consistent, descriptive accessible name for command palette button #54323

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ function DocumentActions() {
<Button
className="edit-post-document-actions__command"
onClick={ () => openCommandCenter() }
aria-label={ __( 'Command Palette' ) }
jeryj marked this conversation as resolved.
Show resolved Hide resolved
>
<HStack
className="edit-post-document-actions__title"
spacing={ 1 }
justify="center"
>
<BlockIcon icon={ layout } />
<Text size="body" as="h1">
<Text
className="edit-post-document-actions__text"
size="body"
as="span"
color={ undefined }
>
<VisuallyHidden as="span">
{ __( 'Editing template: ' ) }
</VisuallyHidden>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
flex-shrink: 0;
}

h1 {
.edit-post-document-actions__text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { __, isRTL } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import {
Button,
VisuallyHidden,
__experimentalText as Text,
__experimentalHStack as HStack,
} from '@wordpress/components';
Expand All @@ -33,13 +32,6 @@ import { store as coreStore } from '@wordpress/core-data';
import useEditedEntityRecord from '../../use-edited-entity-record';
import { store as editSiteStore } from '../../../store';

const typeLabels = {
wp_block: __( 'Editing pattern:' ),
wp_navigation: __( 'Editing navigation menu:' ),
wp_template: __( 'Editing template:' ),
wp_template_part: __( 'Editing template part:' ),
};

export default function DocumentActions() {
const isPage = useSelect(
( select ) => select( editSiteStore ).isPage(),
Expand Down Expand Up @@ -144,9 +136,6 @@ function TemplateDocumentActions( { className, onBack } ) {
icon={ typeIcon }
onBack={ onBack }
>
<VisuallyHidden as="span">
{ typeLabels[ record.type ] ?? typeLabels.wp_template }
</VisuallyHidden>
{ getTitle() }
</BaseDocumentActions>
);
Expand All @@ -173,14 +162,19 @@ function BaseDocumentActions( { className, icon, children, onBack } ) {
<Button
className="edit-site-document-actions__command"
onClick={ () => openCommandCenter() }
aria-label={ __( 'Command Palette' ) }
jeryj marked this conversation as resolved.
Show resolved Hide resolved
>
<HStack
className="edit-site-document-actions__title"
spacing={ 1 }
justify="center"
>
<BlockIcon icon={ icon } />
<Text size="body" as="h1">
<Text
className="edit-site-document-actions__text"
size="body"
as="span"
>
{ children }
</Text>
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
&.is-synced-entity {
.edit-site-document-actions__title {
color: var(--wp-block-synced-color);
h1 {
.edit-site-document-actions__text {
color: var(--wp-block-synced-color);
}
}
Expand Down Expand Up @@ -68,7 +68,7 @@
flex-shrink: 0;
}

h1 {
.edit-site-document-actions__text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand All @@ -78,7 +78,7 @@
.edit-site-document-actions.is-page & {
color: $gray-800;

h1 {
.edit-site-document-actions__text {
color: $gray-800;
}
}
Expand Down
16 changes: 16 additions & 0 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,21 @@ import {
} from '../editor-canvas-container';
import { unlock } from '../../lock-unlock';
import { FOCUSABLE_ENTITIES } from '../../utils/constants';
import useEditedEntityRecord from '../use-edited-entity-record';

const { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );

const preventDefault = ( event ) => {
event.preventDefault();
};

const typeLabels = {
wp_block: __( 'Editing pattern:' ),
wp_navigation: __( 'Editing navigation menu:' ),
wp_template: __( 'Editing template:' ),
wp_template_part: __( 'Editing template part:' ),
};

export default function HeaderEditMode() {
const inserterButton = useRef();
const {
Expand Down Expand Up @@ -116,6 +124,7 @@ export default function HeaderEditMode() {
};
}, [] );

const { record, getTitle } = useEditedEntityRecord();
const {
__experimentalSetPreviewDeviceType: setPreviewDeviceType,
setIsInserterOpened,
Expand Down Expand Up @@ -183,12 +192,19 @@ export default function HeaderEditMode() {
ease: 'easeOut',
};

const title = hasDefaultEditorCanvasView
? `${
typeLabels[ record.type ] ?? typeLabels.wp_template
} ${ getTitle() }`
: getEditorCanvasContainerTitle( editorCanvasView );

return (
<div
className={ classnames( 'edit-site-header-edit-mode', {
'show-icon-labels': showIconLabels,
} ) }
>
<VisuallyHidden as="h1">{ title }</VisuallyHidden>
{ hasDefaultEditorCanvasView && (
<NavigableToolbar
as={ motion.div }
Expand Down
Loading