From f205b4d54e762b0691e2511cb93a6313b55f18b5 Mon Sep 17 00:00:00 2001 From: Vikas Gajanan Kale Date: Thu, 19 Nov 2026 12:11:52 +0100 Subject: [PATCH 1/2] Revert "feat: Enabled support for more than 4 columns for key-value pair (#5081)" This reverts commit ddb08abfdcecab66472ea318237f58b0fa1e34eb. --- pages/key-value-pairs/permutations.page.tsx | 10 ------ .../__snapshots__/documenter.test.ts.snap | 10 ++---- .../__tests__/key-value-pairs.test.tsx | 34 ++++++++----------- src/key-value-pairs/interfaces.ts | 8 ++--- src/key-value-pairs/internal.tsx | 25 ++++++++++---- 5 files changed, 39 insertions(+), 48 deletions(-) diff --git a/pages/key-value-pairs/permutations.page.tsx b/pages/key-value-pairs/permutations.page.tsx index 440669b0a11..deb2bde5056 100644 --- a/pages/key-value-pairs/permutations.page.tsx +++ b/pages/key-value-pairs/permutations.page.tsx @@ -393,16 +393,6 @@ const permutations = createPermutations([ ], ], }, - { - columns: [5, 6], - minColumnWidth: [undefined, 100], - items: [ - Array.from({ length: 7 }, (_, i) => ({ - label: `Label for key ${i + 1}`, - value: `Value ${i + 1}`, - })), - ], - }, ]); export default function KeyValueScenario() { diff --git a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap index b369da37cbd..b58f6442aff 100644 --- a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap +++ b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap @@ -18715,9 +18715,8 @@ Don't use \`ariaLabel\` and \`ariaLabelledby\` at the same time.", }, { "defaultValue": "1", - "description": "Specifies the number of columns in each grid row. It defaults to 1. - -The number of columns is reduced as the available space narrows, based on \`minColumnWidth\`.", + "description": "Specifies the number of columns in each grid row. +Valid values are any integer between 1 and 4. It defaults to 1.", "name": "columns", "optional": true, "type": "number", @@ -18757,10 +18756,7 @@ Each group definition has the following properties: The number of columns is determined by the value of this property, the available space, and the maximum number of columns as defined by the \`columns\` property. -If not set, defaults to 150. - -While reducing the count, odd numbers are skipped, so 5 columns becomes 4 and then 2. -A requested odd count is kept when it fits.", +If not set, defaults to 150.", "name": "minColumnWidth", "optional": true, "type": "number", diff --git a/src/key-value-pairs/__tests__/key-value-pairs.test.tsx b/src/key-value-pairs/__tests__/key-value-pairs.test.tsx index db54a7cd3e7..d75250c16e9 100644 --- a/src/key-value-pairs/__tests__/key-value-pairs.test.tsx +++ b/src/key-value-pairs/__tests__/key-value-pairs.test.tsx @@ -106,26 +106,22 @@ describe('KeyValuePairs', () => { }); }); - describe('columns property', () => { - test.each([1, 2, 3, 4, 5, 6, 12])('does not warn when columns is set to %i', columns => { + describe('warnOnce when columns property exceeds max', () => { + test.each([ + { columns: 1, warnOnceMessage: false }, + { columns: 2, warnOnceCalled: false }, + { + columns: 3, + warnOnceCalled: false, + }, + { columns: 4, warnOnceCalled: false }, + { + columns: 5, + warnOnceCalled: true, + }, + ])(`warnOnce called = $warnOnceCalled when columns is set to $columns`, ({ columns, warnOnceCalled }) => { renderKeyValuePairs(); - expect(warnOnce).not.toHaveBeenCalled(); - }); - - // Asserts the resolved grid rather than the number of items, because every item renders either - // way - test.each([3, 6, 12])('lays out %i columns', columns => { - const { wrapper } = renderKeyValuePairs( - ({ - label: `Label ${index}`, - value: `Value ${index}`, - }))} - /> - ); - - expect(wrapper.find('dl')!.getElement().style.gridTemplateColumns).toBe(`repeat(${columns}, minmax(0, 1fr))`); + expect(warnOnce).toHaveBeenCalledTimes(warnOnceCalled ? 1 : 0); }); }); diff --git a/src/key-value-pairs/interfaces.ts b/src/key-value-pairs/interfaces.ts index 23192ea6d44..d7431872084 100644 --- a/src/key-value-pairs/interfaces.ts +++ b/src/key-value-pairs/interfaces.ts @@ -6,9 +6,8 @@ import { BaseComponentProps } from '../types/base-component'; export interface KeyValuePairsProps extends BaseComponentProps { /** - * Specifies the number of columns in each grid row. It defaults to 1. - * - * The number of columns is reduced as the available space narrows, based on `minColumnWidth`. + * Specifies the number of columns in each grid row. + * Valid values are any integer between 1 and 4. It defaults to 1. */ columns?: number; /** @@ -47,9 +46,6 @@ export interface KeyValuePairsProps extends BaseComponentProps { * The number of columns is determined by the value of this property, the available space, * and the maximum number of columns as defined by the `columns` property. * If not set, defaults to 150. - * - * While reducing the count, odd numbers are skipped, so 5 columns becomes 4 and then 2. - * A requested odd count is kept when it fits. */ minColumnWidth?: number; } diff --git a/src/key-value-pairs/internal.tsx b/src/key-value-pairs/internal.tsx index ccb3fb1f21f..318a8ff02bb 100644 --- a/src/key-value-pairs/internal.tsx +++ b/src/key-value-pairs/internal.tsx @@ -3,7 +3,7 @@ import React from 'react'; import clsx from 'clsx'; -import { useUniqueId } from '@cloudscape-design/component-toolkit/internal'; +import { useUniqueId, warnOnce } from '@cloudscape-design/component-toolkit/internal'; import Box from '../box/internal'; import ColumnLayout from '../column-layout/internal'; @@ -48,9 +48,18 @@ const InternalKeyValuePairs = React.forwardRef( ariaLabelledby, minColumnWidth, ...rest - }: KeyValuePairsProps & Required>, + }: KeyValuePairsProps & Required>, ref: React.Ref ) => { + const MAX_COLUMNS = 4; + + if (columns > MAX_COLUMNS) { + warnOnce( + 'Key-value pairs', + `\`columns\` (${columns}) must be <= ${MAX_COLUMNS}. Using ${MAX_COLUMNS} as default.` + ); + } + return (
{/* - A minColumnWidth is always passed (KeyValuePairs defaults it to 150) so that ColumnLayout - picks FlexibleColumnLayout, which wraps each column item in a single div. GridColumnLayout - wraps in two, which breaks the dl -> dt/dd relationship a11y relies on. + minColumnWidth={150} is set to use FlexibleColumnLayout which has only 1 nested div wrapper for column items, + otherwise GridColumnLayout will be used, which has 2 nested div, therefore it is not a11y compatible for dl -> dt/dd relationship */} - + {items.map((pair, index) => { if (pair.type === 'group') { return ( From f4ba7e4b0dc1cc4d88c9c4c757d3502391f5ea22 Mon Sep 17 00:00:00 2001 From: Vikas Gajanan Kale Date: Thu, 19 Nov 2026 12:11:59 +0100 Subject: [PATCH 2/2] Revert "feat: Added support for more than 4 columns for column-layout component (#5086)" This reverts commit 16758dddac65a2ca11713bacc2639c9c0a5f877e. --- pages/column-layout/permutations.page.tsx | 10 ----- .../__snapshots__/documenter.test.ts.snap | 16 ++------ .../__tests__/column-layout.test.tsx | 25 +++++++----- src/column-layout/__tests__/util.test.ts | 40 +------------------ src/column-layout/__tests__/with-css.test.tsx | 36 ----------------- .../flexible-column-layout/index.tsx | 11 +---- src/column-layout/interfaces.ts | 14 +------ src/column-layout/internal.tsx | 21 +++++++--- 8 files changed, 40 insertions(+), 133 deletions(-) diff --git a/pages/column-layout/permutations.page.tsx b/pages/column-layout/permutations.page.tsx index c1b67e94690..d65f9ac5c96 100644 --- a/pages/column-layout/permutations.page.tsx +++ b/pages/column-layout/permutations.page.tsx @@ -26,16 +26,6 @@ const permutations = createPermutations([ variant: ['text-grid'], columns: [1, 2, 3, 4], }, - // Above 4 columns, ColumnLayout renders through FlexibleColumnLayout instead of - // GridColumnLayout, so these permutations cover that second renderer. - { - variant: ['default'], - columns: [5, 7], - }, - { - variant: ['text-grid'], - columns: [5, 6], - }, ]); export default function ColumnLayoutPermutationsPage() { diff --git a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap index b58f6442aff..a4006166822 100644 --- a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap +++ b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap @@ -10511,7 +10511,7 @@ exports[`Components definition for column-layout matches the snapshot: column-la "defaultValue": "'none'", "description": "Controls whether dividers are placed between rows and columns. -Note: This is not supported when used with \`minColumnWidth\`, or with more than 4 columns.", +Note: This is not supported when used with \`minColumnWidth\`.", "inlineType": { "name": "ColumnLayoutProps.Borders", "type": "union", @@ -10536,14 +10536,7 @@ Note: This is not supported when used with \`minColumnWidth\`, or with more than { "defaultValue": "1", "description": "Specifies the number of columns in each grid row. - -The number of columns is reduced as the available space narrows. One of two layout systems is -used, and which one applies determines how that reduction works: - * Grid - used for up to 4 columns when \`minColumnWidth\` is not set. Columns are reduced at - fixed breakpoints, to 2 and then to 1 as the container narrows. \`borders\` are supported. - * Flexible grid - used in all other cases. Columns are reduced based on the available width - and the desired column width, which is \`minColumnWidth\` when set and 150px otherwise. - \`borders\` are not supported.", +When \`minColumnWidth\` is not set, only up to 4 columns are supported.", "name": "columns", "optional": true, "type": "number", @@ -10568,10 +10561,7 @@ use the \`id\` attribute, consider setting it on a parent element instead.", "description": "Use together with \`columns\` to specify the desired minimum width for each column in pixels. The number of columns is determined by the value of this property, the available space, -and the maximum number of columns as defined by the \`columns\` property. - -While reducing the count, odd numbers are skipped, so 5 columns becomes 4 and then 2. -A requested odd count is kept when it fits.", +and the maximum number of columns as defined by the \`columns\` property.", "name": "minColumnWidth", "optional": true, "type": "number", diff --git a/src/column-layout/__tests__/column-layout.test.tsx b/src/column-layout/__tests__/column-layout.test.tsx index 5bc5cc0bb14..f31e54e4fbc 100644 --- a/src/column-layout/__tests__/column-layout.test.tsx +++ b/src/column-layout/__tests__/column-layout.test.tsx @@ -8,7 +8,6 @@ import { warnOnce } from '@cloudscape-design/component-toolkit/internal'; import ColumnLayout, { ColumnLayoutProps } from '../../../lib/components/column-layout'; import createWrapper from '../../../lib/components/test-utils/dom'; -import cssGridStyles from '../../../lib/components/column-layout/flexible-column-layout/styles.css.js'; import styles from '../../../lib/components/column-layout/styles.css.js'; jest.mock('@cloudscape-design/component-toolkit/internal', () => ({ @@ -35,23 +34,29 @@ describe('ColumnLayout component', () => { [2, 3, 4].forEach(columnCount => { it(`can have ${columnCount} columns`, () => { - const wrapper = renderColumnLayout({ columns: columnCount }); + const wrapper = renderColumnLayout({ columns: columnCount as 2 | 3 | 4 }); expect(wrapper.getElement()).toHaveClass(styles[`grid-columns-${columnCount}`]); }); }); - [5, 6, 12].forEach(columnCount => { - it(`renders ${columnCount} columns through FlexibleColumnLayout`, () => { - const { container } = render(); - // Above 4 columns, GridColumnLayout must not be used: findGrid() targets its root. - expect(createWrapper(container).findGrid()).toBeNull(); - expect(container.querySelector(`.${cssGridStyles['css-grid']}`)).not.toBeNull(); + [1, 2, 3, 4].forEach(columnCount => { + it(`does not warn for ${columnCount} columns`, () => { + render(); + expect(warnOnce).not.toHaveBeenCalled(); }); }); - [1, 4, 5, 12, 20].forEach(columnCount => { - it(`does not warn for ${columnCount} columns`, () => { + [5, 6, 10, 12].forEach(columnCount => { + it(`warns that ${columnCount} columns is unsupported without minColumnWidth`, () => { render(); + expect(warnOnce).toHaveBeenCalledWith( + 'ColumnLayout', + expect.stringContaining(`\`columns\` (${columnCount}) is not supported without \`minColumnWidth\``) + ); + }); + + it(`does not warn for ${columnCount} columns when minColumnWidth is set`, () => { + render(); expect(warnOnce).not.toHaveBeenCalled(); }); }); diff --git a/src/column-layout/__tests__/util.test.ts b/src/column-layout/__tests__/util.test.ts index 4598a22dd0a..84013aa27cf 100644 --- a/src/column-layout/__tests__/util.test.ts +++ b/src/column-layout/__tests__/util.test.ts @@ -1,9 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - calculcateCssColumnCount, - DEFAULT_MIN_COLUMN_WIDTH, -} from '../../../lib/components/column-layout/flexible-column-layout'; +import { calculcateCssColumnCount } from '../../../lib/components/column-layout/flexible-column-layout'; describe('ColumnLayout calculcateCssColumnCount', () => { it('returns desired number of columns when container width is not defined', () => { @@ -29,7 +26,7 @@ describe('ColumnLayout calculcateCssColumnCount', () => { expect(calculcateCssColumnCount(3, 200, 220)).toBe(1); }); - it('supports more than 4 columns when minColumnWidth is set', () => { + it('supports more than 4 columns', () => { // all fit into 10 columns expect(calculcateCssColumnCount(10, 50, 900)).toBe(10); @@ -39,36 +36,3 @@ describe('ColumnLayout calculcateCssColumnCount', () => { expect(calculcateCssColumnCount(10, 50, 90)).toBe(1); }); }); - -describe('ColumnLayout column count with the assumed default width', () => { - // Mirrors what the renderer does when `minColumnWidth` is not set: the same calculation runs with - // DEFAULT_MIN_COLUMN_WIDTH supplied in its place, so there is one reduction rule, not two. - const withDefault = (columns: number, containerWidth: number | null) => - calculcateCssColumnCount(columns, DEFAULT_MIN_COLUMN_WIDTH, containerWidth); - - it('renders the requested count before the container has been measured', () => { - expect(withDefault(12, null)).toBe(12); - expect(withDefault(5, null)).toBe(5); - }); - - it('steps the count down as the container narrows', () => { - expect(withDefault(12, 1840)).toBe(12); - expect(withDefault(12, 1200)).toBe(8); - expect(withDefault(12, 1000)).toBe(6); - expect(withDefault(12, 700)).toBe(4); - expect(withDefault(12, 450)).toBe(2); - expect(withDefault(12, 300)).toBe(2); - expect(withDefault(12, 140)).toBe(1); - }); - - it('skips odd counts while reducing, so 13 items wrap as 12-1, 8-5, 6-6-1, then 4-4-4-1', () => { - // floor(750/150) is 5 and floor(1100/150) is 7, both rounded down to the next even count. - expect(withDefault(12, 750)).toBe(4); - expect(withDefault(12, 1100)).toBe(6); - }); - - it('leaves an odd requested count alone when it fits', () => { - expect(withDefault(5, 800)).toBe(5); - expect(withDefault(7, 1100)).toBe(7); - }); -}); diff --git a/src/column-layout/__tests__/with-css.test.tsx b/src/column-layout/__tests__/with-css.test.tsx index a26d102c0a7..fafa13f9388 100644 --- a/src/column-layout/__tests__/with-css.test.tsx +++ b/src/column-layout/__tests__/with-css.test.tsx @@ -59,40 +59,4 @@ describe('ColumnLayout (with CSS grid) component', () => { expect(getGridColumns()).toBe('repeat(4, minmax(0, 1fr))'); }); - - it('supports more than 4 columns', () => { - const { getGridColumns } = renderColumnLayout({ - minColumnWidth: 100, - columns: 5, - children: Array.from({ length: 5 }, (_, i) =>
), - }); - - expect(getGridColumns()).toBe('repeat(5, minmax(0, 1fr))'); - }); - - it('marks the first item of each row above 4 columns', () => { - // 5 columns, 7 items: row 1 is items 0-4, row 2 is items 5-6. - const { wrapper } = renderColumnLayout({ - minColumnWidth: 100, - columns: 5, - children: Array.from({ length: 7 }, (_, i) =>
), - }); - - const firstColumnIndexes = wrapper - .findAll(`.${styles.item}`) - .map((item, i) => (item.getElement().classList.contains(styles['first-column']) ? i : -1)) - .filter(i => i !== -1); - - expect(firstColumnIndexes).toEqual([0, 5]); - }); - - it('collapses responsively without minColumnWidth', () => { - // The mocked container width of 500 resolves to the xxs breakpoint, which caps at 2 columns. - const { getGridColumns } = renderColumnLayout({ - columns: 5, - children: Array.from({ length: 5 }, (_, i) =>
), - }); - - expect(getGridColumns()).toBe('repeat(2, minmax(0, 1fr))'); - }); }); diff --git a/src/column-layout/flexible-column-layout/index.tsx b/src/column-layout/flexible-column-layout/index.tsx index 4e257beea29..ef4fffb6bf6 100644 --- a/src/column-layout/flexible-column-layout/index.tsx +++ b/src/column-layout/flexible-column-layout/index.tsx @@ -31,24 +31,17 @@ export function calculcateCssColumnCount( ); } -/** - * Column width assumed when `minColumnWidth` is not set. Without a value to divide the container - * width by, the count could not be reduced at all, so the layout would keep every requested column - * at any width. Matches the default KeyValuePairs passes to this renderer. - */ -export const DEFAULT_MIN_COLUMN_WIDTH = 150; - interface FlexibleColumnLayoutProps extends Pick< InternalColumnLayoutProps, - 'minColumnWidth' | 'columns' | 'variant' | 'disableGutters' | '__tagOverride' + 'minColumnWidth' | 'columns' | 'variant' | 'borders' | 'disableGutters' | '__tagOverride' > { children: React.ReactNode; } export default function FlexibleColumnLayout({ columns = 1, - minColumnWidth = DEFAULT_MIN_COLUMN_WIDTH, + minColumnWidth = 0, disableGutters, variant, children, diff --git a/src/column-layout/interfaces.ts b/src/column-layout/interfaces.ts index 1caf98a0048..43a392e9b38 100644 --- a/src/column-layout/interfaces.ts +++ b/src/column-layout/interfaces.ts @@ -7,14 +7,7 @@ import { BaseComponentProps } from '../types/base-component'; export interface ColumnLayoutProps extends BaseComponentProps { /** * Specifies the number of columns in each grid row. - * - * The number of columns is reduced as the available space narrows. One of two layout systems is - * used, and which one applies determines how that reduction works: - * * Grid - used for up to 4 columns when `minColumnWidth` is not set. Columns are reduced at - * fixed breakpoints, to 2 and then to 1 as the container narrows. `borders` are supported. - * * Flexible grid - used in all other cases. Columns are reduced based on the available width - * and the desired column width, which is `minColumnWidth` when set and 150px otherwise. - * `borders` are not supported. + * When `minColumnWidth` is not set, only up to 4 columns are supported. */ columns?: number; @@ -26,7 +19,7 @@ export interface ColumnLayoutProps extends BaseComponentProps { /** * Controls whether dividers are placed between rows and columns. * - * Note: This is not supported when used with `minColumnWidth`, or with more than 4 columns. + * Note: This is not supported when used with `minColumnWidth`. */ borders?: ColumnLayoutProps.Borders; @@ -40,9 +33,6 @@ export interface ColumnLayoutProps extends BaseComponentProps { * * The number of columns is determined by the value of this property, the available space, * and the maximum number of columns as defined by the `columns` property. - * - * While reducing the count, odd numbers are skipped, so 5 columns becomes 4 and then 2. - * A requested odd count is kept when it fits. */ minColumnWidth?: number; diff --git a/src/column-layout/internal.tsx b/src/column-layout/internal.tsx index 53380cbaf06..62d87263eb0 100644 --- a/src/column-layout/internal.tsx +++ b/src/column-layout/internal.tsx @@ -3,6 +3,8 @@ import React from 'react'; import clsx from 'clsx'; +import { warnOnce } from '@cloudscape-design/component-toolkit/internal'; + import { getBaseProps } from '../internal/base-component'; import FlexibleColumnLayout from './flexible-column-layout'; import GridColumnLayout from './grid-column-layout'; @@ -14,10 +16,10 @@ export const COLUMN_TRIGGERS = ['default', 'xxs', 'xs'] as const; export type ColumnLayoutBreakpoint = (typeof COLUMN_TRIGGERS)[number] | null; /** - * The 12-column grid renderer can only express column counts that divide 12 evenly, and its - * divider styles are generated per count. Anything above this uses the CSS grid renderer instead. + * Highest `columns` value supported without `minColumnWidth`, as stated in the `columns` docs. + * The grid renderer's column definitions only cover 1 to 4. */ -export const MAX_GRID_COLUMNS = 4; +const MAX_SUPPORTED_COLUMNS = 4; /** * A responsive grid layout. @@ -36,13 +38,22 @@ export default function ColumnLayout({ }: InternalColumnLayoutProps) { const baseProps = getBaseProps(restProps); - const useCssGrid = Boolean(minColumnWidth) || columns > MAX_GRID_COLUMNS; + // this combination type-checks is outside the documented contract and renders + // unexpected behavior: the grid renderer has no column definition above + // MAX_SUPPORTED_COLUMNS + if (columns > MAX_SUPPORTED_COLUMNS && !minColumnWidth) { + warnOnce( + 'ColumnLayout', + `\`columns\` (${columns}) is not supported without \`minColumnWidth\`: only up to ${MAX_SUPPORTED_COLUMNS} columns are supported, so the value is ignored and the columns are sized by their content instead. Set \`minColumnWidth\`, or use ${MAX_SUPPORTED_COLUMNS} columns or fewer.` + ); + } return (
- {useCssGrid ? ( + {minColumnWidth ? (