);
};
export const EventPropagationAndMobile: React.FC = () => {
const [showExpandedClick, setShowExpandedClick] = useState(false);
const [showExpandedHover, setShowExpandedHover] = useState(false);
const {
tooltipVisible: tooltipVisibleClick,
targetRef: targetRefClick,
tooltip: tooltipClick,
} = useTooltip("You clicked on the help icon but the card did not expand", { placement: "right", trigger: "click" });
const {
tooltipVisible: tooltipVisibleHover,
targetRef: targetRefHover,
tooltip: tooltipHover,
} = useTooltip("You hovered over the help icon", { placement: "right", trigger: "hover" });
return (
Events do not propagate to other elements in the tree. This helps to not cause unwanted bahaviour like expanding
the cards when clicking on the tooltip target.
setShowExpandedClick(!showExpandedClick)}>
On click {showExpandedClick ? "▴" : "▾"}
{showExpandedClick && (
You clicked on the header but not on the help icon inside the header
)}
{tooltipVisibleClick && tooltipClick}
On touch screen devices hover interactions are also properly handled with `touchstart` and `touchend` events
(`mouseenter` and `mouseleave` cause unwated behaviour on some mobile browsers).
setShowExpandedHover(!showExpandedHover)}>
On hover {showExpandedHover ? "▴" : "▾"}
{showExpandedHover && (
On mobile hovering (or more specifically touching and holding) over the help icon does not trigger expansion
of this card
);
};
export const ScreenEdges: React.FC = () => {
const {
targetRef: targetRefLeft,
tooltip: tooltipLeft,
tooltipVisible: leftVisible,
} = useTooltip("I should not touch the edge of the screen", { placement: "top", trigger: "click" });
const {
targetRef: targetRefRight,
tooltip: tooltipRight,
tooltipVisible: rightVisible,
} = useTooltip("I should not touch the edge of the screen", { placement: "top", trigger: "click" });
const {
targetRef: targetRefMiddle,
tooltip: tooltipMiddle,
tooltipVisible: middleVisible,
} = useTooltip("I should not touch the edge of the screen", { placement: "top", trigger: "click" });
return (
This story can be used to visually tooltip behavior when the target element is positioned close to the screen
edge. Open this screen on the phone or in browser with responsive mode. Tooltips should not touch the screen
edge.