Skip to content

Commit

Permalink
fix(Button): make children prop optional (#3661)
Browse files Browse the repository at this point in the history
* fix(Button): make children prop optional

* chore: add changeset

* chore: refactor optional children type and require it in ActionMenu button

---------

Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
  • Loading branch information
joshblack and joshblack authored Sep 7, 2023
1 parent 1f88928 commit 25693b0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/cuddly-rice-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

Update the `children` prop for `Button` to be optional

<!-- Changed components: Button, IconButton -->
4 changes: 3 additions & 1 deletion src/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const Anchor = React.forwardRef<HTMLElement, ActionMenuAnchorProps>(({children,
})

/** this component is syntactical sugar 🍭 */
export type ActionMenuButtonProps = ButtonProps
export type ActionMenuButtonProps = ButtonProps & {
children: React.ReactNode
}
const MenuButton = React.forwardRef(({...props}, anchorRef) => {
return (
<Anchor ref={anchorRef}>
Expand Down
4 changes: 3 additions & 1 deletion src/ActionMenu/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const Anchor = React.forwardRef<HTMLElement, ActionMenuAnchorProps>(({children,
})

/** this component is syntactical sugar 🍭 */
export type ActionMenuButtonProps = ButtonProps
export type ActionMenuButtonProps = Omit<ButtonProps, 'children'> & {
children: React.ReactNode
}
const MenuButton = React.forwardRef(({...props}, anchorRef) => {
return (
<Anchor ref={anchorRef}>
Expand Down
4 changes: 4 additions & 0 deletions src/Button/__tests__/Button.types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export function iconButtonShouldNotAcceptOutlandishProps() {
return <Button icon={StopIcon} aria-label="Stop icon" anOutlandshPropThatShouldNotBeAllowedOnA={'Button'} />
}

export function supportsNoChildren() {
return <Button />
}

export function supportsLeadingVisual() {
return <Button leadingVisual={() => <span />}>child</Button>
}
Expand Down
2 changes: 1 addition & 1 deletion src/Button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type ButtonProps = {
*/
trailingAction?: React.ElementType | null

children: React.ReactNode
children?: React.ReactNode

/**
* Content alignment for when visuals are present
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ActionMenu.types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ActionMenu} from '..'
import React from 'react'

export function actionButtonWithoutProps() {
//@ts-expect-error requires children
// @ts-expect-error requires children
return <ActionMenu.Button />
}

Expand Down

0 comments on commit 25693b0

Please sign in to comment.