Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix: navigation outside of product collection block
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu committed Dec 5, 2023
1 parent 6a90ee3 commit 860e286
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion assets/js/blocks/collection-filters/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"reusable": false
},
"usesContext": [
"query"
"query",
"queryId"
],
"providesContext": {
"collectionData": "collectionData"
Expand Down
7 changes: 2 additions & 5 deletions assets/js/blocks/collection-filters/save.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/**
* External dependencies
*/
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import { InnerBlocks } from '@wordpress/block-editor';

export default function save() {
const blockProps = useBlockProps.save();
const innerBlockProps = useInnerBlocksProps.save( blockProps );

return <nav { ...innerBlockProps } />;
return <InnerBlocks.Content />;
}
25 changes: 25 additions & 0 deletions src/BlockTypes/CollectionFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ protected function enqueue_data( array $attributes = [] ) {
}
}

/**
* Render the block.
*
* @param array $attributes Block attributes.
* @param string $content Block content.
* @param WP_Block $block Block instance.
* @return string Rendered block type output.
*/
protected function render( $attributes, $content, $block ) {
$attributes_data = array(
'data-wc-interactive' => wp_json_encode( array( 'namespace' => 'woocommerce/collection-filters' ) ),
'class' => 'wc-block-collection-filters',
);

if ( ! isset( $block->context['queryId'] ) ) {
$attributes_data['data-wc-navigation-id'] = 'wc-collection-filters';
}

return sprintf(
'<nav %1$s>%2$s</nav>',
get_block_wrapper_attributes( $attributes_data ),
$content
);
}

/**
* Modify the context of inner blocks.
*
Expand Down

0 comments on commit 860e286

Please sign in to comment.