Skip to content

Commit

Permalink
Add className prop support to TreeView (#4512)
Browse files Browse the repository at this point in the history
* Add className prop support to TreeView

* Add className props to TreeView components

* Move cool-trees-admire changeset to top level

* Update packages/react/src/TreeView/TreeView.tsx
  • Loading branch information
colebemis committed Apr 19, 2024
1 parent f9eae58 commit 622b144
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cool-trees-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Added `className` props to `TreeView` and `TreeView.Item` components for custom styling.
7 changes: 6 additions & 1 deletion packages/react/src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type TreeViewProps = {
'aria-labelledby'?: React.AriaAttributes['aria-labelledby']
children: React.ReactNode
flat?: boolean
className?: string
}

const UlBox = styled.ul<SxProp>`
Expand Down Expand Up @@ -255,6 +256,7 @@ const Root: React.FC<TreeViewProps> = ({
'aria-labelledby': ariaLabelledby,
children,
flat,
className,
}) => {
const containerRef = React.useRef<HTMLUListElement>(null)
const mouseDownRef = React.useRef<boolean>(false)
Expand Down Expand Up @@ -311,6 +313,7 @@ const Root: React.FC<TreeViewProps> = ({
aria-labelledby={ariaLabelledby}
data-omit-spacer={flat}
onMouseDown={onMouseDown}
className={className}
>
{children}
</UlBox>
Expand All @@ -333,6 +336,7 @@ export type TreeViewItemProps = {
expanded?: boolean
onExpandedChange?: (expanded: boolean) => void
onSelect?: (event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => void
className?: string
}

const Item = React.forwardRef<HTMLElement, TreeViewItemProps>(
Expand All @@ -346,6 +350,7 @@ const Item = React.forwardRef<HTMLElement, TreeViewItemProps>(
onExpandedChange,
onSelect,
children,
className,
},
ref,
) => {
Expand Down Expand Up @@ -433,7 +438,7 @@ const Item = React.forwardRef<HTMLElement, TreeViewItemProps>(
>
{/* @ts-ignore Box doesn't have type support for `ref` used in combination with `as` */}
<li
className="PRIVATE_TreeView-item"
className={clsx('PRIVATE_TreeView-item', className)}
ref={ref as React.ForwardedRef<HTMLLIElement>}
tabIndex={0}
id={itemId}
Expand Down

0 comments on commit 622b144

Please sign in to comment.