diff --git a/.changeset/brown-bees-tap.md b/.changeset/brown-bees-tap.md new file mode 100644 index 00000000000..6dd5c496416 --- /dev/null +++ b/.changeset/brown-bees-tap.md @@ -0,0 +1,5 @@ +--- +"@primer/react": patch +--- + +TreeView: Fix focus styles in styled-components v5.2+ diff --git a/src/TreeView/TreeView.tsx b/src/TreeView/TreeView.tsx index 5c752e62666..0659b9412c8 100644 --- a/src/TreeView/TreeView.tsx +++ b/src/TreeView/TreeView.tsx @@ -182,10 +182,14 @@ const Item: React.FC = ({ '&:hover': { backgroundColor: 'actionListItem.default.hoverBg' }, - [`[role=tree][aria-activedescendant="${itemId}"]:focus-visible &`]: { + // WARNING: styled-components v5.2 introduced a bug that changed + // how it expands `&` in CSS selectors. The following selectors + // are unnecessarily specific to work around that styled-components bug. + // Reference issue: https://github.com/styled-components/styled-components/issues/3265 + [`[role=tree][aria-activedescendant="${itemId}"]:focus-visible #${itemId} > &:is(div)`]: { boxShadow: (theme: Theme) => `0 0 0 2px ${theme.colors.accent.emphasis}` }, - '[role=treeitem][aria-current=true] > &': { + '[role=treeitem][aria-current=true] > &:is(div)': { bg: 'actionListItem.default.selectedBg', '&::after': { position: 'absolute',