Merge pull request #14467 from overleaf/ds-conditional-tooltip

Added condition on tooltip for the dropdown

GitOrigin-RevId: d8291f98b2bad809579b47714b0eab278195327e
This commit is contained in:
Alasdair Smith 2023-08-29 11:12:50 +01:00 committed by Copybot
parent 03fbc5e0a8
commit 575f646dd4
2 changed files with 18 additions and 12 deletions

View file

@ -57,6 +57,7 @@ function ActionsDropdown({
<DropdownToggleWithTooltip
bsRole="toggle"
className="history-version-dropdown-menu-btn"
isOpened={isOpened}
tooltipProps={{
id,
description: toolTipDescription,

View file

@ -8,6 +8,7 @@ type CustomToggleProps = MergeAndOverride<
Pick<DropdownProps, 'bsClass' | 'open'>,
{
children: React.ReactNode
isOpened: boolean
bsRole: 'toggle'
className?: string
tooltipProps: Omit<React.ComponentProps<typeof Tooltip>, 'children'>
@ -20,6 +21,7 @@ const DropdownToggleWithTooltip = forwardRef<
>(function (props, ref) {
const {
tooltipProps,
isOpened,
children,
bsClass,
className,
@ -28,21 +30,24 @@ const DropdownToggleWithTooltip = forwardRef<
...rest
} = props
const button = (
<button
type="button"
ref={ref}
className={classnames(bsClass, 'btn', className)}
aria-expanded={open}
aria-haspopup="true"
{...rest}
>
{children}
</button>
)
return (
<Tooltip {...tooltipProps}>
<button
type="button"
ref={ref}
className={classnames(bsClass, 'btn', className)}
aria-expanded={open}
aria-haspopup="true"
{...rest}
>
{children}
</button>
</Tooltip>
<>{isOpened ? button : <Tooltip {...tooltipProps}>{button}</Tooltip>}</>
)
})
DropdownToggleWithTooltip.displayName = 'DropdownToggleWithTooltip'
export default DropdownToggleWithTooltip