Skip to content

Commit 93b291b

Browse files
committed
feat: show aria label on hover of icon button
1 parent bc7f422 commit 93b291b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Shared/Components/Button/Button.component.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ButtonHTMLAttributes, PropsWithChildren } from 'react'
22
import { Link, LinkProps } from 'react-router-dom'
33
import { Progressing } from '@Common/Progressing'
44
import { Tooltip } from '@Common/Tooltip'
5+
import { TooltipProps } from '@Common/Tooltip/types'
56
import { ComponentSizeType } from '@Shared/constants'
67
import { ButtonComponentType, ButtonProps, ButtonStyleType, ButtonVariantType } from './types'
78
import { getButtonDerivedClass, getButtonIconClassName, getButtonLoaderSize } from './utils'
@@ -142,8 +143,22 @@ const Button = ({
142143
icon,
143144
})}`
144145

146+
const getTooltipProps = (): TooltipProps => {
147+
if (!showTooltip && icon && ariaLabel) {
148+
return {
149+
alwaysShowTippyOnHover: true,
150+
content: ariaLabel,
151+
}
152+
}
153+
154+
return {
155+
alwaysShowTippyOnHover: showTooltip && !!tooltipProps?.content,
156+
...tooltipProps,
157+
}
158+
}
159+
145160
return (
146-
<Tooltip {...tooltipProps} alwaysShowTippyOnHover={showTooltip && !!tooltipProps?.content}>
161+
<Tooltip {...getTooltipProps()}>
147162
<div>
148163
<ButtonElement
149164
{...props}

0 commit comments

Comments
 (0)