Skip to content

Commit

Permalink
fix(CompositeBar): fix multipleTooltip sticking (#100)
Browse files Browse the repository at this point in the history
* fix(CompositeBar): fix multipleTooltip sticking

* chore: fix pr

* fix(AsideHeaderShowcase): reorder cases in if
  • Loading branch information
Lunory authored Sep 8, 2023
1 parent 08a812a commit 420bd6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const AsideHeaderShowcase: FC<AsideHeaderShowcaseProps> = ({
// @ts-ignore
eventBroker.subscribe((data: EventBrokerData<{layersCount: number}>) => {
if (data?.eventId === 'layerschange') {
callback(data?.meta?.layersCount !== 0 && isModalOpen);
callback(isModalOpen && data?.meta?.layersCount !== 0);
}
});
};
Expand Down
29 changes: 27 additions & 2 deletions src/components/CompositeBar/CompositeBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
}) => {
const ref = useRef<List<CompositeBarItem>>(null);
const tooltipRef = useRef<HTMLDivElement>(null);

const {
setValue: setMultipleTooltipContextValue,
active: multipleTooltipActive,
Expand All @@ -61,10 +62,27 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
} = useContext(MultipleTooltipContext);
const {compact} = useAsideHeaderContext();

React.useEffect(() => {
function handleBlurWindow() {
if (multipleTooltip && multipleTooltipActive) {
setMultipleTooltipContextValue({active: false});
}
}

window.addEventListener('blur', handleBlurWindow);

return () => {
window.removeEventListener('blur', handleBlurWindow);
};
}, [multipleTooltip, multipleTooltipActive, setMultipleTooltipContextValue]);

const onTooltipMouseEnter = useCallback(
(e) => {
if (
multipleTooltip &&
compact &&
!multipleTooltipActive &&
document.hasFocus() &&
activeIndex !== lastClickedItemIndex &&
e.clientX <= ASIDE_HEADER_COMPACT_WIDTH
) {
Expand All @@ -73,11 +91,18 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
});
}
},
[multipleTooltipActive, activeIndex, lastClickedItemIndex, setMultipleTooltipContextValue],
[
multipleTooltip,
compact,
multipleTooltipActive,
activeIndex,
lastClickedItemIndex,
setMultipleTooltipContextValue,
],
);

const onTooltipMouseLeave = useCallback(() => {
if (multipleTooltipActive) {
if (multipleTooltip && multipleTooltipActive && document.hasFocus()) {
setMultipleTooltipContextValue?.({
active: false,
lastClickedItemIndex: undefined,
Expand Down

0 comments on commit 420bd6e

Please sign in to comment.