Skip to content

useDisclosure

Share boolean open state between controls.

useDisclosure provides open, close, and toggle actions for a boolean ref. It does not render anything or manage focus, dismissal, or accessibility.

Usage

Pass an existing ref to share state with an Akaza component. Without a ref, each call starts closed and owns independent state.

vue
<script setup lang="ts">
import { useTypeahead } from "akaza-ui";

const { query, push, reset } = useTypeahead({ timeout: 500 });

function onKeydown(event: KeyboardEvent) {
  if (event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) return;
  push(event.key.toLocaleLowerCase());
}
</script>

<template>
  <button
    type="button"
    @keydown="onKeydown"
    @blur="reset"
  >
    Type to build a query
  </button>
  <output>{{ query }}</output>
</template>

Actions can be passed directly to native event handlers. They write the ref directly; they do not emit or cancel component change events. Use component slot actions when a change must pass through that component's event policy.

API Reference

ts
export default defineNuxtConfig({
  modules: ['akaza-ui/nuxt'],
})
ArgumentDescription
modelOptional writable ref, including a writable computed ref. Default: a new ref(false).
ReturnTypeDescription
isOpenRef<boolean>The supplied ref or the internally created ref.
open() => voidSet state to true.
close() => voidSet state to false.
toggle() => voidInvert current state.

SSR and Scope

No DOM access, timers, providers, or shared module state. The composable can run during SSR or inside an effect scope. Modal focus and keyboard behavior remain the rendered component's responsibility.

Edit this page on GitHub ↗