Skip to content

Commit

Permalink
New technique -- hide tooltip element when missing
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesuss committed Nov 17, 2020
1 parent 64b6334 commit b431476
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,12 @@ const InputContainer = styled.div`
`}
`;

const ErrorTooltipMessage = styled(TooltipMessage)`
width: 170px;
`;

const ErrorTooltip = styled(WithTooltip)`
width: 100%;
${(props) =>
!props.tooltip &&
`
${ErrorTooltipMessage} {
display: none;
}
`}
`;

const ErrorTooltipMessage = styled(TooltipMessage)`
width: 170px;
`;

const Action = styled.div`
Expand Down
9 changes: 7 additions & 2 deletions src/components/tooltip/WithTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const ButtonContainer = styled.button`
text-decoration: none;
`;

const StyledTooltip = styled(Tooltip)`
${(props) => !props.hasTooltipContent && `display: none;`}
`;

const isDescendantOfAction = (element) => {
const { parentElement } = element;

Expand Down Expand Up @@ -132,7 +136,7 @@ function WithTooltip({
arrowRef,
placement: tooltipPlacement,
}) => (
<Tooltip
<StyledTooltip
hasChrome={hasChrome}
placement={tooltipPlacement}
tooltipRef={tooltipRef}
Expand All @@ -142,9 +146,10 @@ function WithTooltip({
{...getTooltipProps()}
id={id}
role="tooltip"
hasTooltipContent={!!tooltip}
>
{typeof tooltip === 'function' ? tooltip({ onHide: closeTooltip }) : tooltip}
</Tooltip>
</StyledTooltip>
)}
>
{({ getTriggerProps, triggerRef }) => (
Expand Down

0 comments on commit b431476

Please sign in to comment.