QUI React

Collapse

Conditionally hide or show content with a collapse animation.

import {QCollapse} from "@qui/react"

Examples

Expand from the start edge of the child element.

I'm a collapsible section
import {ReactNode, useState} from "react"
import {QButton, QCollapse} from "@qui/react"
export default function Showcase(): ReactNode {
const [showing, setShowing] = useState(true)
const toggle = () => {
setShowing((prevState) => !prevState)
}
return (
<div className="flex flex-col items-center">
<QCollapse className="q-body-s" in={showing}>
I'm a collapsible section
</QCollapse>
<QButton className="mt-4" color="primary" onClick={toggle} variant="fill">
Click me to {showing ? "Hide" : "Show"}
</QButton>
</div>
)
}

API

Props

This component extends the Transition component from react-transition-group.

Name & DescriptionOption(s)Default
Add a custom transition end trigger. Called with the transitioning DOM node and a done callback. Allows for more fine-grained transition end logic. Note: Timeouts are still used as a fallback if provided.
      (
      node: HTMLElement | object,
      done: () => void,
      ) => void
      Whether to show the animation when the component is first mounted.
      boolean
      React Children
      ReactNode
      Class applied to the root element.
      string
      Minimum size of the component. If supplied as a number, the value will be converted into pixels.
      | string
      | number
      The transition timing function. You may specify a single easing or an object containing independent values for enter and exit.
      | string
      | {
      enter: string
      exit: string
      }
      If true, the component will also fade in and out.
      boolean
      Show the component; triggers the enter or exit states
      boolean
      Props for the element that wraps the children.
      Omit<
      DetailedHTMLProps<
      HTMLAttributes<HTMLDivElement>,
      HTMLDivElement
      >
      >
      By default, the child component is mounted immediately along with the parent Transition component. If you want to "lazy mount" the component on the first in = true you can set mountOnEnter. After the first enter transition the component will stay mounted, even on "exited", unless you also specify unmountOnExit.
      boolean
      A React reference to DOM element that need to transition. example. When nodeRef prop is used, node is not passed to callback functions (e.g. onEnter) because user already has direct access to the node. When changing key prop of Transition in a TransitionGroup a new nodeRef needs to be provided to Transition with changed key prop. see also.
      Ref<HTMLElement>
      Callback fired before the "entering" status is applied. An extra parameter isAppearing is supplied to indicate if the enter stage is occurring on the initial mount
          (
          node: HTMLElement | object,
          isAppearing: boolean,
          ) => void
          Callback fired after the "entered" status is applied. An extra parameter isAppearing is supplied to indicate if the enter stage is occurring on the initial mount
              (
              node: HTMLElement | object,
              isAppearing: boolean,
              ) => void
              Callback fired after the "entering" status is applied. An extra parameter isAppearing is supplied to indicate if the enter stage is occurring on the initial mount
                  (
                  node: HTMLElement | object,
                  isAppearing: boolean,
                  ) => void
                  Callback fired before the "exiting" status is applied.
                      (
                      node: HTMLElement | object,
                      ) => void
                      Callback fired after the "exited" status is applied.
                          (
                          node: HTMLElement | object,
                          ) => void
                          Callback fired after the "exiting" status is applied.
                              (
                              node: HTMLElement | object,
                              ) => void
                              Inline styles
                              CSSProperties
                              The duration of the transition, in milliseconds. If supplied as 'auto', the duration will be computed based on the height of the component's child element.
                              | number
                              | 'auto'
                              | {
                              appear?: number
                              enter?: number
                              exit?: number
                              }
                              By default, the child component stays mounted after it reaches the 'exited' state. Set unmountOnExit if you'd prefer to unmount the component after it finishes exiting.
                              boolean
                              Type
                              (
                              node: HTMLElement | object,
                              done: () => void,
                              ) => void
                              Description
                              Add a custom transition end trigger. Called with the transitioning DOM node and a done callback. Allows for more fine-grained transition end logic. Note: Timeouts are still used as a fallback if provided.
                                  Type
                                  boolean
                                  Description
                                  Whether to show the animation when the component is first mounted.
                                  Description
                                  React Children
                                  Type
                                  string
                                  Description
                                  Class applied to the root element.
                                  Type
                                  | string
                                  | number
                                  Description
                                  Minimum size of the component. If supplied as a number, the value will be converted into pixels.
                                  Type
                                  | string
                                  | {
                                  enter: string
                                  exit: string
                                  }
                                  Description
                                  The transition timing function. You may specify a single easing or an object containing independent values for enter and exit.
                                  Type
                                  boolean
                                  Description
                                  If true, the component will also fade in and out.
                                  Type
                                  boolean
                                  Description
                                  Show the component; triggers the enter or exit states
                                  Type
                                  Omit<
                                  DetailedHTMLProps<
                                  HTMLAttributes<HTMLDivElement>,
                                  HTMLDivElement
                                  >
                                  >
                                  Description
                                  Props for the element that wraps the children.
                                  Type
                                  boolean
                                  Description
                                  By default, the child component is mounted immediately along with the parent Transition component. If you want to "lazy mount" the component on the first in = true you can set mountOnEnter. After the first enter transition the component will stay mounted, even on "exited", unless you also specify unmountOnExit.
                                  Type
                                  Ref<HTMLElement>
                                  Description
                                  A React reference to DOM element that need to transition. example. When nodeRef prop is used, node is not passed to callback functions (e.g. onEnter) because user already has direct access to the node. When changing key prop of Transition in a TransitionGroup a new nodeRef needs to be provided to Transition with changed key prop. see also.
                                  Type
                                  (
                                  node: HTMLElement | object,
                                  isAppearing: boolean,
                                  ) => void
                                  Description
                                  Callback fired before the "entering" status is applied. An extra parameter isAppearing is supplied to indicate if the enter stage is occurring on the initial mount
                                      Type
                                      (
                                      node: HTMLElement | object,
                                      isAppearing: boolean,
                                      ) => void
                                      Description
                                      Callback fired after the "entered" status is applied. An extra parameter isAppearing is supplied to indicate if the enter stage is occurring on the initial mount
                                          Type
                                          (
                                          node: HTMLElement | object,
                                          isAppearing: boolean,
                                          ) => void
                                          Description
                                          Callback fired after the "entering" status is applied. An extra parameter isAppearing is supplied to indicate if the enter stage is occurring on the initial mount
                                              Type
                                              (
                                              node: HTMLElement | object,
                                              ) => void
                                              Description
                                              Callback fired before the "exiting" status is applied.
                                                  Type
                                                  (
                                                  node: HTMLElement | object,
                                                  ) => void
                                                  Description
                                                  Callback fired after the "exited" status is applied.
                                                      Type
                                                      (
                                                      node: HTMLElement | object,
                                                      ) => void
                                                      Description
                                                      Callback fired after the "exiting" status is applied.
                                                          Description
                                                          Inline styles
                                                          Type
                                                          | number
                                                          | 'auto'
                                                          | {
                                                          appear?: number
                                                          enter?: number
                                                          exit?: number
                                                          }
                                                          Description
                                                          The duration of the transition, in milliseconds. If supplied as 'auto', the duration will be computed based on the height of the component's child element.
                                                          Type
                                                          boolean
                                                          Description
                                                          By default, the child component stays mounted after it reaches the 'exited' state. Set unmountOnExit if you'd prefer to unmount the component after it finishes exiting.