-
Notifications
You must be signed in to change notification settings - Fork 381
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
Changes from 7 commits
7cf934b
5d24223
2529763
3aea271
f85a178
c5ae0ff
2d737dc
5a74246
aa7712c
0d8177e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,3 +63,11 @@ To provide users with more context about a `<DropdownItem>`, pass a short messag | |||||||||||||||
| ```ts file="./DropdownWithDescriptions.tsx" | ||||||||||||||||
|
|
||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| ### Split button | ||||||||||||||||
|
|
||||||||||||||||
| Description of split button | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
wdyt about this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 🚀🚀. |
||||||||||||||||
|
|
||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
can you add these 2 lines too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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> | ||
| ); | ||
| }; | ||
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.
to align with the language used in the menu toggle docs