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

Show text labels in block toolbars when option is set. #26135

Merged
merged 23 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d521749
Show text labels in block toolbars when option is set.
tellthemachines Oct 15, 2020
b80f997
Fix tests and snapshots.
tellthemachines Oct 15, 2020
11be445
Redo block switcher labels
tellthemachines Jan 5, 2021
8ec8fe3
Update snapshot
tellthemachines Jan 5, 2021
7c777bd
Simplify English strings where possible
tellthemachines Jan 6, 2021
832c2b8
Text labels in format toolbar
tellthemachines Jan 6, 2021
c058503
Simplify transform button
tellthemachines Jan 6, 2021
26d6dba
Shorten labels further.
tellthemachines Jan 7, 2021
8b9de85
update snapshot
tellthemachines Jan 7, 2021
92bc967
Update e2e selectors
tellthemachines Jan 7, 2021
dacd08c
Reduce font size and fix block mover border.
tellthemachines Jan 11, 2021
e4e7bb8
Change back switcher label and update e2e test selectors.
tellthemachines Jan 11, 2021
568490d
Add describedby to button and use in block switcher.
tellthemachines Jan 11, 2021
afcf904
Don't break existing aria-describedby
tellthemachines Jan 11, 2021
55a4d17
Change select parent and add descriptions
tellthemachines Jan 12, 2021
fddc985
Styling adjustments
tellthemachines Jan 12, 2021
ce5a39b
Fix unit tests and update snapshots.
tellthemachines Jan 12, 2021
a46769d
Add unit tests for new button prop.
tellthemachines Jan 12, 2021
794ee18
Change alignment labels
tellthemachines Jan 13, 2021
9c7a3f1
Add toggleProps to ToolbarGroup
diegohaz Jan 13, 2021
a251724
Change e2e test selectors and revert label change
tellthemachines Jan 13, 2021
dcff5af
Actually fix e2e selector this time :P
tellthemachines Jan 13, 2021
61d7d95
Update list e2e test selectors
tellthemachines Jan 13, 2021
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 @@ -38,7 +38,8 @@ export function AlignmentToolbar( props ) {
value,
onChange,
alignmentControls = DEFAULT_ALIGNMENT_CONTROLS,
label = __( 'Change text alignment' ),
label = __( 'Align' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a bit nervous about changing the label to something so succinct, are we confident it's informative enough for screen reader users?

This one in particular because it's using the same label as block alignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, might be worth adding the full text as a tooltip here.

Copy link
Contributor

@hypest hypest Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came here to say something similar to Daniel's. As part of fixing a regression after this PR got merged, it seems that we rely on now single-word label to find the button in E2E tests and tap it on native mobile. My small concern is whether that single word label is unique enough for confident search of it. I don't think it's an issue atm, but wanted to share the concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always resort to a combination of classnames, or other attributes, and labels to find the item. E2e tests shouldn't determine UI design 😅

describedBy = __( 'Change text alignment' ),
isCollapsed = true,
} = props;

Expand All @@ -61,6 +62,7 @@ export function AlignmentToolbar( props ) {
isCollapsed={ isCollapsed }
icon={ setIcon() }
label={ label }
toggleProps={ { describedBy } }
popoverProps={ POPOVER_PROPS }
controls={ alignmentControls.map( ( control ) => {
const { align } = control;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ exports[`AlignmentToolbar should allow custom alignment controls to be specified
</SVG>
}
isCollapsed={true}
label="Change text alignment"
label="Align"
popoverProps={
Object {
"isAlternate": true,
"position": "bottom right",
}
}
toggleProps={
Object {
"describedBy": "Change text alignment",
}
}
/>
`;

Expand Down Expand Up @@ -119,12 +124,17 @@ exports[`AlignmentToolbar should match snapshot 1`] = `
</SVG>
}
isCollapsed={true}
label="Change text alignment"
label="Align"
popoverProps={
Object {
"isAlternate": true,
"position": "bottom right",
}
}
toggleProps={
Object {
"describedBy": "Change text alignment",
}
}
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function BlockAlignmentToolbar( {
? activeAlignmentControl.icon
: defaultAlignmentControl.icon
}
label={ __( 'Change alignment' ) }
label={ __( 'Align' ) }
toggleProps={ { describedBy: __( 'Change alignment' ) } }
controls={ enabledControls.map( ( control ) => {
return {
...BLOCK_ALIGNMENTS_CONTROLS[ control ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ exports[`BlockAlignmentToolbar should match snapshot 1`] = `
</SVG>
}
isCollapsed={true}
label="Change alignment"
label="Align"
popoverProps={
Object {
"isAlternate": true,
}
}
toggleProps={
Object {
"describedBy": "Change alignment",
}
}
/>
`;
3 changes: 1 addition & 2 deletions packages/block-editor/src/components/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ function BlockMover( {
return null;
}

const dragHandleLabel =
clientIds.length === 1 ? __( 'Drag block' ) : __( 'Drag blocks' );
const dragHandleLabel = __( 'Drag' );

// We emulate a disabled state because forcefully applying the `disabled`
// attribute on the buttons while it has focus causes the screen to change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function BlockSettingsDropdown( {
} ) => (
<DropdownMenu
icon={ moreVertical }
label={ __( 'More options' ) }
label={ __( 'Options' ) }
className="block-editor-block-settings-menu"
popoverProps={ POPOVER_PROPS }
noIcons
Expand Down
21 changes: 17 additions & 4 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import BlockStylesMenu from './block-styles-menu';
export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
const { replaceBlocks } = useDispatch( blockEditorStore );
const blockInformation = useBlockDisplayInformation( blocks[ 0 ].clientId );
const { possibleBlockTransformations, hasBlockStyles, icon } = useSelect(
const {
possibleBlockTransformations,
hasBlockStyles,
icon,
blockTitle,
} = useSelect(
( select ) => {
const { getBlockRootClientId, getBlockTransformItems } = select(
blockEditorStore
Expand Down Expand Up @@ -61,10 +66,12 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
),
hasBlockStyles: !! styles?.length,
icon: _icon,
blockTitle: getBlockType( firstBlockName ).title,
};
},
[ clientIds, blocks, blockInformation?.icon ]
);

const onTransform = ( name ) =>
replaceBlocks( clientIds, switchToBlockType( blocks, name ) );
const hasPossibleBlockTransformations = !! possibleBlockTransformations.length;
Expand All @@ -74,13 +81,16 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
<ToolbarButton
disabled
className="block-editor-block-switcher__no-switcher-icon"
title={ __( 'Block icon' ) }
title={ blockTitle }
icon={ <BlockIcon icon={ icon } showColors /> }
/>
</ToolbarGroup>
);
}
const blockSwitcherLabel =

const blockSwitcherLabel = blockTitle;

const blockSwitcherDescription =
1 === blocks.length
? __( 'Change block type or style' )
: sprintf(
Expand Down Expand Up @@ -112,7 +122,10 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
showColors
/>
}
toggleProps={ toggleProps }
toggleProps={ {
describedBy: blockSwitcherDescription,
...toggleProps,
} }
menuProps={ { orientation: 'both' } }
>
{ ( { onClose } ) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ exports[`BlockSwitcherDropdownMenu should render disabled block switcher with mu
showColors={true}
/>
}
title="Block icon"
/>
</ToolbarGroup>
`;
Expand Down
97 changes: 97 additions & 0 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,100 @@
transform: translateY(-($block-toolbar-height + $grid-unit-15));
}
}

.show-icon-labels {
.block-editor-block-toolbar {
.components-button.has-icon {
width: auto;

// Hide the button icons when labels are set to display...
svg {
display: none;
}
// ... and display labels.
&::after {
content: attr(aria-label);
font-size: $helptext-font-size;
}
}
}

// Padding overrides.

.components-accessible-toolbar .components-toolbar-group > div:first-child:last-child > .components-button.has-icon {
padding-left: 6px;
padding-right: 6px;
}

// Switcher overrides.
.block-editor-block-switcher {
border-right: 1px solid $gray-900;

.components-dropdown-menu__toggle {
margin-left: 0;
}
}

.block-editor-block-switcher .components-dropdown-menu__toggle,
.block-editor-block-switcher__no-switcher-icon {
.block-editor-block-icon {
width: 0 !important;
height: 0 !important;
}

&:focus::before {
right: $grid-unit-05 !important;
}
}

// Parent selector overrides

.block-editor-block-parent-selector__button {
.block-editor-block-icon {
width: 0;
}
}

// Mover overrides.
.block-editor-block-toolbar__block-controls .block-editor-block-mover {
margin-left: 0;
white-space: nowrap;
}

.block-editor-block-mover-button {
// The specificity can be reduced once https://github.com/WordPress/gutenberg/blob/try/block-toolbar-labels/packages/block-editor/src/components/block-mover/style.scss#L34 is also dealt with.
padding-left: $grid-unit !important;
padding-right: $grid-unit !important;
}

.block-editor-block-mover__drag-handle.has-icon {
padding-left: 6px !important;
padding-right: 6px !important;
border-right: 1px solid $gray-900;
}

@include break-small() {
// Specificity override for https://github.com/WordPress/gutenberg/blob/try/block-toolbar-labels/packages/block-editor/src/components/block-mover/style.scss#L69
.is-up-button.is-up-button.is-up-button {
border-bottom: 1px solid $gray-900;
margin-right: 0;
border-radius: 0;
}
}

.block-editor-block-contextual-toolbar .block-editor-block-mover.is-horizontal .block-editor-block-mover-button.block-editor-block-mover-button {
width: auto;
}

// Mobile adjustments
.components-toolbar,
.components-toolbar-group {
flex-shrink: 1;
}

.block-editor-format-toolbar {
.components-button + .components-button {
margin-left: 6px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
className="components-circular-option-picker__option-wrapper"
>
<button
aria-describedby={null}
aria-label="Color: red"
aria-pressed={true}
className="components-button components-circular-option-picker__option is-pressed"
Expand Down Expand Up @@ -91,6 +92,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
className="components-dropdown components-circular-option-picker__dropdown-link-action"
>
<button
aria-describedby={null}
aria-expanded={false}
aria-haspopup="true"
aria-label="Custom color picker"
Expand All @@ -102,6 +104,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
</button>
</div>
<button
aria-describedby={null}
className="components-button components-circular-option-picker__clear is-secondary is-small"
onClick={[Function]}
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const FormatToolbarContainer = ( { inline, anchorRef } ) => {
focusOnMount={ false }
anchorRef={ anchorRef }
className="block-editor-rich-text__inline-format-toolbar"
__unstableSlotName="block-toolbar"
draganescu marked this conversation as resolved.
Show resolved Hide resolved
>
<FormatToolbar />
</Popover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ const FormatToolbar = () => {
{ ( toggleProps ) => (
<DropdownMenu
icon={ chevronDown }
label={ __(
'More rich text controls'
) }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'More' ) }
toggleProps={ toggleProps }
controls={ orderBy(
fills.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@
justify-content: center;
}
}

.show-icon-labels {
.block-editor-format-toolbar {
.components-button.has-icon {
width: auto;

// Hide the button icons when labels are set to display...
svg {
display: none;
}
// ... and display labels.
&::after {
content: attr(aria-label);
}
}
}
}
12 changes: 8 additions & 4 deletions packages/block-library/src/list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default function ListEdit( {
icon: isRTL()
? formatListBulletsRTL
: formatListBullets,
title: __( 'Convert to unordered list' ),
title: __( 'Unordered' ),
describedBy: __( 'Convert to unordered list' ),
isActive: isActiveListType( value, 'ul', tagName ),
onClick() {
onChange(
Expand All @@ -108,7 +109,8 @@ export default function ListEdit( {
icon: isRTL()
? formatListNumberedRTL
: formatListNumbered,
title: __( 'Convert to ordered list' ),
title: __( 'Ordered' ),
describedBy: __( 'Convert to ordered list' ),
isActive: isActiveListType( value, 'ol', tagName ),
onClick() {
onChange(
Expand All @@ -123,7 +125,8 @@ export default function ListEdit( {
},
{
icon: isRTL() ? formatOutdentRTL : formatOutdent,
title: __( 'Outdent list item' ),
title: __( 'Outdent' ),
describedBy: __( 'Outdent list item' ),
shortcut: _x( 'Backspace', 'keyboard key' ),
isDisabled: ! canOutdentListItems( value ),
onClick() {
Expand All @@ -133,7 +136,8 @@ export default function ListEdit( {
},
{
icon: isRTL() ? formatIndentRTL : formatIndent,
title: __( 'Indent list item' ),
title: __( 'Indent' ),
describedBy: __( 'Indent list item' ),
shortcut: _x( 'Space', 'keyboard key' ),
isDisabled: ! canIndentListItems( value ),
onClick() {
Expand Down
Loading