Skip to content

Dakota/refactor collapsible block #377

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

Open
wants to merge 8 commits into
base: dakota/Refactor-existing-Block-Architecture
Choose a base branch
from

Conversation

acketon
Copy link
Member

@acketon acketon commented May 28, 2025

  • Refactor block to modernize structure
    • Add support for Block Supports: Color
    • Breaking Changes:
      • Icon for +/- and up/down switched from BU Default Icons font to SVG markup to remove dependency on Responsive Foundation's icons. Existing themes will need to update.

Later in future PR:

  • Migrate frontend.js to use the new viewScript setup
  • Consider removing the is-style-preview layout if it's usage is limited in production.

><?php echo esc_html( "{$attributes['buttonOpenLabel']}" ); ?></button>
<?php endif; ?>
<div class="bu-block-collapsible-content js-bu-block-collapsible-content" id="<?php echo esc_attr( "{$attributes['id']}-panel" ); ?>">
<?php echo $content; ?>

Choose a reason for hiding this comment

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

wp_kses_post()?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is not escaped because the current version of the block isn't: https://github.com/bu-ist/bu-blocks/blob/develop/src/blocks/collapsible/index.php#L135

Do you think wp_kses_post() would be permissive enough to not have issues with outputting blocks and markup? The collapsible block allows a wide variety of nested blocks. I just don't want to break any existing blocks.

Choose a reason for hiding this comment

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

Do we need to do any escaping or filtering here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have any suggestions for what's left in this index.php file? Is this method of getting the SVG markup from the SVG file acceptable?

checked={ autoID }
onChange={ () => setAttributes( { autoID: ! autoID } ) }
/>
<p>

Choose a reason for hiding this comment

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

Nice to have - is there any way to check that this is unique and flag it if not?

Additional notes to include:

  • the id name is case sensitive
  • the id name must contain at least one character and cannot start with a number

Copy link
Member Author

Choose a reason for hiding this comment

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

The autoID here is just a toggle boolean attribute, defaulting to true that controls if the auto anchor id generation should be handled. I wrote this enhancement to the block a long while ago because the block was broken and putting duplicate anchor id's into production site and it was getting flagged in SiteImprove. It also was causing issues for the JS on the frontend and aria labels, etc.

You can see more about this in this file: https://github.com/bu-ist/bu-blocks/blob/dakota/refactor-collapsible-block/src/blocks/collapsible/generated-ids.js and the usage inside the Edit.js function.

I do like the idea of improving the ID name validation and I don't remember if it is currently checking for those two issues you point out. All of this is a bit of hack because WP core doesn't yet support a feature to handle this for attributes.

There is more background on this in the PR from a couple years ago where I introduced this auto generating ID's feature: #356

// WordPress dependencies.
import { __ } from '@wordpress/i18n';
import {
PanelBody,

Choose a reason for hiding this comment

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

PanelBody, ToggleControl, TextControl, RangeControl, Button, and ButtonGroup are not used and can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, good catch

import {
InnerBlocks,
BlockControls,
InspectorControls,

Choose a reason for hiding this comment

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

InspectorControls is not used and can be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

customMarginBottom,
marginBottom,
id,
buttonCloseLabel,

Choose a reason for hiding this comment

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

buttonCloseLabel is not used - not sure if that was missed or if it can be removed

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 think this got moved into the InspectorControls partial now, but let me double check it's still working

Copy link

@timkingbu timkingbu left a comment

Choose a reason for hiding this comment

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

Code looks pretty well documented and organized. Just a few cleanup items and things to watch out for as we move past 5.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants