Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MenuToggle): allow split action toggle text #10256

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-core/src/components/MenuToggle/MenuToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ class MenuToggleBase extends React.Component<MenuToggleProps> {
aria-label={ariaLabel}
disabled={isDisabled}
onClick={onClick}
{...(children && { style: { display: 'flex', paddingLeft: 'var(--pf-v5-global--spacer--sm)' } })}
{...otherProps}
>
{children && <span className={css(styles.menuToggleText)}>{children}</span>}
{toggleControls}
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,24 @@ Variant styling can be applied to split button toggles to adjust their appearanc

```

### Split button toggle with text label
### Split button toggle with checkbox label

To display text in a split button menu toggle, add a label to the `items` property of `splitButtonOptions`.

```ts file='MenuToggleSplitButtonCheckboxWithText.tsx'

```

### Split button toggle with checkbox and toggle button text

For split button toggles that should still contain text which will trigger the toggle's `onClick`, pass `children` to the `MenuToggle`.

The following example shows a split button with a `<MenuToggleCheckbox>` and toggle button text.

```ts file='MenuToggleSplitButtonCheckboxWithToggleText.tsx'

```

### Split button toggle with action

To add an action to a split button, pass `variant='action'` into `splitButtonOptions` and add a `<MenuToggleAction>` to the `items` property of `splitButtonOptions`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import { MenuToggleCheckbox, MenuToggle } from '@patternfly/react-core';

export const MenuToggleSplitButtonCheckboxWithToggleText: React.FunctionComponent = () => (
<React.Fragment>
<MenuToggle
splitButtonOptions={{
items: [
<MenuToggleCheckbox
id="split-button-checkbox-with-text-example"
key="split-checkbox-with-text"
aria-label="Select all"
/>
]
}}
aria-label="Menu toggle with checkbox split button and text"
>
10 selected
</MenuToggle>{' '}
<MenuToggle
variant="primary"
splitButtonOptions={{
items: [
<MenuToggleCheckbox
id="split-button-checkbox-primary-example"
key="split-checkbox-primary"
aria-label="Select all"
/>
]
}}
aria-label="Primary menu toggle with checkbox split button"
>
10 selected
</MenuToggle>{' '}
<MenuToggle
variant="secondary"
splitButtonOptions={{
items: [
<MenuToggleCheckbox
id="split-button-checkbox-secondary-example"
key="split-checkbox-secondary"
aria-label="Select all"
/>
]
}}
aria-label="Secondary menu toggle with checkbox split button"
>
10 selected
</MenuToggle>
</React.Fragment>
);
Loading