Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 677
TreeView: Add count to TreeView trailing actions#6919
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ced0673dc47f06f07f21397fbf8fa3fe0b620d10abaada341f9935cfFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': minor | ||
| --- | ||
| TreeView: Add `count` and `className` support for trailing actions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,10 +22,11 @@ import {useTypeahead} from './useTypeahead' | ||
| import {SkeletonAvatar} from '../SkeletonAvatar' | ||
| import {SkeletonText} from '../SkeletonText' | ||
| import {Dialog} from '../Dialog/Dialog' | ||
| import {IconButton} from '../Button' | ||
| import {Button, IconButton} from '../Button' | ||
| import {ActionList} from '../ActionList' | ||
| import {getAccessibleKeybindingHintString} from '../KeybindingHint' | ||
| import {useIsMacOS} from '../hooks' | ||
| import {Tooltip} from '../TooltipV2' | ||
| // ---------------------------------------------------------------------------- | ||
| // Context | ||
| @@ -80,6 +81,8 @@ export type TreeViewSecondaryActions = { | ||
| label: string | ||
| onClick: () => void | ||
| icon: Icon | ||
| count?: number | string | ||
| className?: string | ||
| } | ||
| /* Size of toggle icon in pixels. */ | ||
| @@ -739,7 +742,7 @@ const TrailingAction = (props: TreeViewTrailingAction) => { | ||
| return ( | ||
| <> | ||
| <div id={trailingActionId} className={clsx('PRIVATE_VisuallyHidden', classes.TreeViewVisuallyHidden)}> | ||
| ; {shortcutText} | ||
| - {shortcutText} | ||
| </div> | ||
| <div | ||
| className={classes.TreeViewItemTrailingAction} | ||
| @@ -751,25 +754,50 @@ const TrailingAction = (props: TreeViewTrailingAction) => { | ||
| } | ||
| onKeyDown={event => event.stopPropagation()} | ||
| > | ||
| {items.map(({label, onClick, icon}, index) => ( | ||
| <IconButton | ||
| icon={icon} | ||
| variant="invisible" | ||
| aria-label={label} | ||
| className={classes.TreeViewItemTrailingActionButton} | ||
| onClick={onClick} | ||
| tabIndex={-1} | ||
| aria-hidden={true} | ||
| key={index} | ||
| onKeyDown={() => { | ||
| // hack to send focus back to the tree item after the action is triggered via click | ||
| // this is needed because the trailing action shouldn't be focused, as it does not interact well with | ||
| // the focus management of TreeView | ||
| const parentElement = document.getElementById(itemId) | ||
| parentElement?.focus() | ||
| }} | ||
| /> | ||
| ))} | ||
| {items.map(({label, onClick, icon, count, className}, index) => { | ||
| // If there is a count, we render a Button instead of an IconButton, | ||
| // as IconButton doesn't support displaying a count. | ||
| if (count) { | ||
| return ( | ||
| <Tooltip key={index} text={label}> | ||
| <Button | ||
| aria-label={label} | ||
| leadingVisual={icon} | ||
| variant="invisible" | ||
| className={clsx(className, classes.TreeViewItemTrailingActionButton)} | ||
| onClick={onClick} | ||
| onKeyDown={() => { | ||
| // hack to send focus back to the tree item after the action is triggered via click | ||
| // this is needed because the trailing action shouldn't be focused, as it does not interact well with | ||
| // the focus management of TreeView | ||
| const parentElement = document.getElementById(itemId) | ||
| parentElement?.focus() | ||
| }} | ||
Comment on lines
+769
to
+775
CopilotAI | ||
| tabIndex={-1} | ||
| aria-hidden={true} | ||
| count={count} | ||
| /> | ||
| </Tooltip> | ||
| ) | ||
| } | ||
| return ( | ||
| <IconButton | ||
| icon={icon} | ||
| variant="invisible" | ||
| aria-label={label} | ||
| className={clsx(className, classes.TreeViewItemTrailingActionButton)} | ||
| onClick={onClick} | ||
| tabIndex={-1} | ||
| aria-hidden={true} | ||
| key={index} | ||
| onKeyDown={() => { | ||
| const parentElement = document.getElementById(itemId) | ||
| parentElement?.focus() | ||
| }} | ||
| /> | ||
| ) | ||
| })} | ||
| </div> | ||
| </> | ||
| ) | ||
| @@ -816,12 +844,18 @@ const ActionDialog: React.FC<TreeViewActionDialogProps> = ({items, onClose}) => | ||
| }} | ||
| > | ||
| <ActionList> | ||
| {items.map(({label, onClick, icon: Icon}, index) => ( | ||
| {items.map(({label, onClick, icon: Icon, count}, index) => ( | ||
| <ActionList.Item key={index} onSelect={onClick}> | ||
| <ActionList.LeadingVisual> | ||
| <Icon /> | ||
| </ActionList.LeadingVisual> | ||
| {label} | ||
| {count ? ( | ||
| <ActionList.TrailingVisual> | ||
| {count} | ||
| <VisuallyHidden>items</VisuallyHidden> | ||
CopilotAI | ||
| </ActionList.TrailingVisual> | ||
| ) : null} | ||
| </ActionList.Item> | ||
| ))} | ||
| </ActionList> | ||
Uh oh!
There was an error while loading. Please reload this page.
CopilotAIOct 6, 2025
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.
Changed semicolon to hyphen in visually hidden text. This appears to be an unintended character change that should be reverted.