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
Contributor

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)

{...(variant === 'label' && { 'aria-hidden': true })}
id={id}
role={role}
data-testid="toolbaritem"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about hardcoding a testid in, since there could be many items on a page, and a testid should be able to be passed with the spread props line below this.

xl?: 'wrap' | 'nowrap';
'2xl'?: 'wrap' | 'nowrap';
};
/** Flex grow modifier at various breakpoints */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** Flex grow modifier at various breakpoints */
/** Indicates whether a flex grow modifier of 1 is applied at various breakpoints */

Small nit to the description, just to make it clear that it's currently a hardcoded flex grow modifier rather than something more customizable.

Comment on lines +234 to +241
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.

Rather than this, we can just use our formateBreakpointMods util function

xl?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
'2xl'?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
};
/** Flex grow modifier at various breakpoints */
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar nit here for prop description as above

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]);
});
});

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