Skip to content
Merged
Changes from all 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
20 changes: 20 additions & 0 deletions packages/block-library/src/accordion/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
useBlockProps,
useInnerBlocksProps,
InspectorControls,
BlockControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import {
Expand All @@ -13,7 +15,10 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
ToolbarButton,
} from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -27,10 +32,12 @@ const ACCORDION_BLOCK = {

export default function Edit( {
attributes: { autoclose, iconPosition, showIcon },
clientId,
setAttributes,
} ) {
const blockProps = useBlockProps();
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const { insertBlock } = useDispatch( blockEditorStore );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
template: [ [ ACCORDION_BLOCK_NAME ], [ ACCORDION_BLOCK_NAME ] ],
Expand All @@ -39,8 +46,21 @@ export default function Edit( {
templateInsertUpdatesSelection: true,
} );

const addAccordionContentBlock = () => {
const newAccordionContent = createBlock( ACCORDION_BLOCK_NAME );
insertBlock( newAccordionContent, undefined, clientId );
};

return (
<>
<BlockControls group="other">
<ToolbarButton
label={ __( 'Add accordion content block' ) }
onClick={ addAccordionContentBlock }
>
{ __( 'Add' ) }
Comment on lines +58 to +61
Copy link
Member

Choose a reason for hiding this comment

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

I might be mistaken, but I thought we shouldn't use different labels when a button has an actual text label, from an a11y perspective.

cc @joedolson, @t-hamano

Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't use different labels when a button has an actual text label, from an a11y perspective.

This is how I understand it too. I think we should remove the label prop (aria-label),

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I agree, I don't think we should have the label here at all. I thought I used a pattern I found in another block, but the only other example I can see is the Gallery block, which just uses "Add" as the button text with no label. Will spin up a PR with a fix!

Copy link
Member

@Mamaduka Mamaduka Sep 19, 2025

Choose a reason for hiding this comment

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

Or we could do that as part of #71750

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, we'll address it in #71750

Copy link
Member Author

Choose a reason for hiding this comment

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

PR here: #71756

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, we'll address it in #71750

Ah sorry, didn't see these comments until after creating the PR 😅

Copy link
Member

Choose a reason for hiding this comment

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

We can do separate PRs. No problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. If the context of the button is clear and it has visible text, it shouldn't also have a label prop. Thanks for catching this!

</ToolbarButton>
</BlockControls>
<InspectorControls key="setting">
<ToolsPanel
label={ __( 'Settings' ) }
Expand Down
Loading