-
Notifications
You must be signed in to change notification settings - Fork 376
chore(dropdown): add split button action example #11753
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
Merged
thatblindgeye
merged 10 commits into
patternfly:main
from
Mash707:dropdown-add-split-action-example
Dec 17, 2025
+110
−1
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7cf934b
chore(dropdown): add split button action example
Mash707 5d24223
added aria label
Mash707 2529763
added aria label
Mash707 3aea271
added aria labels
Mash707 f85a178
added the onOpenChange prop
Mash707 c5ae0ff
added focus logic
Mash707 2d737dc
remove unnecessary nesting
Mash707 5a74246
update description and title
Mash707 aa7712c
update description
Mash707 0d8177e
update imports
Mash707 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/react-core/src/components/Dropdown/examples/DropdownWithSplit.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add these 2 lines too?
There was a problem hiding this comment.
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 🚀.