Skip to content

Conversation

@khadesamrudhi
Copy link

This PR adds the previously removed widths prop to <ToolbarItem /> and introduces a new flexGrow prop that maps to .pf-m-flex-grow[on-{breakpoint}] modifiers.

Changes

  • Added responsive widths and flexGrow support using formatBreakpointMods
  • Updated unit tests to verify classnames
  • All ToolbarItem tests passing ✅

Closes #11910

@patternfly-build
Copy link
Collaborator

patternfly-build commented Oct 20, 2025

@khadesamrudhi khadesamrudhi changed the title fix(ToolbarItem): add width and flex-grow props and handle breakpoint… fix(Toolbar): add width and flex-grow props to ToolbarItem; add flex-grow to ToolbarGroup; update demo and tests Oct 23, 2025
@khadesamrudhi
Copy link
Author

khadesamrudhi commented Oct 23, 2025

First-time contributor, could a maintainer please approve workflows and re-run the failed job?

Notes:

  • The TypeScript parse error in packages/tsconfig.base.json was fixed.
  • Remaining failure is a transient Surge preview upload DNS error (EAI_AGAIN), unrelated to code changes.
  • Changes are limited to ToolbarItem widths + flexGrow, ToolbarGroup flexGrow, tests, demo, and types/global.d.ts.

Thanks!

@mcoker @kmcfaul @thatblindgeye

@khadesamrudhi
Copy link
Author

I’ve fixed the packages/tsconfig.base.json JSON issue and pushed the update. Could you please approve the workflows and re-run the CI? If Surge preview shows EAI_AGAIN, it indicates a transient network error that we can retry. Thanks!

@khadesamrudhi
Copy link
Author

Hi, all automated checks have passed.
Requesting a review when convenient.
Please let me know if any additional changes are needed. Thank you.
@mcoker @thatblindgeye @kmcfaul

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments below. Additionally, there are several files updates not related to the issue. If those updates aren't necessary for the flexGrow and widths updates being made here, I might suggest pulling those out in favor of a separate issue (if they're more enhancements you feel would be good for the codebase for example)

Comment on lines 246 to 261
widths &&
Object.entries(widths).reduce(
(acc, [bp, size]) => ({
...acc,
[`pf-m-w-${size}${bp !== 'default' ? `-on-${bp}` : ''}`]: true
}),
{}
),
flexGrow &&
Object.entries(flexGrow).reduce(
(acc, [bp]) => ({
...acc,
[`pf-m-flex-grow${bp !== 'default' ? `-on-${bp}` : ''}`]: true
}),
{}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, we should be able to just use our formatBreakpointMods util function instead

Copy link
Contributor

@thatblindgeye thatblindgeye Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an addendum to this, we should use the formatBreakpointMods function for the flexGrow here, but for handling applying the widths prop we should basically just add back in what was removed in this React PR https://github.com/patternfly/patternfly-react/pull/10022/files#diff-7beeea05e52252eb360f045d661fab89fe634b00becfd8a3dbaa48338c6032c0 (we want to apply a styles object rather than a class)

@@ -0,0 +1,40 @@
import { useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an intention to add Cypress tests for this demo? Not entirely sure we need one to test the new props, so my feeling is we could remove this demo file and revert the changes made to the ToolbarDemo/ToolbarDemo.tsx file.

Comment on lines +14 to +18
describe('ToolbarGroup flexGrow', () => {
const bps = ['default', 'sm', 'md', 'lg', 'xl', '2xl'];

describe.each(bps)('flexGrow at various breakpoints', (bp) => {
it(`should render with pf-m-flex-grow when flexGrow is set at ${bp}`, () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically use the describe block a bit more rarely in our codebase, in this case I'm not sure we should use it. Instead what we could do is put the breakpoints variable as a global var or within the first describe('ToolbarGroup' ... block, then:

  • Move the flexGrow and widths tests inside that block
  • remove the nested describe blocks being used here
  • instead, just run a forEach over the breakpoints array and call the tests in this forEach block

We do something similar in some of our unit test files, such as our Button tests:

Object.values(ButtonVariant).forEach((variant) => {
if (variant !== 'primary') {
test(`Does not render with class ${styles.modifiers[variant]} by default`, () => {
render(<Button>Not {variant} Button</Button>);
expect(screen.getByRole('button')).not.toHaveClass(styles.modifiers[variant]);
});
}
test(`Renders with class ${styles.modifiers[variant]} when variant=${variant}`, () => {
render(<Button variant={variant}>{variant} Button</Button>);
expect(screen.getByRole('button')).toHaveClass(styles.modifiers[variant]);
});
});

khadesamrudhi and others added 3 commits November 9, 2025 11:44
… flexGrow via formatBreakpointMods; update ToolbarItem tests; remove extra demo
… flexGrow via formatBreakpointMods; update JSDoc and tests
@khadesamrudhi
Copy link
Author

Pushed updates to fix review feedback:

  • ToolbarItem: widths applied via setBreakpointCssVars using base token c_toolbar__item_Width; flexGrow via formatBreakpointMods; removed hardcoded data-testid; JSDoc clarifies flexGrow=1.
  • ToolbarGroup: flexGrow via formatBreakpointMods; JSDoc updated.
  • Tests: ToolbarItem width tests assert CSS var per breakpoint.

No extra demo files included.
Previous CI errors from missing react-tokens imports should be resolved. Could you please approve the workflow run so CI can proceed?

@thatblindgeye @mcoker @kmcfaul

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more change requests below. Also looks like there's still some unrelated file updates being made:

  • .yarnrc.yml should be reverted
  • cleanup.js should be removed
  • eslint.config.mjs should be reverted
  • packager.json should be reverted
  • ToolbarDemo.tsx should be reverted
  • tsconfig.base.json should be reverted
  • build-single-packages.mjs should be reverted
  • global.d.ts should be removed

The updates/additions of those files shouldn't be necessary for this PR

Comment on lines +250 to +276
style={{
...style,
...(widths
? setBreakpointCssVars(
Object.entries(widths).reduce(
(acc, [bp, size]) => {
if (!size) {
return acc;
}
const cssVarValueMap: Record<string, string> = {
sm: 'var(--pf-c-toolbar__item--m-w-sm--Width)',
md: 'var(--pf-c-toolbar__item--m-w-md--Width)',
lg: 'var(--pf-c-toolbar__item--m-w-lg--Width)',
xl: 'var(--pf-c-toolbar__item--m-w-xl--Width)',
'2xl': 'var(--pf-c-toolbar__item--m-w-2xl--Width)',
'3xl': 'var(--pf-c-toolbar__item--m-w-3xl--Width)',
'4xl': 'var(--pf-c-toolbar__item--m-w-4xl--Width)'
};
const value = cssVarValueMap[size as keyof typeof cssVarValueMap];
return value ? { ...acc, [bp]: value } : acc;
},
{} as Record<string, string>
),
(c_toolbar__item_Width as any).name
)
: undefined)
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the above comment, we'll need to tweak this and we can simplify it a bit :

Suggested change
style={{
...style,
...(widths
? setBreakpointCssVars(
Object.entries(widths).reduce(
(acc, [bp, size]) => {
if (!size) {
return acc;
}
const cssVarValueMap: Record<string, string> = {
sm: 'var(--pf-c-toolbar__item--m-w-sm--Width)',
md: 'var(--pf-c-toolbar__item--m-w-md--Width)',
lg: 'var(--pf-c-toolbar__item--m-w-lg--Width)',
xl: 'var(--pf-c-toolbar__item--m-w-xl--Width)',
'2xl': 'var(--pf-c-toolbar__item--m-w-2xl--Width)',
'3xl': 'var(--pf-c-toolbar__item--m-w-3xl--Width)',
'4xl': 'var(--pf-c-toolbar__item--m-w-4xl--Width)'
};
const value = cssVarValueMap[size as keyof typeof cssVarValueMap];
return value ? { ...acc, [bp]: value } : acc;
},
{} as Record<string, string>
),
(c_toolbar__item_Width as any).name
)
: undefined)
}}
style={{
...style,
...(widths ? setBreakpointCssVars(widths, c_toolbar__item_Width.name) : undefined)
}}

Out of curiosity, where did the --pf-c-toolbar__item--m-w-xl--Width etc strings come from?

Comment on lines +23 to +28
default?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
sm?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
md?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
lg?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
xl?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
'2xl'?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this prop, we want the types to be just string, e.g. default?: string, as the expectation is that a consumer would pass a unit value for this prop like widths={{sm: '3rem'}} rather than us setting a token.

Suggested change
default?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
sm?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
md?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
lg?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
xl?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
'2xl'?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
default?: string;
sm?: string;
md?: string;
lg?: string;
xl?: string;
'2xl'?: string;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToolbarItem - props for width and flex-grow

3 participants