Skip to content

Commit 33ba836

Browse files
authored
TreeView: Increase touch target size for coarse pointers (#2376)
* Add type support for css customer properties in the sx prop * Increase touch targets for coarse pointers * Create orange-beds-rhyme.md
1 parent fbd379d commit 33ba836

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

.changeset/orange-beds-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
TreeView: Increase touch target size for coarse pointers

src/TreeView/TreeView.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,24 @@ const Item: React.FC<TreeViewItemProps> = ({
169169
}
170170
}}
171171
sx={{
172+
'--toggle-width': '1rem', // 16px
172173
position: 'relative',
173174
display: 'grid',
174-
gridTemplateColumns: `calc(${level - 1} * 8px) 16px 1fr`,
175+
gridTemplateColumns: `calc(${level - 1} * (var(--toggle-width) / 2)) var(--toggle-width) 1fr`,
175176
gridTemplateAreas: `"spacer toggle content"`,
176177
width: '100%',
177-
height: 32,
178+
height: '2rem', // 32px
178179
fontSize: 1,
179180
color: 'fg.default',
180181
borderRadius: 2,
181182
cursor: 'pointer',
182183
'&:hover': {
183184
backgroundColor: 'actionListItem.default.hoverBg'
184185
},
186+
'@media (pointer: coarse)': {
187+
'--toggle-width': '1.5rem', // 24px
188+
height: '2.75rem' // 44px
189+
},
185190
// WARNING: styled-components v5.2 introduced a bug that changed
186191
// how it expands `&` in CSS selectors. The following selectors
187192
// are unnecessarily specific to work around that styled-components bug.

src/sx.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ export type BetterCssProperties = {
1111
: SystemCssProperties[K]
1212
}
1313

14-
export type BetterSystemStyleObject = BetterCssProperties | SystemStyleObject
14+
// Support CSS custom properties in the `sx` prop
15+
type CSSCustomProperties = {
16+
[key: `--${string}`]: string | number
17+
}
18+
19+
type CSSSelectorObject = {
20+
[cssSelector: string]: SystemStyleObject | CSSCustomProperties
21+
}
22+
23+
export type BetterSystemStyleObject = BetterCssProperties | SystemStyleObject | CSSCustomProperties | CSSSelectorObject
1524

1625
export interface SxProp {
1726
sx?: BetterSystemStyleObject

0 commit comments

Comments
 (0)