Skip to content

Commit b0e77d6

Browse files
committed
Added prop to menu toggle
1 parent b465df9 commit b0e77d6

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface MenuToggleProps
4545
isFullWidth?: boolean;
4646
/** Flag indicating the toggle contains placeholder text */
4747
isPlaceholder?: boolean;
48+
/** @beta Flag indicating the toggle has circular styling. Can only be applied to plain toggles. */
49+
isCircle?: boolean;
4850
/** Flag indicating whether the toggle is a settings toggle. This will override the icon property */
4951
isSettings?: boolean;
5052
/** Elements to display before the toggle button. When included, renders the menu toggle as a split button. */
@@ -84,6 +86,7 @@ class MenuToggleBase extends Component<MenuToggleProps, MenuToggleState> {
8486
isFullWidth: false,
8587
isFullHeight: false,
8688
isPlaceholder: false,
89+
isCircle: false,
8790
size: 'default',
8891
ouiaSafe: true
8992
};
@@ -103,6 +106,7 @@ class MenuToggleBase extends Component<MenuToggleProps, MenuToggleState> {
103106
isFullHeight,
104107
isFullWidth,
105108
isPlaceholder,
109+
isCircle,
106110
isSettings,
107111
splitButtonItems,
108112
variant,
@@ -225,7 +229,7 @@ class MenuToggleBase extends Component<MenuToggleProps, MenuToggleState> {
225229

226230
return (
227231
<button
228-
className={css(commonStyles)}
232+
className={css(commonStyles, isCircle && isPlain && 'pf-m-circle')}
229233
type="button"
230234
aria-label={ariaLabel}
231235
aria-expanded={isExpanded}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ describe('Old Snapshot tests - remove when refactoring', () => {
5555
});
5656
});
5757

58+
const toggleVariants = ['default', 'plain', 'primary', 'plainText', 'secondary', 'typeahead'];
59+
5860
test(`Renders with class ${styles.modifiers.small} when size="sm" is passed`, () => {
5961
render(<MenuToggle size="sm">Toggle</MenuToggle>);
6062
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.small);
@@ -110,6 +112,24 @@ test(`Renders with class ${styles.modifiers.settings} when isSettings is passed`
110112
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.settings);
111113
});
112114

115+
test(`Renders with class pf-m-circle when variant="plain" and isCircle is true`, () => {
116+
render(<MenuToggle isCircle variant="plain" aria-label="Toggle"></MenuToggle>);
117+
expect(screen.getByRole('button')).toHaveClass('pf-m-circle');
118+
});
119+
120+
toggleVariants
121+
.filter((variant) => variant !== 'plain')
122+
.forEach((variant) => {
123+
test(`Does not with class pf-m-circle when variant="${variant}" and isCircle is true`, () => {
124+
render(
125+
<MenuToggle isCircle variant={variant as 'default' | 'primary' | 'plainText' | 'secondary' | 'typeahead'}>
126+
Toggle
127+
</MenuToggle>
128+
);
129+
expect(screen.getByRole('button')).not.toHaveClass('pf-m-circle');
130+
});
131+
});
132+
113133
test('Does not render custom icon when icon prop and isSettings are passed', () => {
114134
render(
115135
<MenuToggle isSettings icon={<div>Custom icon</div>}>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
2020
A toggle is collapsed until it is selected by a user.
2121

2222
```ts file="MenuToggleCollapsed.tsx"
23+
2324
```
2425

2526
### Expanded toggle
2627

2728
When a user selects a toggle, it becomes expanded and is styled with a blue underline. To flag expanded toggles, and apply expanded styling, use the `isExpanded` property .
2829

2930
```ts file ="MenuToggleExpanded.tsx"
31+
3032
```
3133

3234
### Small toggle
@@ -42,13 +44,15 @@ You can pass `size="sm"` to a MenuToggle to style it as a small toggle, such as
4244
To disable the selection and expansion of a toggle, use the `isDisabled` property.
4345

4446
```ts file="MenuToggleDisabled.tsx"
47+
4548
```
4649

4750
### With a badge
4851

4952
To display a count of selected items in a toggle, use the `badge` property. You can also pass in `variant="plainText"` for a badge only toggle.
5053

5154
```ts file="MenuToggleBadge.tsx"
55+
5256
```
5357

5458
### Settings toggle
@@ -76,13 +80,15 @@ You can also pass images into the `icon` property. The following example passes
7680
This can be used alongside a text label that provides more context for the image.
7781

7882
```ts file="MenuToggleAvatarText.tsx"
83+
7984
```
8085

8186
### Variant styles
8287

8388
Variant styling can be applied to menu toggles. In the following example, the toggle uses primary styling by passing `variant="primary"` into the `<MenuToggle>` component. Additional variant options include “default”, “plain”, “plainText”, “secondary”, and “typeahead”.
8489

8590
```ts file="MenuToggleVariantStyles.tsx"
91+
8692
```
8793

8894
### Plain toggle with icon
@@ -92,13 +98,23 @@ To apply plain styling to a menu toggle with an icon, pass in `variant="plain"`.
9298
If the toggle does not have any visible text content, use the `aria-label` property to provide an accessible name.
9399

94100
```ts file="MenuTogglePlainIcon.tsx"
101+
102+
```
103+
104+
### Plain circle toggle
105+
106+
You can also pass the `isCircle` property to a plain, icon-only toggle to adjust the styling to a complete circular shape, rather than a rounded square.
107+
108+
```ts file="MenuTogglePlainCircle.tsx"
109+
95110
```
96111

97112
### Plain toggle with text label
98113

99114
To apply plain styling to a menu toggle with a text label, pass in `variant="plainText"`. Unlike the “plain” variant, “plainText” adds a caret pointing down in the toggle.
100115

101116
```ts file="MenuTogglePlainTextLabel.tsx"
117+
102118
```
103119

104120
### Split toggle with checkbox
@@ -150,6 +166,7 @@ A full height toggle fills the height of its parent. To flag a full height toggl
150166
In the following example, the toggle fills the size of the "80px" `<div>` element that it is within.
151167

152168
```ts file="MenuToggleFullHeight.tsx"
169+
153170
```
154171

155172
### Full width toggle
@@ -159,6 +176,7 @@ A full width toggle fills the width of its parent. To flag a full width toggle,
159176
In the following example, the toggle fills the width of its parent as the window size changes.
160177

161178
```ts file="MenuToggleFullWidth.tsx"
179+
162180
```
163181

164182
### Typeahead toggle
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Fragment } from 'react';
2+
import { MenuToggle } from '@patternfly/react-core';
3+
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
4+
5+
export const MenuTogglePlainCircle: React.FunctionComponent = () => (
6+
<Fragment>
7+
<MenuToggle isCircle icon={<EllipsisVIcon />} variant="plain" aria-label="plain circle kebab" />{' '}
8+
<MenuToggle isCircle icon={<EllipsisVIcon />} variant="plain" isExpanded aria-label="plain circle expanded kebab" />{' '}
9+
<MenuToggle isCircle icon={<EllipsisVIcon />} variant="plain" isDisabled aria-label="disabled plain circle kebab" />
10+
</Fragment>
11+
);

0 commit comments

Comments
 (0)