packages/react-components/react-positioning/stories/src/UseSafeZoneArea/UseSafeZoneAreaDescription.md
useSafeZoneArea is a hook that creates a "safe zone" area to improve user experience with nested popover interfaces like menus with submenus. It calculates and renders a V-shaped SVG polygon that temporarily traps the mouse cursor to prevent accidental dismissal of popovers when moving from a trigger to its associated content.
import { useSafeZoneArea } from '@fluentui/react-components';
function MyComponent() {
const safeZoneArea = useSafeZoneArea({
debug: false,
timeout: 300,
onSafeZoneLeave: () => {
console.log('Safe zone left');
},
onSafeZoneEnter: () => {
console.log('Safe zone entered');
},
onSafeZoneTimeout: () => {
console.log('Safe zone timeout');
},
});
return (
<>
<button ref={safeZoneArea.targetRef}>Open Menu</button>
<Portal>
<div ref={safeZoneArea.containerRef} style={{ position: 'absolute', top: 100, left: 100 }}>
Menu Content
</div>
{safeZoneArea.elementToRender}
</Portal>
</>
);
}