Skip to content
GaudiGaudi Design System home

Search documentation

Search every page, heading and paragraph.

useOnClickOutside

Run a callback when a press lands outside one or more elements.

HooksInteraction@gaudi/design-system/hooks/interaction/use-on-click-outsideView in StorybookSource

Listens for pointerdown on the document and calls the handler when the target is outside every ref, for custom panels and inline editors. Pass several refs, such as a trigger and its panel.

Usage

import { useOnClickOutside } from '@gaudi/design-system/hooks';
useOnClickOutside([triggerRef, panelRef], () => setOpen(false), { enabled: open });

Examples

Commit an inline editor

Storybook

Trigger and panel together

Storybook

API

3 options
1 return value

Accessibility

An outside click is a pointer shortcut. Also close on Escape and return focus to the trigger, so keyboard users can dismiss the panel.

Notes

  • Popover, Dialog, Select and menus already dismiss themselves.