Collapsible

Collapsible keeps optional content reachable without expanding the page by default.

import Collapsible from '@/components/ui/collapsible';

export default function UsageDemo() {
  return (

Installation

Add this component with the NateUI CLI.

npx @nateui/cli@latest add Collapsible

Examples

Basic

import Collapsible from '@/components/ui/collapsible';

export default function BasicDemo() {
  return (

Controlled

import { useState } from 'react';
import Button from '@/components/ui/button';
import Collapsible from '@/components/ui/collapsible';
import { ChevronUp, ChevronDown } from '@/components/ui/icons';

Accordion

import { useState } from 'react';
import Collapsible from '@/components/ui/collapsible';

const faqs = [

Custom trigger

import Collapsible from '@/components/ui/collapsible';
import Button from '@/components/ui/button';
import { Plus, Minus } from '@/components/ui/icons';

API

Collapsible is a compound component: a root Collapsible that owns the open state, Collapsible.Trigger for the toggle, and Collapsible.Content for the animated region.

Collapsible

Collapsible accepts the props below plus native props for the root div.

PropDescriptionTypeDefault
childrenTrigger and content parts rendered inside the collapsible.ReactNode-
classNameClass names applied to the root div.string-
defaultOpenInitial open state for uncontrolled usage.booleanfalse
onOpenChangeCalled with the next open state whenever it changes.(open: boolean) => void-
openControls the open state. Provide with onOpenChange for controlled usage.boolean-
...nativeDivPropsNative props for the root div.ComponentProps<'div'>-

Collapsible.Trigger

Renders the default toggle button, or a custom trigger when children is a function.

PropDescriptionTypeDefault
childrenTrigger label, or a render function that receives isOpen and toggle for a custom trigger.ReactNode | CollapsibleTriggerRender-
classNameClass names applied to the default trigger button. Ignored when children is a function.string-

Collapsible.Content

Wraps the region that expands and collapses. Accepts the props below plus native props for the div.

PropDescriptionTypeDefault
childrenContent revealed when the collapsible is open.ReactNode-
classNameClass names applied to the animated content wrapper.string-
defaultOverflowHiddenApplies overflow-hidden so content is clipped during the height animation.booleantrue
...nativeDivPropsNative props for the content div.ComponentProps<'div'>-

Types

type CollapsibleTriggerRender = (props: {
  isOpen: boolean;
  toggle: () => void;
}) => ReactNode;