Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ensure zero and empty width values are treated as though no custom wi…
…dth is specified
  • Loading branch information
andrewserong committed May 27, 2021
commit 6ca4fdecaea0370f96c643cd16a43bf42d1f533d
11 changes: 11 additions & 0 deletions packages/block-library/src/columns/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,15 @@ describe( 'getColumnWidthsAsFrUnits', () => {
const result = getColumnWidthsAsFrUnits( [] );
expect( result ).toBe( '' );
} );

it( 'treats 0 or empty widths as though no custom width is specified', () => {
const blocks = [
{ clientId: 'a', attributes: { width: 0 } },
{ clientId: 'b', attributes: { width: '' } },
{ clientId: 'c', attributes: { width: 33.33 } },
];

const result = getColumnWidthsAsFrUnits( blocks );
expect( result ).toBe( '1fr 1fr 1fr' );
} );
} );
2 changes: 1 addition & 1 deletion packages/block-library/src/columns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function getColumnWidthsAsFrUnits( blocks ) {
getEffectiveColumnWidth( block, blocks.length )
);
const fractions = percentageWidths.map( ( width ) =>
toWidthPrecision( ( width / 100 ) * blocks.length )
width ? toWidthPrecision( ( width / 100 ) * blocks.length ) : 1
);
let fractionsString = '';

Expand Down