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

Add column count to the column block label #30248

Merged
merged 4 commits into from Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/block-library/src/column/edit.js
Expand Up @@ -36,15 +36,18 @@ function ColumnEdit( {
[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,
} );

const { hasChildBlocks, rootClientId } = useSelect(
const { columnsIds, hasChildBlocks, rootClientId } = useSelect(
( select ) => {
const { getBlockOrder, getBlockRootClientId } = select(
blockEditorStore
);

const rootId = getBlockRootClientId( clientId );

return {
hasChildBlocks: getBlockOrder( clientId ).length > 0,
rootClientId: getBlockRootClientId( clientId ),
rootClientId: rootId,
columnsIds: getBlockOrder( rootId ),
};
},
[ clientId ]
Expand Down Expand Up @@ -73,6 +76,10 @@ function ColumnEdit( {
: InnerBlocks.ButtonBlockAppender,
} );

const columnsCount = columnsIds.length;
const currentColumnPosition = columnsIds.indexOf( clientId ) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would getBlockIndex and getBlockOrder work for this? When I tried earlier this week I was not able to solve it.

const label = `${ innerBlocksProps[ 'aria-label' ] } (${ currentColumnPosition } of ${ columnsCount })`;
diegohaz marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<BlockControls>
Expand All @@ -97,7 +104,7 @@ function ColumnEdit( {
/>
</PanelBody>
</InspectorControls>
<div { ...innerBlocksProps } />
<div { ...innerBlocksProps } aria-label={ label } />
diegohaz marked this conversation as resolved.
Show resolved Hide resolved
</>
);
}
Expand Down