UX4G Logo
Components

Accordion

Expandable disclosure panels and grouped FAQ lists in Jetpack Compose

Expandable disclosure panels and grouped FAQ lists in Jetpack Compose.

Import from com.ux4g.designsystemv1.components.Ux4gAccordion.


Interactive Preview

Ux4gAccordionJetpack Compose
UX4G Accordion Preview

Kotlin Usage

Standalone Accordion Example
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.material3.Text
import com.ux4g.designsystemv1.components.Ux4gAccordion
import com.ux4g.designsystemv1.components.Ux4gAccordionChevronPosition
import com.ux4g.designsystemv1.theme.Ux4gTheme
import com.ux4g.designsystemv1.foundation.Ux4gColors

@Composable
fun SingleAccordionExample() {
    var expanded by remember { mutableStateOf(false) }

    Ux4gAccordion(
        title = "What documents are required for Income Certificate?",
        expanded = expanded,
        onExpandedChange = { expanded = it },
        chevronPosition = Ux4gAccordionChevronPosition.Trailing
    ) {
        Text(
            text = "1. Aadhaar Card of the applicant\n2. Salary slips for last 3 months or ITR\n3. Proof of residence (Electricity bill / Ration card)",
            style = Ux4gTheme.typography.bXS_default,
            color = Ux4gColors.neutral600
        )
    }
}
Grouped Accordion Example
import androidx.compose.runtime.*
import androidx.compose.material3.Text
import com.ux4g.designsystemv1.components.Ux4gAccordionGroup
import com.ux4g.designsystemv1.components.Ux4gAccordionItem
import com.ux4g.designsystemv1.theme.Ux4gTheme
import com.ux4g.designsystemv1.foundation.Ux4gColors

@Composable
fun GroupedAccordionExample() {
    var expandedIndex by remember { mutableStateOf<Int?>(0) }

    val items = listOf(
        Ux4gAccordionItem(title = "General Information"),
        Ux4gAccordionItem(title = "Eligibility Criteria"),
        Ux4gAccordionItem(title = "Fee Structure & Payment", enabled = false)
    )

    Ux4gAccordionGroup(
        items = items,
        expandedIndex = expandedIndex,
        onExpandedIndexChange = { expandedIndex = it }
    ) { index, item ->
        Text(
            text = "Detailed information for ${item.title}",
            style = Ux4gTheme.typography.bXS_default,
            color = Ux4gColors.neutral600
        )
    }
}

Parameters

Ux4gAccordion Props

PropTypeDescriptionDefault
title *StringHeader text displayed on the accordion panel.—
content *@Composable () -> UnitContent composable shown when expanded.{}
modifierModifierCompose layout modifier applied to the accordion container.Modifier
expandedBooleanCurrent expanded state of the panel.false
enabledBooleanWhen false, header is grayed out and non-interactive.true
onExpandedChange((Boolean) -> Unit)?Called when the panel is toggled.null
backgroundColorColor?Header background. Defaults to colors.surface (theme-aware).null
disabledBackgroundColorColor?Header background when disabled. Defaults to Ux4gColors.neutral100.null
contentBackgroundColorColor?Background of the expanded content area only. Defaults to colors.surface.null
collapsedBorderColorColor?Border when collapsed. Defaults to colors.onSurface at 12% opacity (theme-aware).null
expandedBorderColorColor?Border when expanded. Defaults to collapsedBorderColor.null
disabledBorderColorColor?Border when disabled. Defaults to colors.onSurface at 12% opacity (theme-aware).null
titleColorColor?Header title text color when enabled. Defaults to colors.onSurface.null
disabledTitleColorColor?Header title text color when disabled. Defaults to colors.onSurface at 38% opacity.null
iconColorColor?Chevron and leading icon color when enabled. Defaults to colors.onSurface.null
disabledIconColorColor?Chevron and leading icon color when disabled. Defaults to colors.onSurface at 38% opacity.null
leadingIcon(@Composable () -> Unit)?Optional custom composable icon displayed before title.null
chevronPositionUx4gAccordionChevronPositionPosition of expand/collapse arrow icon (Leading or Trailing).Trailing

Ux4gAccordionGroup Props

PropTypeDescriptionDefault
items *List<Ux4gAccordionItem>List of accordion item configuration models to display.—
content *@Composable (index: Int, item: Ux4gAccordionItem) -> UnitComposable lambda rendering the expanded body for each item.—
modifierModifierCompose layout modifier applied to the group container.Modifier
expandedIndexInt?Index of the currently expanded item, or null if all collapsed.null
onExpandedIndexChange(Int?) -> UnitCallback invoked when an item is expanded or collapsed.{}
itemSpacingDpVertical spacing between accordion items.20.dp

Ux4gAccordionItem Data Class

PropTypeDescriptionDefault
title *StringHeader title text for the accordion item.—
enabledBooleanWhether this item is interactive or disabled.true
leadingIcon(@Composable () -> Unit)?Optional leading icon composable slot before the title.null
chevronPositionUx4gAccordionChevronPositionChevron icon placement (Leading or Trailing).Trailing

Ux4gAccordionChevronPosition Enum

ValueDescription
LeadingPosition chevron arrow at the start (left side) of the header row.
TrailingPosition chevron arrow at the end (right side) of the header row (default).

On this page