Skip to content

Commit

Permalink
fix (button block): autofocus when adding buttons (#3339)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae authored Oct 8, 2024
1 parent de4cb54 commit 1b3c1d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
29 changes: 17 additions & 12 deletions src/block/button-group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
FlexGapControls,
Transform,
} from '~stackable/block-components'
import { useBlockContext, useDeviceType } from '~stackable/hooks'
import { useDeviceType } from '~stackable/hooks'
import {
withBlockAttributeContext,
withBlockWrapperIsHovered,
Expand All @@ -49,6 +49,7 @@ import {
} from '@wordpress/block-editor'
import { sprintf, __ } from '@wordpress/i18n'
import { memo } from '@wordpress/element'
import { useSelect } from '@wordpress/data'

const ALLOWED_INNER_BLOCKS = [ 'stackable/button', 'stackable/icon-button' ]

Expand Down Expand Up @@ -109,7 +110,12 @@ const Edit = props => {
const deviceType = useDeviceType()
const rowClass = getRowClasses( attributes )
const blockAlignmentClass = getAlignmentClasses( attributes )
const { hasInnerBlocks } = useBlockContext()
const { hasInnerBlocks } = useSelect( select => {
const { getBlockOrder } = select( 'core/block-editor' )
return {
hasInnerBlocks: getBlockOrder( props.clientId ).length > 0,
}
}, [ props.clientId ] )

const blockClassNames = classnames( [
className,
Expand Down Expand Up @@ -176,16 +182,15 @@ const Edit = props => {
<CustomCSS mainBlockClass="stk-block-button-group" />

{ ! hasInnerBlocks && <GroupPlaceholder blockName="stackable/button" /> }
{ hasInnerBlocks &&
<div className={ contentClassNames }>
<InnerBlocks
orientation="horizontal"
allowedBlocks={ ALLOWED_INNER_BLOCKS }
template={ TEMPLATE }
templateInsertUpdatesSelection={ true }
/>
</div>
}
<div className={ contentClassNames }>
<InnerBlocks
orientation="horizontal"
allowedBlocks={ ALLOWED_INNER_BLOCKS }
template={ TEMPLATE }
templateInsertUpdatesSelection={ true }
renderAppender={ hasInnerBlocks ? undefined : false }
/>
</div>
</BlockDiv>
{ props.isHovered && hasInnerBlocks && <MarginBottom /> }
</>
Expand Down
7 changes: 1 addition & 6 deletions src/block/button-group/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ const variations = [
'stk-type': 'essential',
'stk-demo': 'https://wpstackable.com/button-block/?utm_source=welcome&utm_medium=settings&utm_campaign=view_demo&utm_content=demolink',
isDefault: true,
innerBlocks: [
[
'stackable/button',
{},
],
],
innerBlocks: [],
example: buttonExample,
},
{
Expand Down

0 comments on commit 1b3c1d0

Please sign in to comment.