Skip to content
Draft
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
3 changes: 2 additions & 1 deletion packages/react/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import {forwardRef, type JSX} from 'react'
import type {ButtonProps} from './types'
import {ButtonBase} from './ButtonBase'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
import {mergeProps} from '../utils/mergeProps'

const ButtonComponent = forwardRef(({children, ...props}, forwardedRef): JSX.Element => {
return (
<ButtonBase ref={forwardedRef} as="button" type="button" {...props}>
<ButtonBase ref={forwardedRef} {...mergeProps({as: 'button', type: 'button'}, props)}>
{children}
</ButtonBase>
)
Expand Down
39 changes: 24 additions & 15 deletions packages/react/src/Button/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Tooltip} from '../TooltipV2/Tooltip'
import {TooltipContext} from '../TooltipV2/TooltipContext'
import {TooltipContext as TooltipContextV1} from '../Tooltip/TooltipContext'
import classes from './ButtonBase.module.css'
import {mergeProps} from '../utils/mergeProps'
import {clsx} from 'clsx'

const IconButton = forwardRef(
Expand Down Expand Up @@ -43,15 +44,19 @@ const IconButton = forwardRef(
if (withoutTooltip) {
return (
<ButtonBase
icon={Icon}
className={clsx(className, classes.IconButton)}
data-component="IconButton"
type="button"
aria-label={ariaLabel}
disabled={disabled}
{...props}
// @ts-expect-error StyledButton wants both Anchor and Button refs
ref={forwardedRef}
{...mergeProps(
{
icon: Icon,
className: clsx(classes.IconButton, className),
'data-component': 'IconButton',
type: 'button',
'aria-label': ariaLabel,
disabled,
},
props,
)}
/>
)
} else {
Expand All @@ -66,14 +71,18 @@ const IconButton = forwardRef(
_privateDisableTooltip={hasActivePopup}
>
<ButtonBase
icon={Icon}
className={clsx(className, classes.IconButton)}
data-component="IconButton"
type="button"
aria-keyshortcuts={keyshortcuts ?? undefined}
// If description is provided, we will use the tooltip to describe the button, so we need to keep the aria-label to label the button.
aria-label={description ? ariaLabel : undefined}
{...props}
{...mergeProps(
{
icon: Icon,
className: clsx(classes.IconButton, className),
'data-component': 'IconButton',
type: 'button',
'aria-keyshortcuts': keyshortcuts ?? undefined,
// If description is provided, we will use the tooltip to describe the button, so we need to keep the aria-label to label the button.
'aria-label': description ? ariaLabel : undefined,
},
props,
)}
/>
</Tooltip>
)
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/Button/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {forwardRef, type JSX} from 'react'
import type {LinkButtonProps as BaseLinkButtonProps, ButtonProps} from './types'
import {ButtonBase} from './ButtonBase'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
import {mergeProps} from '../utils/mergeProps'

export type LinkButtonProps = BaseLinkButtonProps & ButtonProps

const LinkButton = forwardRef(({children, as: Component = 'a', ...props}, forwardedRef): JSX.Element => {
return (
<ButtonBase as={Component} ref={forwardedRef} data-component="LinkButton" {...props}>
<ButtonBase ref={forwardedRef} {...mergeProps({as: Component, 'data-component': 'LinkButton'}, props)}>
{children}
</ButtonBase>
)
Expand Down
Loading