Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ To provide users with more context about a `<DropdownItem>`, pass a short messag
```ts file="./DropdownWithDescriptions.tsx"

```

### Split button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Split button
### Split toggle with checkbox

to align with the language used in the menu toggle docs


Description of split button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edonehoo would you mind taking a stab at quick verbiage here? Would be worth mentioning that the focus must be handled manually when shifting focus back to the toggle element after selecting an item (if the dropdown menu closes upon selection)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description of split button
To combine a checkbox or other control with a dropdown menu, use a split button.
A `<MenuToggle>` can be rendered as a split button via `splitButtonItems`. Elements to be displayed before the dropdown toggle button (like the `<MenuToggleCheckbox>`) must be included in the `splitButtonItems`.
If the dropdown menu closes upon selection, you will need to manually shift focus back to the toggle element after a user selects an item from the menu.

wdyt about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 it

@Mash707 if this looks good to you can you make this quick update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🚀🚀.


Copy link
Contributor

@edonehoo edonehoo Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `<MenuToggle>` can be rendered as a split button via `splitButtonItems`. Elements to be displayed before the dropdown toggle button (like the `<MenuToggleCheckbox>`) must be included in the `splitButtonItems`.
If the dropdown menu closes upon selection, you will need to manually shift focus back to the toggle element after a user selects an item from the menu.

can you add these 2 lines too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. I totally missed it in the previous comment. Have added it now 🚀.

```ts file="./DropdownWithSplit.tsx"

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
Dropdown,
MenuToggle,
MenuToggleCheckbox,
DropdownItem,
DropdownList,
Divider,
MenuToggleElement
} from '@patternfly/react-core';
import { useState } from 'react';

export const DropdownSplitButtonText: React.FunctionComponent = () => {
const [isOpen, setIsOpen] = useState(false);
const toggleRef = React.useRef<MenuToggleElement>(null);

const onFocus = () => {
if (!toggleRef.current) {
return;
}

const toggleButton = toggleRef.current.querySelector('button[aria-expanded]');
toggleButton?.focus();
};

const onSelect = () => {
setIsOpen(false);
onFocus();
};

const onToggleClick = () => {
setIsOpen(!isOpen);
};

return (
<Dropdown
onSelect={onSelect}
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
toggle={(toggleRefCallback: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={(node) => {
// Handle both callback ref and useRef
if (typeof toggleRefCallback === 'function') {
toggleRefCallback(node);
} else if (toggleRefCallback) {
(toggleRefCallback as React.MutableRefObject<MenuToggleElement | null>).current = node;
}
(toggleRef as React.MutableRefObject<MenuToggleElement | null>).current = node;
}}
splitButtonItems={[
<MenuToggleCheckbox id="split-button-checkbox-example" key="split-checkbox" aria-label="Select all" />
]}
aria-label="Dropdown with checkbox split button"
onClick={onToggleClick}
isExpanded={isOpen}
/>
)}
isOpen={isOpen}
>
<DropdownList>
<DropdownItem value={0} key="action">
Action
</DropdownItem>
<DropdownItem
value={1}
key="link"
to="#default-link2"
// Prevent the default onClick functionality for example purposes
onClick={(ev: any) => ev.preventDefault()}
>
Link
</DropdownItem>
<DropdownItem value={2} isDisabled key="disabled action">
Disabled Action
</DropdownItem>
<DropdownItem value={3} isDisabled key="disabled link" to="#default-link4">
Disabled Link
</DropdownItem>
<DropdownItem
value={4}
isAriaDisabled
key="aria-disabled link"
to="#default-link5"
tooltipProps={{ content: 'aria-disabled link', position: 'top' }}
>
Aria-disabled Link
</DropdownItem>
<Divider component="li" key="separator" />
<DropdownItem value={5} key="separated action">
Separated Action
</DropdownItem>
<DropdownItem value={6} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
Separated Link
</DropdownItem>
</DropdownList>
</Dropdown>
);
};
Loading