Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support z index for WithTooltip & Tooltip #283

Merged
merged 3 commits into from
Aug 9, 2021
Merged
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
7 changes: 5 additions & 2 deletions src/components/shared/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ export const pageMargins = css`
export const hoverEffect = css`
border: 1px solid ${color.border};
border-radius: ${spacing.borderRadius.small}px;
transition: background 150ms ease-out, border 150ms ease-out,
transform 150ms ease-out;
transition: background 150ms ease-out, border 150ms ease-out, transform 150ms ease-out;

&:hover,
&.__hover {
Expand All @@ -117,3 +116,7 @@ export const hoverEffect = css`
transform: translate3d(0, 0, 0);
}
`;

export const zIndex = {
tooltip: 2147483647,
};
15 changes: 12 additions & 3 deletions src/components/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
import { typography, spacing } from '../shared/styles';
import { typography, spacing, zIndex as sharedZIndex } from '../shared/styles';

const ifPlacementEquals = (placement, value, fallback = 0) => (props) =>
props['data-placement'].split('-')[0] === placement ? value : fallback;
Expand Down Expand Up @@ -44,7 +44,7 @@ const Arrow = styled.div`

const TooltipWrapper = styled.div`
display: ${(props) => (props.hidden ? 'none' : 'inline-block')};
z-index: 2147483647;
z-index: ${(props) => props.zIndex};

${(props) =>
!props.hasChrome &&
Expand Down Expand Up @@ -80,10 +80,17 @@ export function Tooltip({
arrowProps,
tooltipRef,
arrowRef,
zIndex,
...props
}) {
return (
<TooltipWrapper hasChrome={hasChrome} data-placement={placement} ref={tooltipRef} {...props}>
<TooltipWrapper
hasChrome={hasChrome}
data-placement={placement}
ref={tooltipRef}
zIndex={zIndex}
{...props}
>
<Arrow isVisible={hasChrome} data-placement={placement} ref={arrowRef} {...arrowProps} />
{children}
</TooltipWrapper>
Expand All @@ -98,6 +105,7 @@ Tooltip.propTypes = {
placement: PropTypes.string,
arrowRef: PropTypes.any, // eslint-disable-line react/forbid-prop-types
tooltipRef: PropTypes.any, // eslint-disable-line react/forbid-prop-types
zIndex: PropTypes.number,
};
Tooltip.defaultProps = {
children: undefined,
Expand All @@ -106,4 +114,5 @@ Tooltip.defaultProps = {
arrowProps: null,
arrowRef: undefined,
tooltipRef: undefined,
zIndex: sharedZIndex.tooltip,
};
4 changes: 4 additions & 0 deletions src/components/tooltip/WithTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function WithTooltip({
startOpen,
delayHide,
onVisibilityChange,
tooltipZIndex,
...props
}) {
const id = React.useMemo(() => uuid.v4(), []);
Expand Down Expand Up @@ -152,6 +153,7 @@ function WithTooltip({
id={id}
role="tooltip"
hasTooltipContent={!!tooltip}
zIndex={tooltipZIndex}
>
{typeof tooltip === 'function' ? tooltip({ onHide: closeTooltip }) : tooltip}
</StyledTooltip>
Expand Down Expand Up @@ -192,6 +194,7 @@ WithTooltip.propTypes = {
startOpen: PropTypes.bool,
delayHide: PropTypes.number,
onVisibilityChange: PropTypes.func,
tooltipZIndex: PropTypes.number,
};

WithTooltip.defaultProps = {
Expand All @@ -205,6 +208,7 @@ WithTooltip.defaultProps = {
startOpen: false,
delayHide: 100,
onVisibilityChange: () => {},
tooltipZIndex: undefined,
};

export default WithTooltip;