Skip to content

Commit

Permalink
Use section object
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 21, 2022
1 parent 227c8e9 commit 698c1c2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
firstBlockName,
'__experimentalSection',
false
) && getBlockAttributes( clientId ).isSection,
) && !! getBlockAttributes( clientId ).section,
};
},
[ clientIds, blocks, blockInformation?.icon ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe( 'BlockTitle', () => {
it( 'should return section title if the block supports it', () => {
useSelect.mockImplementation( () => ( {
name: 'name-with-section',
attributes: { isSection: true, sectionName: 'My custom section' },
attributes: { section: { name: 'My custom section' } },
} ) );

const wrapper = shallow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export default function useBlockDisplayTitle( clientId, maximumLength ) {

const sectionTitle =
hasBlockSupport( name, '__experimentalSection', false ) &&
attributes.isSection
? attributes.sectionName
: undefined;
attributes.section?.name;

const label = sectionTitle || reusableBlockTitle || blockLabel;
// Label will fallback to the title if no label is defined for the current
Expand Down
18 changes: 4 additions & 14 deletions packages/block-editor/src/hooks/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@ import { hasBlockSupport } from '@wordpress/blocks';
*/
export function addAttribute( settings ) {
if ( hasBlockSupport( settings, '__experimentalSection', false ) ) {
// Allow blocks to specify their own isSection attribute definition with default value if needed.
if ( ! has( settings.attributes, [ 'isSection' ] ) ) {
// Allow blocks to specify their own section attribute definition with default value if needed.
if ( ! has( settings.attributes, [ 'section' ] ) ) {
settings.attributes = {
...settings.attributes,
isSection: {
type: 'boolean',
},
};
}

// Allow blocks to specify their own sectionName attribute definition with default value if needed.
if ( ! has( settings.attributes, [ 'sectionName' ] ) ) {
settings.attributes = {
...settings.attributes,
sectionName: {
type: 'string',
section: {
type: 'object',
},
};
}
Expand Down

0 comments on commit 698c1c2

Please sign in to comment.