--- title: Popover Component description: "A modern, accessible popover component for STX applications." --- # Popover A modern, accessible popover component for STX applications. ## Features - 🎯 Fully accessible (WAI-ARIA compliant) - 🌐 Keyboard navigation support - 🎨 Customizable styling - 📱 Mobile-friendly - 🎯 TypeScript support - 🎈 Floating UI integration - 🔄 Auto-positioning
## Install ::: code-group ```sh [npm] npm install @stacksjs/components ``` ```sh [bun] bun install @stacksjs/components # bun add @stacksjs/components # bun i @stacksjs/components ``` ```sh [pnpm] pnpm add @stacksjs/components # pnpm i @stacksjs/components ``` ```sh [yarn] yarn add @stacksjs/components # yarn i -d @stacksjs/components ``` :::
## Usage The popover component is composed of several sub-components that work together to create a fully functional and accessible popover: ```html ``` ## API Reference ### Popover The root component that wraps all popover elements. #### Props - `as` - (string) The element to render as (default: 'div') - `static` - (boolean) Whether the popover should always be rendered ### PopoverButton The button that toggles the popover panel. #### Props - `as` - (string) The element to render as (default: 'button') - `disabled` - (boolean) Whether the button is disabled ### PopoverPanel The panel that contains the popover content. #### Props - `as` - (string) The element to render as (default: 'div') - `static` - (boolean) Whether the panel should always be rendered - `unmount` - (boolean) Whether to unmount the panel when closed #### Slot Props The PopoverPanel component exposes the following slot props: - `open` - (boolean) Whether the panel is currently open - `close` - (function) Method to close the panel ## Styling The popover components can be styled using standard CSS classes. Each component accepts standard HTML attributes including `class` and `style`. For dynamic positioning and transitions: ```html
``` ## Accessibility The popover component follows WAI-ARIA guidelines and includes the following features: - Proper ARIA attributes (aria-expanded, aria-haspopup) - Keyboard navigation support (Escape to close) - Focus management and focus trap - Screen reader announcements ## TypeScript Support The popover component includes full TypeScript support: The exported names are the components - `Popover`, `PopoverButton`, `PopoverPanel` - not their slot-prop types: ```ts import { Popover, PopoverButton, PopoverPanel } from '@stacksjs/components' import { ref } from '@stacksjs/stx' const panelOpen = ref(false) ``` Still have questions relating this component's usage? Contact us and we will help you out.