-
Notifications
You must be signed in to change notification settings - Fork 373
fix(Toolbar): add width and flex-grow props to ToolbarItem; add flex-grow to ToolbarGroup; update demo and tests #12074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Preview: https://pf-react-pr-12074.surge.sh A11y report: https://pf-react-pr-12074-a11y.surge.sh |
…exGrow; update demo and tests; fix lint
|
First-time contributor, could a maintainer please approve workflows and re-run the failed job? Notes:
Thanks! |
|
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 |
|
Hi, all automated checks have passed. |
There was a problem hiding this 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" |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** 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.
| flexGrow && | ||
| Object.entries(flexGrow).reduce( | ||
| (acc, [bp]) => ({ | ||
| ...acc, | ||
| [`pf-m-flex-grow${bp !== 'default' ? `-on-${bp}` : ''}`]: true | ||
| }), | ||
| {} | ||
| ), |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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
| 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 | ||
| }), | ||
| {} | ||
| ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'; | |||
There was a problem hiding this comment.
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.
| 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}`, () => { |
There was a problem hiding this comment.
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
describeblocks being used here - instead, just run a
forEachover 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:
patternfly-react/packages/react-core/src/components/Button/__tests__/Button.test.tsx
Lines 10 to 22 in 9421a92
| 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]); | |
| }); | |
| }); |
This PR adds the previously removed
widthsprop to<ToolbarItem />and introduces a newflexGrowprop that maps to.pf-m-flex-grow[on-{breakpoint}]modifiers.Changes
widthsandflexGrowsupport usingformatBreakpointModsCloses #11910