Skip to content

Commit b1d7b8c

Browse files
authored
ActionMenu.Button: Fix spacing between text and caret (#1922)
* Fix spacing between Text and caret for ActionMenu.Button * Improve changelog * fix margin after design review * unrelated change
1 parent 561aad8 commit b1d7b8c

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
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+
ActionMenu.Button: Fix spacing between text and caret

src/ActionMenu.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Divider} from './ActionList/Divider'
88
import {ActionListContainerContext} from './ActionList/ActionListContainerContext'
99
import {Button, ButtonProps} from './Button'
1010
import {MandateProps} from './utils/types'
11+
import {SxProp, merge} from './sx'
1112

1213
type MenuContextProps = Pick<
1314
AnchoredOverlayProps,
@@ -73,13 +74,26 @@ const Anchor = React.forwardRef<AnchoredOverlayProps['anchorRef'], ActionMenuAnc
7374

7475
/** this component is syntactical sugar 🍭 */
7576
export type ActionMenuButtonProps = ButtonProps
76-
const MenuButton = React.forwardRef<AnchoredOverlayProps['anchorRef'], ButtonProps>((props, anchorRef) => {
77-
return (
78-
<Anchor ref={anchorRef}>
79-
<Button trailingIcon={TriangleDownIcon} type="button" {...props} />
80-
</Anchor>
81-
)
82-
})
77+
const MenuButton = React.forwardRef<AnchoredOverlayProps['anchorRef'], ButtonProps>(
78+
({sx: sxProp = {}, ...props}, anchorRef) => {
79+
return (
80+
<Anchor ref={anchorRef}>
81+
<Button
82+
type="button"
83+
trailingIcon={TriangleDownIcon}
84+
sx={merge(
85+
{
86+
// override the margin on caret for optical alignment
87+
'[data-component=trailingIcon]': {marginX: -1}
88+
},
89+
sxProp as SxProp
90+
)}
91+
{...props}
92+
/>
93+
</Anchor>
94+
)
95+
}
96+
)
8397

8498
type MenuOverlayProps = Partial<OverlayProps> &
8599
Pick<AnchoredOverlayProps, 'align'> & {

src/__tests__/__snapshots__/ActionMenu.test.tsx.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ exports[`ActionMenu renders consistently 1`] = `
9191
box-shadow: inset 0 0.15em 0.3em rgba(27,31,36,0.15);
9292
}
9393
94+
.c1 [data-component=trailingIcon] {
95+
margin-left: -4px;
96+
margin-right: -4px;
97+
}
98+
9499
<div
95100
className="c0"
96101
color="fg.default"

0 commit comments

Comments
 (0)