Skip to Content
ohooks

useInert

Manages the inert and aria-hidden attributes on a target element (or its document-level siblings) with reference counting.

Loading preview...

The useInert hook applies the native inert attribute (and aria-hidden="true" when requested) either directly to a target element or to all document-level siblings outside the target, using reference counting so stacked modals and drawers restore the DOM cleanly.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useInert.json

Usage

Examples

Isolating an Open Modal (trapSiblings: true)

Pass trapSiblings: true so every sibling outside the modal becomes non-interactive and hidden from assistive technologies while the modal is open.

Disabling a Specific Section Directly

With trapSiblings: false (the default), useInert marks the target element itself as inert—useful for disabling a form or panel while saving.

API Reference

UseInertOptions

Configuration options for sibling trapping and aria-hidden synchronization.

Property
Specification
trapSiblings?
uniondefault:false
Apply inert and aria-hidden="true" to all top-level sibling elements instead of the target itself