Skip to content

Commit 6e2f2cc

Browse files
authored
Merge pull request #6 from devfolioco/fix-tooltip-hover
Fix tooltip hover
2 parents 43c5f8c + 16a9ba2 commit 6e2f2cc

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ You can customize almost every aspect of this component using the below props, o
5050
| children | ReactNode | null | Use this if you want to use some custom component inside the anchor tag. |
5151
| defaultTooltip | string | "Copy email address" | Text shown in the tooltip when the user hovers over the link. |
5252
| copiedTooltip | string | "Copied to clipboard!" | Text shown in the tooltip when the user clicks on the link and the text is copied to clipboard. |
53-
| containerStyles | style object | none | The styles to be applied to the anchor container |
53+
| containerStyles | style object | none | The styles to be applied to the container |
5454
| tooltipStyles | style object | none | The styles to be applied to the tooltip |
55+
| anchorStyles | style object | none | The styles to be applied to the anchor |
5556

5657
## Development
5758

src/lib/index.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ const CopyMailTo = ({
5757
copiedTooltip = "Copied to clipboard!",
5858
containerStyles = {},
5959
tooltipStyles = {},
60+
anchorStyles = {},
6061
}: {
6162
email: string;
6263
children?: React.ReactNode;
6364
defaultTooltip?: string;
6465
copiedTooltip?: string;
6566
containerStyles?: React.CSSProperties;
6667
tooltipStyles?: React.CSSProperties;
68+
anchorStyles?: React.CSSProperties;
6769
}): JSX.Element => {
6870
const [showCopied, setShowCopied] = React.useState(false);
6971
const [showTooltip, setShowTooltip] = React.useState(false);
@@ -93,7 +95,7 @@ const CopyMailTo = ({
9395

9496
const allContainerStyles = {
9597
...containerBaseStyles,
96-
...containerStyles
98+
...containerStyles,
9799
};
98100

99101
const allTooltipStyles = {
@@ -103,22 +105,23 @@ const CopyMailTo = ({
103105
};
104106

105107
return (
106-
<a
107-
title={defaultTooltip}
108-
href={`mailto:${email}`}
109-
style={allContainerStyles}
110-
onClick={copyEmail}
111-
onMouseOver={displayTooltip}
112-
onMouseOut={hideTooltip}
113-
onFocus={displayTooltip}
114-
onBlur={hideTooltip}
115-
>
116-
{children || email}
117-
108+
<span style={allContainerStyles}>
109+
<a
110+
aria-label={defaultTooltip}
111+
onClick={copyEmail}
112+
onMouseOver={displayTooltip}
113+
onMouseOut={hideTooltip}
114+
onFocus={displayTooltip}
115+
onBlur={hideTooltip}
116+
href={`mailto:${email}`}
117+
style={anchorStyles}
118+
>
119+
{children || email}
120+
</a>
118121
<span style={allTooltipStyles}>
119122
{showCopied ? copiedTooltip : defaultTooltip}
120123
</span>
121-
</a>
124+
</span>
122125
);
123126
};
124127

0 commit comments

Comments
 (0)