Skip to content

Commit

Permalink
feat: minColumnWidth prop for KVP (#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgylobko authored Dec 12, 2024
1 parent 52a1b25 commit 31c3798
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions pages/key-value-pairs/permutations.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ const permutations = createPermutations<KeyValuePairsProps>([
},
{
columns: [4],
minColumnWidth: [undefined, 500],
items: [
[
{
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9474,6 +9474,17 @@ Each group definition has the following properties:
"optional": false,
"type": "ReadonlyArray<KeyValuePairsProps.Item>",
},
{
"defaultValue": "150",
"description": "Use 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.
If not set, defaults to 150.
",
"name": "minColumnWidth",
"optional": true,
"type": "number",
},
],
"regions": [],
"releaseStatus": "stable",
Expand Down
10 changes: 9 additions & 1 deletion src/key-value-pairs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import InternalKeyValuePairs from './internal';

export { KeyValuePairsProps };

export default function KeyValuePairs({ columns = 1, items, ariaLabel, ariaLabelledby, ...rest }: KeyValuePairsProps) {
export default function KeyValuePairs({
columns = 1,
items,
ariaLabel,
ariaLabelledby,
minColumnWidth = 150,
...rest
}: KeyValuePairsProps) {
const { __internalRootRef } = useBaseComponent('KeyValuePairs', {
props: { columns },
});
Expand All @@ -22,6 +29,7 @@ export default function KeyValuePairs({ columns = 1, items, ariaLabel, ariaLabel
items={items}
ariaLabel={ariaLabel}
ariaLabelledby={ariaLabelledby}
minColumnWidth={minColumnWidth}
{...baseProps}
ref={__internalRootRef}
/>
Expand Down
9 changes: 9 additions & 0 deletions src/key-value-pairs/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export interface KeyValuePairsProps extends BaseComponentProps {
* Don't use `ariaLabel` and `ariaLabelledby` at the same time.
*/
ariaLabelledby?: string;

/**
* Use 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.
* If not set, defaults to 150.
*/
minColumnWidth?: number;
}

export namespace KeyValuePairsProps {
Expand Down
8 changes: 7 additions & 1 deletion src/key-value-pairs/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const InternalKeyValuePairs = React.forwardRef(
className,
ariaLabel,
ariaLabelledby,
minColumnWidth,
...rest
}: KeyValuePairsProps & Required<Pick<KeyValuePairsProps, 'columns'>>,
ref: React.Ref<HTMLDivElement>
Expand All @@ -62,7 +63,12 @@ const InternalKeyValuePairs = React.forwardRef(
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
*/}
<ColumnLayout __tagOverride="dl" columns={Math.min(columns, 4)} variant="text-grid" minColumnWidth={150}>
<ColumnLayout
__tagOverride="dl"
columns={Math.min(columns, 4)}
variant="text-grid"
minColumnWidth={minColumnWidth}
>
{items.map((pair, index) => {
if (pair.type === 'group') {
return (
Expand Down

0 comments on commit 31c3798

Please sign in to comment.