Skip to content

Commit

Permalink
Remove the default columns setting as we don't have access to innerBl…
Browse files Browse the repository at this point in the history
…ocks at the point that the block validation is run
  • Loading branch information
Glen Davies committed Nov 4, 2020
1 parent 53cf527 commit 4d95e95
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
8 changes: 7 additions & 1 deletion packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function GalleryEdit( props ) {
const {
linkTarget,
linkTo,
columns = defaultColumnsNumber( images ),
columns,
sizeSlug,
imageUploads,
imageCrop,
Expand Down Expand Up @@ -122,6 +122,12 @@ function GalleryEdit( props ) {
return newImages;
} );

useEffect( () => {
if ( ! columns && images.length > 0 ) {
setAttributes( { columns: defaultColumnsNumber( images ) } );
}
}, [ images, columns ] );

const imageSizeOptions = useImageSizes( images, isSelected, getSettings );

const { replaceInnerBlocks, updateBlockAttributes } = useDispatch(
Expand Down
13 changes: 1 addition & 12 deletions packages/block-library/src/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
import { useRef, useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import { defaultColumnsNumber } from './shared';

export const Gallery = ( props ) => {
const {
attributes,
Expand All @@ -28,15 +23,9 @@ export const Gallery = ( props ) => {
mediaPlaceholder,
insertBlocksAfter,
blockProps,
images,
} = props;

const {
align,
columns = defaultColumnsNumber( images ),
caption,
imageCrop,
} = attributes;
const { align, columns, caption, imageCrop } = attributes;
const galleryRef = useRef();
const innerBlocksProps = useInnerBlocksProps(
{
Expand Down
18 changes: 2 additions & 16 deletions packages/block-library/src/gallery/save.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { RichText, useBlockProps, InnerBlocks } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { defaultColumnsNumber } from './shared';

export default function save( { attributes, innerBlocks } ) {
const {
columns = defaultColumnsNumber( innerBlocks ),
imageCrop,
caption,
} = attributes;
export default function save( { attributes } ) {
const { columns, imageCrop, caption } = attributes;
const className = `columns-${ columns } ${ imageCrop ? 'is-cropped' : '' }`;

return (
Expand Down

0 comments on commit 4d95e95

Please sign in to comment.