Skip to content

Commit

Permalink
improve renderappender block in the tabbed content
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Jan 30, 2024
1 parent 2736d6b commit e5d7e3c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/blocks.build.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => 'ce0125ece88fe8903fcb');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '7c8af4d60fe64627d438');
16 changes: 8 additions & 8 deletions dist/blocks.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -57230,11 +57230,14 @@ registerBlockType(_block_json__WEBPACK_IMPORTED_MODULE_2__.name, _objectSpread(_
icon: _icons_icon__WEBPACK_IMPORTED_MODULE_0__["default"],
edit: withSelect(function (select, ownProps) {
return {
blockParentId: (select("core/block-editor") || select("core/editor")).getBlockRootClientId(ownProps.clientId)
blockParentId: (select("core/block-editor") || select("core/editor")).getBlockRootClientId(ownProps.clientId),
block: select("core/block-editor").getBlock(ownProps.clientId)
};
})(function (props) {
var _block$innerBlocks;
var blockParentId = props.blockParentId,
setAttributes = props.setAttributes;
setAttributes = props.setAttributes,
block = props.block;
var _props$attributes = props.attributes,
parentID = _props$attributes.parentID,
isActive = _props$attributes.isActive;
Expand All @@ -57247,15 +57250,12 @@ registerBlockType(_block_json__WEBPACK_IMPORTED_MODULE_2__.name, _objectSpread(_
// if (parentID === "" || parentID !== blockParentId) {
// setAttributes({ parentID: blockParentId });
// }

var hasInnerBlocks = (block === null || block === void 0 || (_block$innerBlocks = block.innerBlocks) === null || _block$innerBlocks === void 0 ? void 0 : _block$innerBlocks.length) > 0;
return /*#__PURE__*/React.createElement("div", blockProps, /*#__PURE__*/React.createElement(InnerBlocks, {
templateLock: false,
template: [["core/paragraph", {
placeholder: " "
} //blank string still results into Wordpress displaying default placeholder
]],
template: [["core/paragraph"]],
renderAppender: function renderAppender() {
return /*#__PURE__*/React.createElement(InnerBlocks.ButtonBlockAppender, null);
return hasInnerBlocks ? false : /*#__PURE__*/React.createElement(InnerBlocks.ButtonBlockAppender, null);
}
}));
}),
Expand Down
2 changes: 1 addition & 1 deletion dist/blocks.build.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ That's it. You're done!
* IMPROVE: Color component in button (improved) block.
* IMPROVE: Icon control in all blocks.
* IMPROVE: Styled List additional panel opened by default.
* IMPROVE: Renderappender in tabbed content block.
* NEW: Option to hide review text in the star rating block.
* NEW: Border and Radius option in icon block.

Expand Down
16 changes: 7 additions & 9 deletions src/blocks/tabbed-content/components/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ registerBlockType(metadata.name, {
blockParentId: (
select("core/block-editor") || select("core/editor")
).getBlockRootClientId(ownProps.clientId),
block: select("core/block-editor").getBlock(ownProps.clientId),
}))(function (props) {
const { blockParentId, setAttributes } = props;
const { blockParentId, setAttributes, block } = props;
const { parentID, isActive } = props.attributes;
const blockProps = useBlockProps({
style: { display: isActive ? "block" : "none" },
Expand All @@ -65,18 +66,15 @@ registerBlockType(metadata.name, {
// if (parentID === "" || parentID !== blockParentId) {
// setAttributes({ parentID: blockParentId });
// }

const hasInnerBlocks = block?.innerBlocks?.length > 0;
return (
<div {...blockProps}>
<InnerBlocks
templateLock={false}
template={[
[
"core/paragraph",
{ placeholder: " " }, //blank string still results into Wordpress displaying default placeholder
],
]}
renderAppender={() => <InnerBlocks.ButtonBlockAppender />}
template={[["core/paragraph"]]}
renderAppender={() =>
hasInnerBlocks ? false : <InnerBlocks.ButtonBlockAppender />
}
/>
</div>
);
Expand Down

0 comments on commit e5d7e3c

Please sign in to comment.