Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Button): make children prop optional #3661

Merged
merged 6 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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