# Disclosure

> One collapsible section with an arrow. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/disclosure/

:::tip[In plain words]
A section with a little arrow that shows or hides extra details.
:::

A header with an arrow that shows or hides `content`. You own the open state: change it in `on_toggle`.

`ui.disclosure` · Category: [Lists and menus](https://albakore.github.io/pyzed/library/#lists-and-menus) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#disclosure)

**Code:**

```python
pz.column([
    ui.disclosure("Advanced options", ui.muted("Shown while the section is open."), open=True,
                  on_toggle=on_toggle),
    ui.disclosure("Environment variables", ui.muted("Hidden"), open=False, on_toggle=on_toggle,
                  end=ui.badge("3")),
], spacing=10, width=380)
```

## When to use

- To hide advanced options or details until they are needed.

## Usage

```python
import pyzed as pz
from pyzed import ui

class Form(pz.App):
    def __init__(self):
        self.advanced = False

    def view(self):
        return ui.disclosure("Advanced options", self.advanced_options(), open=self.advanced,
                             on_toggle=lambda: setattr(self, "advanced", not self.advanced))
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in One Dark or One Light to match this site's theme, and cropped to the component so it shows at its real size. The pointer hovers, presses or types into it; a component that does not react to the pointer cycles through a few themes. With reduced motion you see the first frame. Open **Code** under a capture to see the snippet that draws it; free names such as `on_save` stand for your own callbacks.
:::

### State

```python
pz.container(ui.disclosure("Advanced options", ui.muted("…"), open=False, on_toggle=on_toggle), width=300)
```

```python
pz.container(ui.disclosure("Advanced options", ui.muted("Shown while open."), open=True,
                           on_toggle=on_toggle), width=300)
```

```python
pz.container(ui.disclosure("Environment", ui.muted("…"), open=False, on_toggle=on_toggle,
                           end=ui.badge("3")), width=300)
```

## Events

Disclosure has **1 event of its own**, listed below. Like every widget it also has the **18 common events** (`click`, `double_click`, `right_click`, `mouse_enter`, `drag`, `key_down`, `resize`…), attached with `.on(...)`: see [Events](https://albakore.github.io/pyzed/guides/events/) and [Events of every component](https://albakore.github.io/pyzed/library/events/).

| Event | Handler gets | When |
| --- | --- | --- |
| `on_toggle` | `()` | Message or callable when the header is clicked. |

**Handler gets** is what Pyzed passes to your callable: `()` means nothing. Any handler can also be a message (a value that is not callable), which goes to `update()`.

### Handling the events

The same events written three ways. **Imperative**: methods of the app change `self`. **Declarative**: the handlers produce messages and one `update()` decides. **Functional**: a pure function draws an immutable state and asks for changes with `set_state(...)`. See [Imperative, declarative and functional](https://albakore.github.io/pyzed/guides/code-styles/).

**Imperative:**

```python
class Form(pz.App):
    def __init__(self):
        self.advanced = False

    def view(self):
        return ui.disclosure("Advanced options", ui.muted("Proxy, timeouts…"), open=self.advanced,
                             on_toggle=lambda: setattr(self, "advanced", not self.advanced))  # no argument
```

**Declarative:**

```python
class Form(pz.App):
    advanced = False

    def update(self, message):
        if message == "toggle advanced":
            self.advanced = not self.advanced

    def view(self):
        return ui.disclosure("Advanced options", ui.muted("…"), open=self.advanced,
                             on_toggle="toggle advanced")
```

**Functional:**

```python
from dataclasses import dataclass

@dataclass(frozen=True)
class State:
    advanced: bool = False

def view(state, set_state):
    return ui.disclosure("Advanced options", ui.muted("…"), open=state.advanced,
                         on_toggle=lambda: set_state(advanced=not state.advanced))
```

## Properties and API

### `ui.disclosure`

```python
disclosure(title, content, *, open, on_toggle=None, end=None, theme=None)
```

A collapsible section: a header with an arrow that shows or hides `content`. You own the open state: change it in `on_toggle`.

| Property | Default | Description |
| --- | --- | --- |
| `title` | *required* | Title (text or widget). |
| `content` | *required* | Content. |
| `open` | *required* | Whether it is open. |
| `end` | `None` | Widgets at the end (right). |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

Events: `on_toggle` ([events](#events)).

[Full reference →](https://albakore.github.io/pyzed/reference/ui/#disclosure)

## Related

- [Accordion](https://albakore.github.io/pyzed/library/accordion/): Stacked collapsible sections, like the panels of a settings screen.
- [Card](https://albakore.github.io/pyzed/library/card/): A bordered surface with an optional title and actions.
