Command palette

@yasinsensoy/native

React Native · Components

Collapsible

A single collapsible section: "Advanced settings", "Show details", "Show more" on long text.

2 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { Collapsible } from "@yasinsensoy/native";

<Collapsible title="Advanced settings" description="Most users don't need to change these.">
  …
</Collapsible>

Events

  1. Events appear here when you interact with the preview.

With your own button

Import

import { Collapsible } from "@yasinsensoy/native";

Collapsible

component

A single collapsible section: "Advanced settings", "Show details", "Show more" on long text. For multiple sections use Accordion. Height is animated; instant with "reduce motion".

Collapsible({ ref, children, title, description, icon, trigger, open: openProp, defaultOpen, onOpenChange, disabled, collapsedHeight, showMoreLabel, showLessLabel, effect, style, }: CollapsibleProps): JSX.Element

Examples

<Collapsible title="Advanced settings" icon="settings">
  <Switch label="Debugging" />
</Collapsible>
<Collapsible collapsedHeight={96}>{product.longDescription}</Collapsible>

Props of Collapsible.

NameTypeDefaultDescription
ref?Ref<ViewRef>Ref of the underlying native element.
children?ReactNodeContent that opens and closes.
title?ReactNodeText of the built-in header row. Not used if trigger is given.
description?ReactNodeSmall description below the title.
icon?IconPropIcon at the start of the title.
trigger?ReactElement<{ onPress?: (...args: never[]) => unknown; "aria-expanded"?: boolean; }>Your own toggle button instead of the built-in header (e.g. <Button variant="ghost">). Toggles on press; onPress and aria-expanded are added.
open?booleanOpen (controlled).
defaultOpen?booleanfalseInitially open (uncontrolled).
onOpenChange?(open: boolean) => voidWhen it opens or closes.
disabled?booleanCannot be toggled.
collapsedHeight?number"Show more" mode: while closed this much of the content (pixels) is visible, ending with a fading bottom edge; the button below opens it fully. If the content is shorter, no button appears.
showMoreLabel?ReactNodethe {@link UIProvider} textText of the "Show more" button.
showLessLabel?ReactNodethe {@link UIProvider} textText of the "Show less" button.
effect?EffectPropEffect of the built-in header row ("ripple", "glow"…). Defaults to appearance.defaults.collapsible.effect. See BuiltinEffect.
style?StyleProp<ViewStyle>Container style.