Skip to content

Commit

Permalink
fix (column block): styling not working when used inside a query loop (
Browse files Browse the repository at this point in the history
…#3298)

* fix(content-align): make getContentAlignmentClasses compatible with adding instanceId

* fix: add instanceId to class if inside QueryLoop

* fix: rearrange getContentAlignmentClasses parameters
  • Loading branch information
Arukuen authored Sep 5, 2024
1 parent e41f751 commit 224a9b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/block-components/content-align/use-content-align.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import { applyFilters } from '@wordpress/hooks'
import classnames from 'classnames'

export const getContentAlignmentClasses = ( attributes, blockName = 'column' ) => {
export const getContentAlignmentClasses = ( attributes, blockName = 'column', instanceId = '' ) => {
let instanceIdString = ''
if ( instanceId ) {
instanceIdString = `${ instanceId }-`
}

return classnames(
'stk-content-align',
`stk-${ attributes.uniqueId }-${ blockName }`,
`stk-${ attributes.uniqueId }-${ instanceIdString }${ blockName }`,
applyFilters( 'stackable.block-components.content-align.getContentAlignmentClasses', {
'stk--flex': attributes.columnJustify,
alignwide: attributes.innerBlockContentAlign === 'alignwide', // This will align the columns inside.
Expand Down
5 changes: 4 additions & 1 deletion src/block/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
withBlockWrapperIsHovered,
withQueryLoopContext,
} from '~stackable/higher-order'
import { useQueryLoopInstanceId } from '~stackable/util'

/**
* WordPress dependencies
Expand Down Expand Up @@ -74,11 +75,13 @@ const Edit = props => {
columnTooltipClass,
], props ) )

const instanceId = useQueryLoopInstanceId( props.attributes.uniqueId )

const contentClassNames = classnames( [
'stk-inner-blocks',
blockAlignmentClass,
'stk-block-content',
], getContentAlignmentClasses( props.attributes ) )
], getContentAlignmentClasses( props.attributes, 'column', instanceId ) )

return (
<>
Expand Down
5 changes: 4 additions & 1 deletion src/block/horizontal-scroller/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
withBlockWrapperIsHovered,
withQueryLoopContext,
} from '~stackable/higher-order'
import { useQueryLoopInstanceId } from '~stackable/util'

/**
* WordPress dependencies
Expand Down Expand Up @@ -81,11 +82,13 @@ const Edit = props => {
columnTooltipClass,
] )

const instanceId = useQueryLoopInstanceId( props.attributes.uniqueId )

const contentClassNames = classnames( [
'stk-inner-blocks',
blockAlignmentClass,
'stk-block-content',
], getContentAlignmentClasses( props.attributes, 'horizontal-scroller' ), {
], getContentAlignmentClasses( props.attributes, 'horizontal-scroller', instanceId ), {
'stk--with-scrollbar': showScrollbar,
} )

Expand Down

0 comments on commit 224a9b0

Please sign in to comment.