useEscapeKey

Run a callback when Escape is pressed.

useEscapeKey(enabled, onEscape)

Calls onEscape when Escape is pressed anywhere on the page, while enabled is true. Use it for overlays that should close on Escape regardless of focus (Modal, Drawer and CommandPalette do). For dropdowns that also close on outside clicks use `useDismissable`.

API

  • enabledboolean

    The listener is attached only while this is true.

  • onEscape() => void

    Called on Escape.

See also:ModalDrawerCommandPalette