Skip to content

Commit b1bd21d

Browse files
committed
add wrap to toolbar content
1 parent 1022e95 commit b1bd21d

File tree

6 files changed

+96
-3
lines changed

6 files changed

+96
-3
lines changed

packages/react-core/src/components/Toolbar/ToolbarContent.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export interface ToolbarContentProps extends React.HTMLProps<HTMLDivElement> {
1616
xl?: 'hidden' | 'visible';
1717
'2xl'?: 'hidden' | 'visible';
1818
};
19+
/** Value to set for content wrapping at various breakpoints */
20+
rowWrap?: {
21+
default?: 'wrap' | 'nowrap';
22+
sm?: 'wrap' | 'nowrap';
23+
md?: 'wrap' | 'nowrap';
24+
lg?: 'wrap' | 'nowrap';
25+
xl?: 'wrap' | 'nowrap';
26+
'2xl'?: 'wrap' | 'nowrap';
27+
};
1928
/** Vertical alignment of children */
2029
alignItems?: 'start' | 'center' | 'baseline' | 'default';
2130
/** Content to be rendered as children of the content row */
@@ -50,6 +59,7 @@ class ToolbarContent extends React.Component<ToolbarContentProps> {
5059
isExpanded,
5160
toolbarId,
5261
visibility,
62+
rowWrap,
5363
alignItems,
5464
clearAllFilters,
5565
showClearFiltersButton,
@@ -95,6 +105,7 @@ class ToolbarContent extends React.Component<ToolbarContentProps> {
95105
<div
96106
className={css(
97107
styles.toolbarContentSection,
108+
formatBreakpointMods(rowWrap, styles, '', getBreakpoint(width)),
98109
alignItems === 'center' && styles.modifiers.alignItemsCenter,
99110
alignItems === 'start' && styles.modifiers.alignItemsStart,
100111
alignItems === 'baseline' && styles.modifiers.alignItemsBaseline

packages/react-core/src/components/Toolbar/__tests__/Toolbar.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,28 @@ describe('Toolbar', () => {
148148

149149
expect(screen.getByTestId('Toolbar-test-secondary-id')).toHaveClass(styles.modifiers.secondary);
150150
});
151+
152+
it('should render ToolbarContent with pf-m-wrap when rowWrap is set to wrap', () => {
153+
render(
154+
<Toolbar>
155+
<ToolbarContent data-testid="toolbarcontent" rowWrap={{ default: 'wrap' }}>
156+
Test
157+
</ToolbarContent>
158+
</Toolbar>
159+
);
160+
161+
expect(screen.getByTestId('toolbarcontent').querySelector('div')).toHaveClass('pf-m-wrap');
162+
});
163+
164+
it('should render ToolbarContent with pf-m-nowrap when rowWrap is set to nowrap', () => {
165+
render(
166+
<Toolbar>
167+
<ToolbarContent data-testid="toolbarcontent" rowWrap={{ default: 'nowrap' }}>
168+
Test
169+
</ToolbarContent>
170+
</Toolbar>
171+
);
172+
173+
expect(screen.getByTestId('toolbarcontent').querySelector('div')).toHaveClass('pf-m-nowrap');
174+
});
151175
});

packages/react-core/src/components/Toolbar/__tests__/ToolbarGroup.test.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ describe('ToolbarItem', () => {
1111
);
1212
expect(screen.getByTestId('toolbargroup')).toHaveClass('pf-m-overflow-container');
1313
});
14-
it('should render with pf-m-wrap when rowWrap is set', () => {
14+
it('should render with pf-m-wrap when rowWrap is set to wrap', () => {
1515
render(
1616
<ToolbarGroup data-testid="toolbargroup" rowWrap={{ default: 'wrap' }}>
1717
Test
1818
</ToolbarGroup>
1919
);
2020
expect(screen.getByTestId('toolbargroup')).toHaveClass('pf-m-wrap');
2121
});
22+
it('should render with pf-m-nowrap when rowWrap is set to nowrap', () => {
23+
render(
24+
<ToolbarGroup data-testid="toolbargroup" rowWrap={{ default: 'nowrap' }}>
25+
Test
26+
</ToolbarGroup>
27+
);
28+
expect(screen.getByTestId('toolbargroup')).toHaveClass('pf-m-nowrap');
29+
});
2230
});

packages/react-core/src/components/Toolbar/__tests__/ToolbarItem.test.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ describe('ToolbarItem', () => {
1111
);
1212
expect(screen.getByTestId('toolbaritem')).toHaveClass('pf-m-overflow-container');
1313
});
14-
it('should render with pf-m-wrap when rowWrap is set', () => {
14+
it('should render with pf-m-wrap when rowWrap is set to wrap', () => {
1515
render(
1616
<ToolbarItem data-testid="toolbaritem" rowWrap={{ default: 'wrap' }}>
1717
Test
1818
</ToolbarItem>
1919
);
2020
expect(screen.getByTestId('toolbaritem')).toHaveClass('pf-m-wrap');
2121
});
22+
it('should render with pf-m-nowrap when rowWrap is set to nowrap', () => {
23+
render(
24+
<ToolbarItem data-testid="toolbaritem" rowWrap={{ default: 'nowrap' }}>
25+
Test
26+
</ToolbarItem>
27+
);
28+
expect(screen.getByTestId('toolbaritem')).toHaveClass('pf-m-nowrap');
29+
});
2230
});

packages/react-core/src/components/Toolbar/examples/Toolbar.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,18 @@ When all of a toolbar's required elements cannot fit in a single line, you can s
111111

112112
```
113113

114-
## Examples with toolbar spacers
114+
## Examples with spacers and wrapping
115115
You may adjust the space between toolbar items to arrange them into groups. Read our spacers documentation to learn more about using spacers.
116116

117117
Items are spaced “16px” apart by default and can be modified by changing their or their parents' `gap`, `columnGap`, and `rowGap` properties. You can set the property values at multiple breakpoints, including "default", "md", "lg", "xl", and "2xl".
118118

119+
### Toolbar content wrapping
120+
The toolbar content section will wrap by default, but you can set the `rowRap` property to `noWrap` to make it not wrap.
121+
122+
```ts file="./ToolbarContentWrap.tsx"
123+
124+
```
125+
119126
### Toolbar group spacers
120127

121128
```ts file="./ToolbarGroupSpacers.tsx"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Toolbar, ToolbarItem, ToolbarContent } from '@patternfly/react-core';
3+
import { Button, SearchInput } from '@patternfly/react-core';
4+
5+
export const ToolbarItems: React.FunctionComponent = () => {
6+
const items = (
7+
<React.Fragment>
8+
<ToolbarItem>
9+
<SearchInput aria-label="Items example search input" />
10+
</ToolbarItem>
11+
<ToolbarItem>
12+
<Button variant="secondary">Action</Button>
13+
</ToolbarItem>
14+
<ToolbarItem>
15+
<Button variant="secondary">Action</Button>
16+
</ToolbarItem>
17+
<ToolbarItem>
18+
<Button variant="secondary">Action</Button>
19+
</ToolbarItem>
20+
<ToolbarItem>
21+
<Button variant="secondary">Action</Button>
22+
</ToolbarItem>
23+
<ToolbarItem variant="separator" />
24+
<ToolbarItem>
25+
<Button variant="primary">Action</Button>
26+
</ToolbarItem>
27+
</React.Fragment>
28+
);
29+
30+
return (
31+
<Toolbar id="toolbar-items-example">
32+
<ToolbarContent rowWrap={{ default: 'nowrap' }}>{items}</ToolbarContent>
33+
</Toolbar>
34+
);
35+
};

0 commit comments

Comments
 (0)