Skip to content

Commit

Permalink
ActionMenu.Button: Fix spacing between text and caret (#1922)
Browse files Browse the repository at this point in the history
* Fix spacing between Text and caret for ActionMenu.Button

* Improve changelog

* fix margin after design review

* unrelated change
  • Loading branch information
siddharthkp authored Mar 7, 2022
1 parent 561aad8 commit b1d7b8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/actionmenu-button-caret-spacing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

ActionMenu.Button: Fix spacing between text and caret
28 changes: 21 additions & 7 deletions src/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Divider} from './ActionList/Divider'
import {ActionListContainerContext} from './ActionList/ActionListContainerContext'
import {Button, ButtonProps} from './Button'
import {MandateProps} from './utils/types'
import {SxProp, merge} from './sx'

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

/** this component is syntactical sugar 🍭 */
export type ActionMenuButtonProps = ButtonProps
const MenuButton = React.forwardRef<AnchoredOverlayProps['anchorRef'], ButtonProps>((props, anchorRef) => {
return (
<Anchor ref={anchorRef}>
<Button trailingIcon={TriangleDownIcon} type="button" {...props} />
</Anchor>
)
})
const MenuButton = React.forwardRef<AnchoredOverlayProps['anchorRef'], ButtonProps>(
({sx: sxProp = {}, ...props}, anchorRef) => {
return (
<Anchor ref={anchorRef}>
<Button
type="button"
trailingIcon={TriangleDownIcon}
sx={merge(
{
// override the margin on caret for optical alignment
'[data-component=trailingIcon]': {marginX: -1}
},
sxProp as SxProp
)}
{...props}
/>
</Anchor>
)
}
)

type MenuOverlayProps = Partial<OverlayProps> &
Pick<AnchoredOverlayProps, 'align'> & {
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/__snapshots__/ActionMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ exports[`ActionMenu renders consistently 1`] = `
box-shadow: inset 0 0.15em 0.3em rgba(27,31,36,0.15);
}
.c1 [data-component=trailingIcon] {
margin-left: -4px;
margin-right: -4px;
}
<div
className="c0"
color="fg.default"
Expand Down

0 comments on commit b1d7b8c

Please sign in to comment.