Replies: 2 comments 2 replies
-
I think you'll need to provide a glide element reference instead of the class. Related articles: |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks @Mamaduka The article "Blocks in an iframed (template) editor" was quite helpful and helped me understand why the slider was not working, especially in the Site Editor. Although I have made the following change, unfortunately, the block is still behaving as before and giving errors in the Site/Template Editor. @@ -27,20 +27,22 @@ import './editor.scss';
* @return {WPElement} The edit component.
*/
export default function Edit( { attributes, setAttributes, clientId } ) {
+ const sliderRef = useRef();
+ const sliderEl = useRef();
+
const blockProps = useBlockProps( {
- className: 'glide__slides',
+ className: '.glide',
+ ref: sliderEl,
} );
- const { children, ...combinedBlockProps } = useInnerBlocksProps(
- blockProps,
+ const { children, ...innerBlocksProps } = useInnerBlocksProps(
+ { className: 'glide__slides' },
{
renderAppender: InnerBlocks.ButtonBlockAppender,
templateLock: attributes.templateLock && 'all',
- }
+ },
);
- const sliderRef = useRef();
-
// Get total number of slide count.
const { blockCount } = useSelect( ( select ) => ( {
blockCount: select( 'core/block-editor' ).getBlockCount( clientId ),
@@ -61,7 +63,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
controls,
} = attributes;
- const slider = new Glide( '.glide', {
+ const slider = new Glide( sliderEl.current, {
type: 'slider',
perView,
gap,
@@ -83,7 +85,9 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
// Update the slider when attributes change.
useEffect( () => {
- if ( ! sliderRef.current ) return;
+ if ( ! sliderRef.current ) {
+ return;
+ }
const {
perView,
@@ -112,9 +116,9 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
prevSlide: () => sliderRef.current.go( '<' ),
} }
/>
- <div className="glide">
+ <div { ...blockProps }>
<div className="glide__track" data-glide-el="track">
- <div { ...combinedBlockProps }>{ children }</div>
+ <div { ...innerBlocksProps }>{ children }</div>
</div>
</div>
</> |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Issue with Custom Slider Gutenberg Block
I'm in the process of building a custom slider Gutenberg block that incorporates the use of
InnerBlocks
. I've chosen to implement this slider using Glide.js. Below is a demo video showcasing the custom block, which functions perfectly in the post editor:However, I'm encountering an issue when attempting to use the same block within the site editor. The error encountered is illustrated by the following images:
Here is the code for the
Edit
component of the custom block:Beta Was this translation helpful? Give feedback.
All reactions