Skip to content

Commit

Permalink
feat(MenuToggle): add placeholder support
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcfaul committed Sep 5, 2024
1 parent e7ba60e commit cdd389f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/react-core/src/components/MenuToggle/MenuToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface MenuToggleProps
isFullHeight?: boolean;
/** Flag indicating the toggle takes up the full width of its parent */
isFullWidth?: boolean;
/** Flag indicating the toggle contains placeholder text */
isPlaceholder?: boolean;
/** Object used to configure a split button menu toggle */
splitButtonOptions?: SplitButtonOptions;
/** Variant styles of the menu toggle */
Expand Down Expand Up @@ -85,6 +87,7 @@ class MenuToggleBase extends React.Component<MenuToggleProps, MenuToggleState> {
isDisabled: false,
isFullWidth: false,
isFullHeight: false,
isPlaceholder: false,
size: 'default',
ouiaSafe: true
};
Expand All @@ -103,6 +106,7 @@ class MenuToggleBase extends React.Component<MenuToggleProps, MenuToggleState> {
isDisabled,
isFullHeight,
isFullWidth,
isPlaceholder,
splitButtonOptions,
variant,
status,
Expand Down Expand Up @@ -179,6 +183,7 @@ class MenuToggleBase extends React.Component<MenuToggleProps, MenuToggleState> {
isFullHeight && styles.modifiers.fullHeight,
isFullWidth && styles.modifiers.fullWidth,
isDisabled && styles.modifiers.disabled,
isPlaceholder && styles.modifiers.placeholder,
size === MenuToggleSize.sm && styles.modifiers.small,
className
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ describe('menu toggle', () => {
await user.click(screen.getByRole(`button`) as Element);
expect(mockClick).toHaveBeenCalled();
});

test(`Renders with class ${styles.modifiers.placeholder} when isPlaceholder is passed`, () => {
render(<MenuToggle isPlaceholder>Toggle</MenuToggle>);
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.placeholder);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,11 @@ When the status value is "warning" or "danger", you must include helper text tha
```ts file='MenuToggleStatus.tsx'

```

### Placeholder text in toggle

To indicate the toggle contains placeholder text, pass the `isPlaceholder` property to the `MenuToggle`.

```ts file='MenuTogglePlaceholder.tsx'

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import { MenuToggle } from '@patternfly/react-core';

export const MenuTogglePlaceholder: React.FunctionComponent = () => (
<MenuToggle isPlaceholder>Placeholder text</MenuToggle>
);

0 comments on commit cdd389f

Please sign in to comment.