Skip to content
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
14 changes: 13 additions & 1 deletion packages/react-core/src/components/Dropdown/examples/Dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ propComponents:
]
---

import { useState } from 'react';
import { useState, useRef } from 'react';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';

## Examples
Expand Down Expand Up @@ -63,3 +63,15 @@ To provide users with more context about a `<DropdownItem>`, pass a short messag
```ts file="./DropdownWithDescriptions.tsx"

```

### Split toggle with checkbox

To combine a checkbox or other control with a dropdown menu, use a split button.

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 🚀.

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.

```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 { useRef, useState } from 'react';

export const DropdownSplitButtonText: React.FunctionComponent = () => {
const [isOpen, setIsOpen] = useState(false);
const toggleRef = 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