Skip to content

Commit 0fd02ce

Browse files
committed
add wrap to toolbar content
1 parent 1b98310 commit 0fd02ce

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 Component<ToolbarContentProps> {
5059
isExpanded,
5160
toolbarId,
5261
visibility,
62+
rowWrap,
5363
alignItems,
5464
clearAllFilters,
5565
showClearFiltersButton,
@@ -95,6 +105,7 @@ class ToolbarContent extends 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
@@ -147,4 +147,28 @@ describe('Toolbar', () => {
147147

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

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

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

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

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

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

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

114114
```
115115

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

119119
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".
120120

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

123130
```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)