Skip to content

Commit

Permalink
[Tooltip] Use media queries for applying "mobile styles"
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Nov 9, 2020
1 parent abe5246 commit 626b3e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
1 change: 0 additions & 1 deletion docs/pages/api-docs/tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Any other props supplied will be provided to the root element (native element).
| <span class="prop-name">tooltip</span> | <span class="prop-name">.MuiTooltip-tooltip</span> | Styles applied to the tooltip (label wrapper) element.
| <span class="prop-name">tooltipArrow</span> | <span class="prop-name">.MuiTooltip-tooltipArrow</span> | Styles applied to the tooltip (label wrapper) element if `arrow={true}`.
| <span class="prop-name">arrow</span> | <span class="prop-name">.MuiTooltip-arrow</span> | Styles applied to the arrow element.
| <span class="prop-name">touch</span> | <span class="prop-name">.MuiTooltip-touch</span> | Styles applied to the tooltip (label wrapper) element if the tooltip is opened by touch.
| <span class="prop-name">tooltipPlacementLeft</span> | <span class="prop-name">.MuiTooltip-tooltipPlacementLeft</span> | Styles applied to the tooltip (label wrapper) element if `placement` contains "left".
| <span class="prop-name">tooltipPlacementRight</span> | <span class="prop-name">.MuiTooltip-tooltipPlacementRight</span> | Styles applied to the tooltip (label wrapper) element if `placement` contains "right".
| <span class="prop-name">tooltipPlacementTop</span> | <span class="prop-name">.MuiTooltip-tooltipPlacementTop</span> | Styles applied to the tooltip (label wrapper) element if `placement` contains "top".
Expand Down
2 changes: 0 additions & 2 deletions packages/material-ui/src/Tooltip/Tooltip.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export interface TooltipProps extends StandardProps<React.HTMLAttributes<HTMLDiv
tooltipArrow?: string;
/** Styles applied to the arrow element. */
arrow?: string;
/** Styles applied to the tooltip (label wrapper) element if the tooltip is opened by touch. */
touch?: string;
/** Styles applied to the tooltip (label wrapper) element if `placement` contains "left". */
tooltipPlacementLeft?: string;
/** Styles applied to the tooltip (label wrapper) element if `placement` contains "right". */
Expand Down
26 changes: 10 additions & 16 deletions packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export const styles = (theme) => ({
maxWidth: 300,
wordWrap: 'break-word',
fontWeight: theme.typography.fontWeightMedium,
'@media (pointer: coarse)': {
padding: '8px 16px',
fontSize: theme.typography.pxToRem(14),
lineHeight: `${round(16 / 14)}em`,
fontWeight: theme.typography.fontWeightRegular,
},
},
/* Styles applied to the tooltip (label wrapper) element if `arrow={true}`. */
tooltipArrow: {
Expand All @@ -104,13 +110,6 @@ export const styles = (theme) => ({
transform: 'rotate(45deg)',
},
},
/* Styles applied to the tooltip (label wrapper) element if the tooltip is opened by touch. */
touch: {
padding: '8px 16px',
fontSize: theme.typography.pxToRem(14),
lineHeight: `${round(16 / 14)}em`,
fontWeight: theme.typography.fontWeightRegular,
},
/* Styles applied to the tooltip (label wrapper) element if `placement` contains "left". */
tooltipPlacementLeft: {
transformOrigin: 'right center',
Expand Down Expand Up @@ -353,20 +352,17 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
}
};

const detectTouchStart = (event) => {
const handleMouseOver = handleEnter;
const handleMouseLeave = handleLeave;

const handleTouchStart = (event) => {
ignoreNonTouchEvents.current = true;

const childrenProps = children.props;
if (childrenProps.onTouchStart) {
childrenProps.onTouchStart(event);
}
};

const handleMouseOver = handleEnter;
const handleMouseLeave = handleLeave;

const handleTouchStart = (event) => {
detectTouchStart(event);
clearTimeout(leaveTimer.current);
clearTimeout(closeTimer.current);
clearTimeout(touchTimer.current);
Expand Down Expand Up @@ -451,7 +447,6 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
...other,
...children.props,
className: clsx(other.className, children.props.className),
onTouchStart: detectTouchStart,
ref: handleRef,
...(followCursor ? { onMouseMove: handleMouseMove } : {}),
};
Expand Down Expand Up @@ -573,7 +568,6 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
className={clsx(
classes.tooltip,
{
[classes.touch]: ignoreNonTouchEvents.current,
[classes.tooltipArrow]: arrow,
},
classes[`tooltipPlacement${capitalize(placementInner.split('-')[0])}`],
Expand Down

0 comments on commit 626b3e8

Please sign in to comment.