Skip to content

Commit 177b684

Browse files
authored
feat(toolbar): add hasNoPadding prop and test (#11648)
1 parent 48b5749 commit 177b684

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export interface ToolbarProps extends React.HTMLProps<HTMLDivElement>, OUIAProps
5757
ouiaSafe?: boolean;
5858
/** Background color variant of the toolbar */
5959
colorVariant?: ToolbarColorVariant | 'default' | 'no-background' | 'primary' | 'secondary';
60+
/** Flag indicating the toolbar padding is removed */
61+
hasNoPadding?: boolean;
6062
}
6163

6264
export interface ToolbarState {
@@ -78,6 +80,7 @@ class Toolbar extends Component<ToolbarProps, ToolbarState> {
7880
static displayName = 'Toolbar';
7981
labelGroupContentRef = createRef<HTMLDivElement>();
8082
staticFilterInfo = {};
83+
hasNoPadding = false;
8184
state = {
8285
isManagedToggleExpanded: false,
8386
filterInfo: {},
@@ -128,6 +131,7 @@ class Toolbar extends Component<ToolbarProps, ToolbarState> {
128131

129132
renderToolbar = (randomId: string) => {
130133
const {
134+
hasNoPadding,
131135
clearAllFilters,
132136
clearFiltersButtonText,
133137
collapseListedFiltersBreakpoint,
@@ -159,6 +163,7 @@ class Toolbar extends Component<ToolbarProps, ToolbarState> {
159163
<div
160164
className={css(
161165
styles.toolbar,
166+
hasNoPadding && styles.modifiers.noPadding,
162167
isFullHeight && styles.modifiers.fullHeight,
163168
isStatic && styles.modifiers.static,
164169
isSticky && styles.modifiers.sticky,

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Fragment } from 'react';
22
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
34

45
import { ToolbarToggleGroup } from '../ToolbarToggleGroup';
56
import { Toolbar } from '../Toolbar';
@@ -42,6 +43,34 @@ describe('Toolbar', () => {
4243
expect(asFragment()).toMatchSnapshot();
4344
});
4445

46+
it(`should render toolbar without ${styles.modifiers.noPadding} by default`, () => {
47+
render(
48+
<Toolbar data-testid="toolbar">
49+
<ToolbarContent>
50+
<ToolbarItem>Test</ToolbarItem>
51+
<ToolbarItem>Test 2</ToolbarItem>
52+
<ToolbarItem variant="separator" />
53+
<ToolbarItem>Test 3 </ToolbarItem>
54+
</ToolbarContent>
55+
</Toolbar>
56+
);
57+
expect(screen.getByTestId('toolbar')).not.toHaveClass('pf-m-no-padding');
58+
});
59+
60+
it(`should render toolbar with ${styles.modifiers.noPadding} class when hasNoPadding is true`, () => {
61+
render(
62+
<Toolbar data-testid="toolbar-no-padding" hasNoPadding>
63+
<ToolbarContent>
64+
<ToolbarItem>Test</ToolbarItem>
65+
<ToolbarItem>Test 2</ToolbarItem>
66+
<ToolbarItem variant="separator" />
67+
<ToolbarItem>Test 3 </ToolbarItem>
68+
</ToolbarContent>
69+
</Toolbar>
70+
);
71+
expect(screen.getByTestId('toolbar-no-padding')).toHaveClass(styles.modifiers.noPadding);
72+
});
73+
4574
it('should render with custom label content', () => {
4675
const items = (
4776
<Fragment>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ exports[`Toolbar should render with custom label content 1`] = `
5151
<DocumentFragment>
5252
<div
5353
class="pf-v6-c-toolbar pf-m-toggle-group-container"
54-
data-ouia-component-id="OUIA-Generated-Toolbar-2"
54+
data-ouia-component-id="OUIA-Generated-Toolbar-4"
5555
data-ouia-component-type="PF6/Toolbar"
5656
data-ouia-safe="true"
5757
id="toolbar-with-filter"

0 commit comments

Comments
 (0)