# Dash Mantine Components Documentation
> Dash Mantine Components (DMC) is a component library for building modern web applications with [Dash](https://dash.plotly.com/).
> It provides a wide range of accessible, themeable, and performant UI components built on top of the [Mantine](https://v8.mantine.dev/) React library.
>
> This documentation applies to **DMC 3.0.0**, which wraps **Mantine 9.7.4**.
> For additional details about underlying component behavior and styling, refer to the Mantine documentation: https://v8.mantine.dev/
> All relative links in this file should be resolved against https://www.dash-mantine-components.com
>
> Assume the reader is a Dash developer familiar with callbacks and layout, but not necessarily with Mantine.
================================================================================
## Getting Started
Build feature-rich, accessible Dash apps faster than ever! Dash Mantine Components includes over 100 customizable components based on the React Mantine library, with consistent styling, theming, and full support for light and dark mode.
Category: General
### Installation
```bash
pip install dash-mantine-components
pip install dash>=4.5
```
### Requires React 19
`dash-mantine-components>=3 requires React 19.
Set in your app:
```python
import dash
dash._dash_renderer._set_react_version("19.2.4")
app = dash.Dash()
```
Or set the React version with an environment variable:
```bash
REACT_VERSION=19.2.4 python app.py
````
### Basic Usage
```python
import dash_mantine_components as dmc
from dash import Dash, _dash_renderer
_dash_renderer._set_react_version("19.2.4")
app = Dash()
app.layout = dmc.MantineProvider(
dmc.Alert(
"Welcome to Dash Mantine Components",
title="Hello!",
color="violet",
)
)
if __name__ == "__main__":
app.run(debug=True)
```
### Important Notes
#### Wrap the layout with `MantineProvider`
```python
app.layout = dmc.MantineProvider(
# your content
)
```
The `MantineProvider` is a core wrapper component that handles global styles, themes, and settings for all child components.
It’s required to:
- Enable component styling and theming (e.g., colors, fonts, spacing)
- Apply dark/light mode
- Customize default props across the app
- Register custom themes or override styles
### Documentation
This documentation site is built almost entirely with Dash Mantine Components.
You can explore the source code on the [dcm-docs GitHub](https://github.com/snehilvj/dmc-docs) for ideas and inspiration.
Throughout the docs, you’ll find interactive demos that highlight how different props and combinations affect each component in real time.
Note that this documentation has some additional styling applied to it. So when you actually use these components, they
might look a bit different. You can check out [MantineProvider theme object](/theme-object) for more details on
theming and customizations and to see the [theme used in these docs.](/theme-object#usage-in-dmc-docs)
### Next Steps
Please read the [Mantine API Overview](/mantine-api) section before starting development to learn about all of the
available theming and styling features.
Using older versions of dash or DMC? See our [Migration Guide](/migration) for more information.
### Questions?
Please ask on the [dash community forum](https://community.plotly.com/), or join our [Discord.](https://discord.gg/KuJkh4Pyq5)
## Help Center
Frequently asked questions and links to more examples
Category: General
### Where can I find the roadmap?
Our [roadmap](https://github.com/snehilvj/dash-mantine-components/discussions/377) on GitHub outlines our development goals and priorities. It is updated regularly to reflect progress and
new plans in DMC and changes in the upstream Mantine library.
### Where can I find release announcements?
[Release announcements](https://github.com/snehilvj/dash-mantine-components/discussions/categories/releases) are
available in GitHub Discussions. They include detailed descriptions and examples of new features and updates to the documentation.
### How can I help?
We welcome contributions!
- Bug Reports: Please open or comment on [issues](https://github.com/snehilvj/dash-mantine-components/issues).
- Feature Requests: Use [Discussions](https://github.com/snehilvj/dash-mantine-components/discussions/categories/ideas).
- Pull Requests: See our [Contributing Guide](https://github.com/snehilvj/dash-mantine-components/blob/master/CONTRIBUTING.md).
- Documentation: Updating the docs is a great starting point for first-time contributors since the project is a Dash app built with `dash-mantine-components`. For more details, check out the [dmc-docs GitHub](https://github.com/snehilvj/dmc-docs).
### Where can I find more examples?
- [Dash Mantine Components PyCafe](https://py.cafe/dash.mantine.components): Browse dozens of complete, minimal examples you can run and edit in your browser.
- The [help_center](https://github.com/snehilvj/dmc-docs/tree/main/help_center) folder in the dmc-docs GitHub for additional examples.
- [DMC DBC Building Blocks](https://dash-building-blocks.com/) site for more minimal code blocks to add to your app.
- [Tips and Tricks](https://github.com/snehilvj/dash-mantine-components/discussions/categories/tips-and-tricks) section of GitHub Discussions:
- Frequently asked questions
- Examples of using DMC components in Dash AG Grid
- KPI cards examples
- AppShell examples with responsive layouts for headers, navbars, footers, and aside
- Theme switch components
- Plotly figures with a Mantine theme
- ...and more! Content is updated regularly
### Need more help?
- Join our [Discord](https://discord.gg/KuJkh4Pyq5) to connect with other contributors.
- Visit the [Plotly Dash Community Forum](https://community.plotly.com/) for discussions and support.
- Use [GitHub Discussions]() to ask questions and find more examples.
- Check out the upstream [Mantine Help Center](https://help.mantine.dev/). The code snippets are in TypeScript, but we can help with those. There’s great content applicable to DMC as well.
## LLMs.txt
Dash Mantine Components provides LLM-friendly documentation to help AI tools like Cursor, Windsurf, GitHub Copilot, ChatGPT, and Claude understand and work with the DMC library.
Category: General
### Documentation
The complete DMC documentation is available in an LLM-friendly format.
- [View DMC llms.txt](https://www.dash-mantine-components.com/assets/llms.txt)
- [View DMC llms.json](https://www.dash-mantine-components.com/assets/llms.json)
- [View Mantine v9 llms.txt](https://mantine.dev/llms.txt)
DMC v3 is based on Mantine v9. Mantine's documentation, MCP server, and skills can help AI tools understand component APIs and behavior. See the [Mantine guide for LLMs](https://mantine.dev/guides/llms/) for details.
### Getting Documentation for AI Tools
You can provide documentation to AI tools in several ways.
#### Complete documentation
Reference the [DMC llms.txt](https://www.dash-mantine-components.com/assets/llms.txt) URL in your prompt or add it to your coding tool's documentation sources.
For best results, specify that you are using DMC v3 and ask the AI to use DMC's Python API rather than Mantine's React API. Mantine documentation can help explain component behavior, but check the DMC documentation for supported props and Dash-specific usage.
#### Individual documentation pages
You can get a text version of any DMC documentation page by adding `.txt` to its URL.
For example, the text version of the Chip documentation is available at [components/chip.txt](https://www.dash-mantine-components.com/components/chip.txt).
Each documentation page also includes a **Copy for LLMs** button that copies the page content in a format suitable for AI tools. Use this when you only need to provide documentation for a few components.
#### Customized documentation
You can create a smaller `llms.txt` file containing only the components and categories relevant to your project. This can reduce unrelated content and help AI tools focus on the APIs you use.
Options for creating a custom file are provided below.
### Example Prompts
- "Using DMC v3, create a dark mode toggle with MantineProvider."
- "Build a responsive layout using DMC v3. Use Mantine v9 documentation for component behavior and the DMC docs for Python props and examples."
- "Show me how to use AppShell with a collapsible navbar in DMC."
- "Use DMC components to align an input and a button in a flex container."
- "Refer only to these DMC documentation pages when generating examples: [paste documentation URLs]."
### Documentation Generation
The LLM documentation is generated from the DMC documentation source and updated with each release.
### Creating a Custom llms.txt File
Using only the documentation you need can make AI responses more focused.
#### Option 1: Use the customization app
Use the interactive tool below to select component categories, such as layout, inputs, or feedback, or individual components such as `AppShell`, `Card`, or `Button`. Then download your customized file.
#### Option 2: Build your own from llms.json
Use the structured data in [llms.json](https://www.dash-mantine-components.com/assets/llms.json) to create a custom file.
Each entry represents a documentation page and includes fields such as `name`, `description`, `category`, and `content`. You can filter and combine entries based on the components or categories relevant to your project.
#### Option 3: Copy individual pages
Use the **Copy for LLMs** button on a documentation page to copy its content directly into an AI conversation. This is useful when you only need information about one or two components.
### Contributing
If you find issues with the LLM documentation or have suggestions for improvement, please [open an issue](https://github.com/snehilvj/dmc-docs/issues) in the documentation repository.
## Mantine API Overview
A guide to help you get familiar with core Mantine concepts.
Category: General
### MantineProvider
Wrap your `app.layout` with a `MantineProvider` to manage your app’s overall theme, including colors, spacing, fonts,
and light/dark mode. It also exposes Mantine CSS variables based on your theme settings.
```python
import dash_mantine_components as dmc
from dash import Dash
app = Dash()
app.layout = dmc.MantineProvider(
# children=[] your layout here
)
if __name__ == "__main__":
app.run(debug=True)
```
### Light Dark Color scheme
All Mantine components support light, dark and auto color schemes.
The default color scheme is light. You can set the default color scheme on `MantineProvider`:
See the Theming section for examples of a [Theme Switch Component](/theme-switch)
### Theme object
Mantine’s [default theme](/theme-object#default-theme) makes Dash apps look great in both light and dark modes. If you’re new to Dash Mantine Components,
start with the default theme. You can customize the theme globally by editing the `theme` prop in the `MantineProvider`.
The `theme` object is a dictionary where you can set things like colors, border radius, spacing, fonts, and breakpoints globally.
Mantine will merge your custom theme with the defaults, so you just need to provide what you want to change.
See the [Theme Object documentation](/theme-object) for all options.
```python
# Your theme is merged with default theme
theme = {
"fontFamily": "Montserrat, sans-serif",
"defaultRadius": "md",
}
app.layout = dmc.MantineProvider(
# children=[] your layout here
theme=theme
)
```
This example demonstrates how changing the `theme` updates the entire app’s appearance. Here, we change:
- Primary accent color
- Border radius
- Card shadow style
- Color scheme (light/dark)
Try it live: [DMC Theme Builder on Pycafe](https://py.cafe/app/dash.mantine.components/dash-mantine-theme-builder)
---
---
Most of the theme values are exposed as CSS variables and can be accessed
both in component props and CSS.
Accessing theme values in a `.css` file in the `/assets` folder:
```css
.demo {
background: var(--mantine-color-red-1);
color: var(--mantine-color-red-9);
font-family: var(--mantine-font-family);
border-radius: var(--mantine-radius-md);
}
```
Accessing CSS variables in the `style` or `styles` prop in a component
```python
dmc.Card(style={"backgroundColor":"var(--mantine-color-red-1)"})
```
### Component specific props
Most of the components provide props that allow you to customize their styles. For example, `Button` component has
`color`, `variant`, `size` and `radius` props that control its appearance:
### Style props
[Style props](/style-props) work similar to component specific props, but with several differences:
- Style props are not component specific, they can be used with any component.
- Style props always control a single CSS property. For example, `c` prop controls CSS `color` property, while `color` prop controls a set of properties: `color`, `background-color` and `border-color`.
- Style props are set in style attribute. It is not possible to override them with CSS without using `!important`.
[Style props](/style-props) are useful when you need to change a single CSS property without creating a separate file for styles. Some of the most common use cases are:
- Changing text color and font-size
```python
dmc.Card([
dmc.Text("Card title", c="blue.8", fz="lg"),
dmc.Text("Card description", c="dimmed", fz="sm")
])
```
- Applying margins to inputs inside a form:
```python
dmc.Paper([
dmc.TextInput(label="First name"),
dmc.TextInput(label="Last name", mt="md"),
dmc.TextInput(label="Email", mt="md")
])
```
- Adding padding to various elements:
```python
dmc.Paper("My custom card", p="xl")
```
Note that style props were never intended to be used as a primary way of styling components. In most cases, it is better
to limit the number of style props used per component to 3-4. If you find yourself using more than 4 style props,
consider creating a separate CSS file with styles – it will be easier to maintain and will be more performant.
### style prop
You can use the `style` prop to define inline styles, just like in other dash components:
```python
dmc.Card(style={"backgroundColor": "blue", "color": "white"})
```
### className prop
You can define CSS classes in a `.css` file in the `/assets` folder. These can then be referenced using the `className` prop, just like in other dash components:
```python
dmc.Card(className="card-style")
```
.css file:
```css
.card-style {
background-color: blue;
color: white;
}
```
### Styles API
Note that the `style` and the `className` props will apply style to the root of the component. Many DMC components contain
multiple elements, for example the `TextInput` includes `label`, `description`, `error` props.
Use the `classNames` or `styles` props to target the nested elements.
- `styles` prop: Used to apply inline styles directly to specific inner elements of a Mantine component.
- `classNames`prop: Used to apply custom CSS class names to specific inner elements of a Mantine component
See more information in the [StylesAPI](/styles-api) section.
### Colors
Colors are stored in `theme['colors']` dict and are exposed as CSS variables. Each color must have at least 10 shades.
You can generate new colors based on a single color value with the [Mantine colors generator](https://mantine.dev/colors-generator/).
Colors are numbered from 0 to 9 where 0 is the lightest and 9 is the darkest color. Example of blue color from the default theme:
To access colors in styles use CSS variables:
```css
.demo {
background: var(--mantine-color-blue-9);
color: var(--mantine-color-blue-0);
}
```
### CSS variables
Theme values are converted to [CSS variables](/css-variables) and are available to use in your styles. All Mantine CSS variables are
prefixed with `--mantine-`, for example:
- theme["fontFamily"] → --mantine-font-family
- theme["colors"]["blue"][9] → --mantine-color-blue-9
- theme["spacing"]["xl"] → --mantine-spacing-xl
### CSS Variables list
For a list of all Mantine CSS variables that are generated from default theme, see the [CSS variables](/css-variables) section.
## ActionIcon
Use this component as an alternative to buttons when you just want to use an icon.
Category: Buttons
### Introduction
### Usage
ActionIcon component is an alternative to [Button](/components/button) component. It can be customized with Mantine styles and used with its
`n_clicks` property.
```python
import dash_mantine_components as dmc
from dash import callback, html, Output, Input
from dash_iconify import DashIconify
component = html.Div(
[
dmc.ActionIcon(
DashIconify(icon="clarity:settings-line", width=20),
size="lg",
variant="filled",
id="action-icon",
n_clicks=0,
mb=10,
),
dmc.Text(id="action-output"),
]
)
@callback(
Output("action-output", "children"),
Input("action-icon", "n_clicks"),
)
def update_clicks(n_clicks):
return f"Clicked {n_clicks} times."
```
### Children
You can use a dash component such as `DashIconify` in the `children` prop. Note that it does not control the icon size,
you need to specify it manually on icon component to match `ActionIcon` size.
For example, if you were to use `DashIconify`, you can set the icon size like this:
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
dmc.ActionIcon(
DashIconify(icon="bi:github", width=20),
size="lg"
)
```
### Variants
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
[
dmc.ActionIcon(
DashIconify(icon="clarity:settings-line"), color="blue", variant=variant
)
for variant in [
"subtle",
"filled",
"outline",
"light",
"default",
"transparent",
"gradient",
"white"
]
]
)
```
### Gradient variant
When `variant` prop is set to `gradient`, you can control gradient with gradient prop, it accepts an object with
`from`, `to` and `deg` properties. If the `gradient` prop is not set, `ActionIcon` will use `defaultGradient` which can
be configured on the `theme` dict in the `MantineProvider`. `gradient` prop is ignored when `variant` is not set to `gradient`.
Note that `variant="gradient"` supports only linear gradients with two colors. If you need a more complex gradient, then
use `Styles API` to modify `ActionIcon` styles.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
[
dmc.ActionIcon(
DashIconify(icon="clarity:settings-line"),
color="blue",
variant="gradient",
gradient=gradient
)
for gradient in [
{"from": "red", "to": "blue", "deg": 90 },
{"from": "red", "to": "blue", "deg": 180},
{"from": "teal", "to": "yellow", "deg": 90},
{"from": "teal", "to": "yellow", "deg": 180}
]
]
)
```
### Colors
Here is a sample using the following colors:
"gray", "red", "pink", "grape", "violet", "indigo", "blue", "lime", "yellow", "orange"
And these variants:
"subtle", "filled", "outline", "light", "transparent"
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
dmc.ActionIcon(
DashIconify(icon="icomoon-free:sun"),
variant="outline",
color="orange",
)
```
### Size
You can use any valid CSS value in `size` prop, it is used to set `width`, `min-width`, `min-height` and `height`
properties. Note that `size` prop does not control child icon size, you need to set it manually on icon component.
When size is a number, the value is treated as `px` units and converted to `rem` units.
```python
dmc.ActionIcon(size=20, children=[...])
```
If you want `ActionIcon` to have the same size as Mantine inputs, use `size="input-sm"` prop:
```python
import dash_mantine_components as dmc
component = dmc.Group([
dmc.TextInput(placeholder="sm sixe input", size="sm"),
dmc.ActionIcon(
size="input-sm",
variant="default",
children="SM"
)
])
```
### Loading state
When `loading` prop is set, `ActionIcon` will be disabled and `Loader` with overlay will be rendered in the center of
the button. Loader color depends on `ActionIcon` variant.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
from dash import callback, Input, Output
component = dmc.Box([
dmc.Group(
[
dmc.ActionIcon(
id="icon-loading-default",
children=DashIconify(icon="tabler:heart", width=18, height=18)
),
dmc.ActionIcon(
id="icon-loading-light",
children=DashIconify(icon="tabler:heart", width=18, height=18),
variant="light",
),
dmc.ActionIcon(
id="icon-loading-outline",
children=DashIconify(icon="tabler:heart", width=18, height=18),
variant="outline",
),
]
),
dmc.Switch(
id="loading-switch",
label="Loading state",
checked=False,
mt="md",
),
])
@callback(
Output("icon-loading-default", "loading"),
Output("icon-loading-light", "loading"),
Output("icon-loading-outline", "loading"),
Input("loading-switch", "checked"),
)
def toggle_loading(loading_state):
return loading_state, loading_state, loading_state
```
### Loader props
You can customize Loader with `loaderProps` prop, it accepts all props that `Loader` component has:
```python
import dash_mantine_components as dmc
component = dmc.ActionIcon(size="xl", loading=True, loaderProps={"type": "dots"})
```
### Add custom variants
To add new `ActionIcon` variants, define a class in the `.css` file using the data-variant attribute. Add the new variants to
the `theme` prop in the `MantineProvider` so they available in all `ActionIcon` components in your app.
Example:
- [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/theme/action_icon_custom_variants.py)
- [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/actionicon-custom-variants-demo)
The example includes the following in a .css file in /assets
```css
.ai-custom-variants {
&[data-variant='danger'] {
background-color: var(--mantine-color-red-9);
color: var(--mantine-color-red-0);
}
&[data-variant='primary'] {
background: linear-gradient(45deg, #4b6cb7 10%, #253b67 90%);
color: var(--mantine-color-white);
}
}
```
The example adds the custom variants to the `theme` prop in `Mantine Provider`
```python
app.layout = dmc.MantineProvider(
children=[# your app content],
theme={
"components": {
"ActionIcon": {"classNames": {"root": "ai-custom-variants"}}
}
}
)
```
### autoContrast
`ActionIcon` supports `autoContrast` prop. You can also set `autoContrast` in the `theme` prop in the `MantineProvider`.
If `autoContrast` is set either on `ActionIcon` or on `theme`, content color will be adjusted to have sufficient
contrast with the value specified in `color` prop.
Note that `autoContrast` feature works only if you use `color` prop to change background color. `autoContrast` works
only with `filled` variant.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
[
dmc.ActionIcon(
children=DashIconify(icon="tabler:heart", width=18, height=18),
color="lime.3"
),
dmc.ActionIcon(
children=DashIconify(icon="tabler:heart", width=18, height=18),
color="lime.3",
autoContrast=True
),
]
)
```
### ActionIconGroup
```python
dmc.ActionIconGroup(
[
dmc.ActionIcon(
variant="default",
size="lg",
children=DashIconify(icon="tabler:photo", width=20),
),
dmc.ActionIcon(
variant="default",
size="lg",
children=DashIconify(icon="tabler:settings", width=20),
),
dmc.ActionIcon(
variant="default",
size="lg",
children=DashIconify(icon="tabler:heart", width=20),
),
],
orientation="horizontal"
)
```
Note that you must not wrap child `ActionIcon` components with any additional elements:
```python
dmc.ActionIconGroup([
html.Div(dmc.ActionIcon(...)), # don't do it like this
dmc.ActionIcon(...)
])
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### ActionIcon Selectors
| Selector | Static selector | Description |
|----------|--------------------------------|------------------------------------------------------------|
| root | .mantine-ActionIcon-root | Root element |
| loader | .mantine-ActionIcon-loader | Loader component, rendered inside the root element when `loading` prop is set |
| icon | .mantine-ActionIcon-icon | Inner icon wrapper |
#### ActionIcon CSS Variables
| Selector | Variable | Description |
|----------|-----------------|----------------------------------------------|
| root | --ai-bg | Controls background |
| | --ai-hover | Controls background when hovered |
| | --ai-bd | Controls border |
| | --ai-color | Controls icon color |
| | --ai-hover-color| Controls icon color when hovered |
| | --ai-radius | Controls border-radius |
| | --ai-size | Controls width, height, min-width, and min-height styles |
#### ActionIcon Data Attributes
| Selector | Attribute | Condition |
|---------------|-----------------|----------------------------|
| root | data-disabled | `disabled` prop is set |
| root, icon | data-loading | `loading` prop is set |
#### ActionIconGroup Selectors
| Selector | Static selector | Description |
|----------|-------------------------------------|---------------------------------|
| group | .mantine-ActionIconGroup-group | Root element |
#### ActionIconGroup CSS Variables
| Selector | Variable | Description |
|----------|---------------------|------------------------------------------------------------------|
| group | --ai-border-width | Controls border width of child `ActionIcon` components placed beside one another |
#### ActionIconGroup Data Attributes
| Selector | Attribute | Value |
|----------|------------------|----------------------------|
| group | data-orientation | Value of `orientation` prop |
### Keyword Arguments
#### ActionIcon
- children (a list of or a singular dash component, string or number; optional):
Icon displayed inside the button.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether button text color with filled variant should
depend on `background-color`. If luminosity of the `color` prop is
less than `theme.luminosityThreshold`, then `theme.white` will be
used for text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- buttonProps (dict; optional):
Props passed down to the `Button` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color. Default value is
`theme.primaryColor`.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- disabled (boolean; optional):
Sets `disabled` and `data-disabled` attributes on the button
element.
- gradient (dict; optional):
Gradient data used when `variant="gradient"`, default value is
`theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loaderProps (dict; optional):
Props added to the `Loader` component (only visible when `loading`
prop is set).
`loaderProps` is a dict with keys:
- loading (boolean; optional):
Determines whether `Loader` component should be displayed instead
of the `children`, `False` by default.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- n_clicks (number; default 0):
An integer that represents the number of times that this element
has been clicked on.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius.
Numbers are converted to rem. `theme.defaultRadius` by default.
- size (number; optional):
Controls width and height of the button. Numbers are converted to
rem. `'md'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### ActionIcon Group
- children (a list of or a singular dash component, string or number; optional):
`ActionIcon` components only.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- borderWidth (string | number; optional):
`border-width` of the child `ActionIcon` components. Default value
in `1`.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Controls group orientation, `'horizontal'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Button
DMC alternative to html.Button.
Category: Buttons
### Introduction
### Variant
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Button("Default button"),
dmc.Button("Subtle button", variant="subtle"),
dmc.Button("Gradient button", variant="gradient"),
dmc.Button("Filled button", variant="filled"),
dmc.Button("Light button", variant="light"),
dmc.Button("Outline button", variant="outline"),
dmc.Button("Transparent", variant="transparent"),
dmc.Button("White", variant="white"),
]
)
```
#### Gradient Variant
To use gradient as Button background:
* set `variant` prop to "gradient"
* set `gradient` prop to `{ 'from': 'color-from', 'to': 'color-to', 'deg': 135}`, where
* `color-from` and `color-to` are colors from Mantine's theme colors.
* `deg` is linear gradient deg.
```python
import dash_mantine_components as dmc
component = dmc.Group(
children=[
dmc.Button(
"Indigo cyan",
variant="gradient",
gradient={"from": "indigo", "to": "cyan"},
),
dmc.Button(
"Lime green",
variant="gradient",
gradient={"from": "teal", "to": "lime", "deg": 105},
),
dmc.Button(
"Teal blue",
variant="gradient",
gradient={"from": "teal", "to": "blue", "deg": 60},
),
dmc.Button(
"Orange red",
variant="gradient",
gradient={"from": "orange", "to": "red"},
),
dmc.Button(
"Grape pink",
variant="gradient",
gradient={"from": "grape", "to": "pink", "deg": 35},
),
]
)
```
### Left and right sections
`leftSection` and `rightSection` allow adding icons or any other element to the left and right side of the button.
When a section is added, padding on the corresponding side is reduced.
Note that `leftSection` and `rightSection` are flipped in RTL mode (`leftSection` is displayed on the right and `rightSection` is displayed on the left).
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
[
dmc.Button(
"Connect to Database",
leftSection=DashIconify(icon="fluent:database-plug-connected-20-filled"),
),
dmc.Button(
"Load Data",
variant="subtle",
rightSection=DashIconify(icon="logos:twitter"),
color="blue",
),
dmc.Button(
"Settings",
variant="outline",
leftSection=DashIconify(icon="fluent:settings-32-regular"),
),
]
)
```
### Sections position
`justify` prop sets `justify-content` of inner element. You can use it to change the alignment of left and right sections.
For example, to spread them across the button set `justify='space-between'`.
If you need to align just one section to the side of the button, set `justify` to `space-between` and add empty `html.Span()` to the opposite section.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
from dash import html
icon = DashIconify(icon="tabler:photo", width=14)
component = dmc.Stack(
[
dmc.Button(
"Button label",
justify="center",
fullWidth=True,
leftSection=icon,
rightSection=icon,
variant="default",
),
dmc.Button(
"Button label",
justify="center",
fullWidth=True,
leftSection=icon,
variant="default",
mt="md",
),
dmc.Button(
"Button label",
justify="center",
fullWidth=True,
rightSection=icon,
variant="default",
mt="md",
),
dmc.Button(
"Button label",
justify="center",
fullWidth=True,
leftSection=html.Span(), # Empty spacer
rightSection=icon,
variant="default",
mt="md",
),
]
)
```
### Loading State
Starting with dash version 2.9.2, you can use duplicate callback outputs. Here's an example that lets you easily show
loading state while the callback is running. Note that the button is disabled automatically when `loading=True`
```python
import uuid
from time import sleep
import dash_mantine_components as dmc
from dash import html, callback, Output, Input, clientside_callback
from dash_iconify import DashIconify
component = html.Div(
[
dmc.Button(
"Load from database",
id="loading-button",
leftSection=DashIconify(icon="fluent:database-plug-connected-20-filled"),
),
dmc.Text(id="clicked-output", mt=10),
]
)
clientside_callback(
"""
function updateLoadingState(n_clicks) {
return true
}
""",
Output("loading-button", "loading", allow_duplicate=True),
Input("loading-button", "n_clicks"),
prevent_initial_call=True,
)
@callback(
Output("clicked-output", "children"),
Output("loading-button", "loading"),
Input("loading-button", "n_clicks"),
prevent_initial_call=True,
)
def load_from_db(n_clicks):
sleep(3)
return str(uuid.uuid4()), False
```
### Loader Props
You can customize [Loader](/components/loader) with `loaderProps` prop, it accepts all props that Loader component has:
```python
import dash_mantine_components as dmc
component = dmc.Button("Loading Props", loaderProps={"type": "dots"}, loading=True)
```
### Colors
```python
import dash_mantine_components as dmc
dmc.Button("Settings", color="red")
```
### Radius and Size
Button's radius and size can be customized by setting `radius` and `size` props. Both props have predefined values:
xs, sm, md, lg, xl. Alternatively, you can use a number to set radius, size in px.
```python
import dash_mantine_components as dmc
dmc.Group(
[
dmc.Button("Connect to Database", size="sm"),
dmc.Button("Notify", radius="xl"),
dmc.Button("Settings", size=20),
]
)
```
### Compact Size
```python
import dash_mantine_components as dmc
sizes = ["xs", "sm", "md", "lg", "xl"]
component = dmc.Stack(
[
dmc.Group(
[dmc.Button(f"Normal {size}", size=size) for size in sizes],
),
dmc.Group(
[dmc.Button(f"Compact {size}", size=f"compact-{size}") for size in sizes],
),
]
)
```
### Full Width Button
Pass `fullWidth=True` for a full width button.
```python
import dash_mantine_components as dmc
component = dmc.Button("Click to open the app", fullWidth=True, variant="outline")
```
### Add custom variants
To add new `Button` variants, define a class in the `.css` file using the `data-variant` attribute. Add the new variants to
the `theme` prop in the `MantineProvider` so they available in all `Button` components in your app.
Example:
- [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/theme/button_custom_variants.py)
- [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/button-custom-variants-demo-0)
The example includes the following in a .css file in /assets
```css
.button-custom-variants {
&[data-variant='danger'] {
background-color: var(--mantine-color-red-9);
color: var(--mantine-color-red-0);
}
&[data-variant='primary'] {
background: linear-gradient(45deg, #4b6cb7 10%, #253b67 90%);
color: var(--mantine-color-white);
border-width: 0;
}
}
```
The example adds the custom variants to the `theme` prop in `Mantine Provider`
```python
app.layout = dmc.MantineProvider(
children=[# your app content],
theme={
"components": {
"Button": {"classNames": {"root": "button-custom-variants"}}
}
}
)
```
### Button Group
```python
import dash_mantine_components as dmc
component = dmc.ButtonGroup(
[
dmc.Button("First", variant="outline"),
dmc.Button("Second", variant="outline"),
dmc.Button("Third", variant="outline"),
]
)
```
Note that you must not wrap child `Button` components with any additional elements:
```python
dmc.ButtonGroup([
html.Div(dmc.Button("This will not work")),
dmc.Button("Buttons will have incorrect borders")
])
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Button Selectors
| Selector | Static selector | Description |
|----------|---------------------------|----------------------------------------------------|
| root | .mantine-Button-root | Root element |
| loader | .mantine-Button-loader | Loader component, displayed only when `loading` prop is set |
| inner | .mantine-Button-inner | Contains all other elements, child of the root element |
| section | .mantine-Button-section | Left and right sections of the button |
| label | .mantine-Button-label | Button children |
#### Button CSS Variables
| Selector | Variable | Description |
|----------|---------------------------|---------------------------------------------------|
| root | --button-bg | Controls background |
| | --button-bd | Controls border |
| | --button-hover | Controls background when hovered |
| | --button-color | Controls text color |
| | --button-hover-color | Controls text color when hovered |
| | --button-radius | Controls border-radius |
| | --button-height | Controls height of the button |
| | --button-padding-x | Controls horizontal padding of the button |
| | --button-fz | Controls font-size of the button |
| | --button-justify | Controls `justify-content` of the inner element |
#### Button Data Attributes
| Selector | Attribute | Condition | Value |
|----------------|------------------------|--------------------------|---------------------------------|
| root | data-disabled | `disabled` prop is set | – |
| root, label | data-loading | `loading` prop is set | – |
| root | data-block | `fullWidth` prop is set | – |
| root | data-with-left-section | `leftSection` is set | – |
| root | data-with-right-section| `rightSection` is set | – |
| section | data-position | – | Section position: left or right |
#### Button.Group Selectors
| Selector | Static selector | Description |
|----------|-----------------------------|---------------------------|
| group | .mantine-ButtonGroup-group | Root element |
#### Button.Group CSS Variables
| Selector | Variable | Description |
|----------|---------------------------|-------------------------------------------|
| group | --button-border-width | Border-width of child Button components |
#### Button.Group Data Attributes
| Selector | Attribute | Value |
|----------|-------------------|-------------------------|
| group | data-orientation | Value of `orientation` prop |
### Keyword Arguments
#### Button
- children (a list of or a singular dash component, string or number; optional):
Button content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether button text color with filled variant should
depend on `background-color`. If luminosity of the `color` prop is
less than `theme.luminosityThreshold`, then `theme.white` will be
used for text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- buttonProps (dict; optional):
Props passed down to the `Button` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color, `theme.primaryColor`
by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- disabled (boolean; optional):
Indicates disabled state.
- fullWidth (boolean; optional):
Determines whether button should take 100% width of its parent
container, `False` by default.
- gradient (dict; optional):
Gradient configuration used when `variant="gradient"`, default
value is `theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- justify (optional):
Sets `justify-content` of `inner` element, can be used to change
distribution of sections and label, `'center'` by default.
- leftSection (a list of or a singular dash component, string or number; optional):
Content displayed on the left side of the button label.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loaderProps (dict; optional):
Props added to the `Loader` component (only visible when `loading`
prop is set).
`loaderProps` is a dict with keys:
- loading (boolean; optional):
Determines whether the `Loader` component should be displayed over
the button.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- n_clicks (number; default 0):
An integer that represents the number of times that this element
has been clicked on.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, `theme.defaultRadius` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content displayed on the right side of the button label.
- size (optional):
Controls button `height`, `font-size` and horizontal `padding`,
`'sm'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### ButtonGroup
- children (a list of or a singular dash component, string or number; optional):
`Button` components.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- borderWidth (string | number; optional):
`border-width` of the child `Button` components. Numbers are
converted to rem. Default value in `1`.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Orientation of the group, `horizontal` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## ColorSchemeToggle
Use ColorSchemeToggle to switch light and dark color schemes.
Category: Buttons
The `ColorSchemeToggle` is a button that lets users switch between light and dark color themes.
It is built on the `ActionIcon` component. See the [ActionIcon documentation](/components/actionicon) for examples of
styling with props such as `size`, `color`, and `gradient`.
### Usage
Copy this app to run it locally. For a live demo, click the `ColorSchemeToggle` in the header of these docs.
Note that the toggle switches themes automatically and does not require a Dash callback.
```python
import dash_mantine_components as dmc
from dash import Dash
from dash_iconify import DashIconify
app = Dash()
component = dmc.ColorSchemeToggle(
lightIcon=DashIconify(icon="radix-icons:sun", width=20),
darkIcon=DashIconify(icon="radix-icons:moon", width=20),
color="yellow",
size="lg",
m="xl",
)
app.layout = dmc.MantineProvider(component)
if __name__ == "__main__":
app.run(debug=True)
```
### lightIcon and darkIcon
The `lightIcon` and `darkIcon` props accept any Dash component. For example, you can pass `DashIconify` to display icons
for each theme. You can also wrap the icon with a tooltip component to show text on hover:
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
dmc.ColorSchemeToggle(
lightIcon=dmc.Tooltip(DashIconify(icon="radix-icons:sun"), label="Light mode"),
darkIcon=dmc.Tooltip(DashIconify(icon="radix-icons:moon"), label="Dark mode"),
)
```
### computedColorScheme
The `computedColorScheme` prop is read-only and can be used as an `Input` in a Dash callback. This is useful when
you need to update Plotly figures or components such as `dash-ag-grid` based on the current Mantine theme. See examples
in the [Figure Templates](/components/figure-templates) and [Dash Ag Grid](/dash-ag-grid) sections.
`computedColorScheme` always returns `"light"` or `"dark"`, even if the toggle is set to `"auto"`.
```python
from dash import Input, Output
import dash_mantine_components as dmc
@app.callback(
Output("color-scheme-output", "children"),
Input("color-scheme-toggle", "computedColorScheme"),
)
def update(scheme):
return f"Current color scheme: {scheme}"
```
### Custom theme switch components
If you want to create your own custom theme switch or need more control over how themes toggle, check out
the [Theme Switch Components](/theme-switch) page for and example using `Switch`.
### Setting theme when the app is loading
The selected color scheme from `ColorSchemeToggle` is saved in `localStorage` under `mantine-color-scheme-value`, allowing
the correct styles to be applied before the app renders and preventing flashes of the wrong color on page load or refresh.
Use `pre_render_color_scheme()` at the top of your app to initialize the Mantine color scheme immediately, matching the
user’s preference or system theme:
```python
import dash_mantine_components as dmc
dmc.pre_render_color_scheme()
```
Note: `pre_render_color_scheme()` required dash>=3.0
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### ColorSchemeToggle Selectors
| Selector | Static selector | Description |
|----------|--------------------------------|------------------------------------------------------------|
| root | .mantine-ActionIcon-root | Root element |
| icon | .mantine-ActionIcon-icon | Inner icon wrapper |
#### ColorSchemeToggle CSS Variables
| Selector | Variable | Description |
|----------|-----------------|----------------------------------------------|
| root | --ai-bg | Controls background |
| | --ai-hover | Controls background when hovered |
| | --ai-bd | Controls border |
| | --ai-color | Controls icon color |
| | --ai-hover-color| Controls icon color when hovered |
| | --ai-radius | Controls border-radius |
| | --ai-size | Controls width, height, min-width, and min-height styles |
#### ActionIcon Data Attributes
| Selector | Attribute | Condition |
|---------------|-----------------|----------------------------|
| root | data-disabled | `disabled` prop is set |
### Keyword Arguments
#### ColorSchemeToggle
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
If set, adjusts text color based on background color for `filled`
variant.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color. default
`theme.primaryColor`.
- computedColorScheme (a value equal to: 'dark', 'light'; optional):
Read-only Color Scheme.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- darkIcon (a list of or a singular dash component, string or number; optional):
Icon shown when scheme is dark.
- data-* (string; optional):
Wild card data attributes.
- disabled (boolean; optional):
Sets `disabled` attribute, prevents interactions.
- gradient (dict; optional):
Gradient values used with `variant="gradient"`. default
`theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- lightIcon (a list of or a singular dash component, string or number; optional):
Icon shown when scheme is light.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius.
Numbers are converted to rem. default `theme.defaultRadius`.
- size (number; optional):
Controls width and height of the button. Numbers are converted to
rem. default `'md'`.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## CopyButton
Copies given text to clipboard. A DMC alternative to dcc.Clipboard.
Category: Buttons
### Introduction
`CopyButton` is a ready-to-use clipboard button built with the Mantine `Button` component.
It supports props for dynamic text, icons and colors while copying plus all standard `Button` props.
### Colors
Use `color` and `copiedColor` props to change the button’s color before and after copying.
Note - if `copiedColor` is not provided, the color will remain unchanged during copying.
```python
import dash_mantine_components as dmc
component = dmc.CopyButton(
value="https://www.dash-mantine-components.com/",
children="Copy URL",
color="blue",
copiedColor="teal"
)
```
### Copy State Display
Use `children` and `copiedChildren` to control the content of the underlying button before and after copying.
The `CopyButton` renders a Mantine `Button` internally, and `children` / `copiedChildren` are passed directly as the
button’s children. For this reason, they must not contain interactive elements (for example: buttons, links, inputs,
or other clickable controls), as nesting interactive components inside a button results in invalid HTML and accessibility issues.
Use text, icons, or non-interactive Dash components (such as `Text`, `Group`, `Stack`, or `Icon` components) to customize the button content.
If you would like to use something other than a button (like an `ActionIcon`), use the `CustomCopyButton` instead.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group([
dmc.CopyButton(
value="https://www.dash-mantine-components.com/",
children="Copy URL",
copiedChildren="Copied!",
color="blue",
copiedColor="teal"
),
dmc.CopyButton(
value="This text is copied",
children=DashIconify(icon="tabler:clipboard"),
copiedChildren=DashIconify(icon="tabler:check"),
color="blue",
copiedColor="teal",
variant="outline"
),
dmc.CopyButton(
value="This text is copied",
children=DashIconify(icon="fa-regular:copy"),
copiedChildren=DashIconify(icon="fa-regular:check-circle"),
color="gray",
copiedColor="dark",
variant="transparent"
)
])
```
### Copy from another component
Use `target_id` to copy text (or value prop) from another component instead of using a static value. No callback required!
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group([
dmc.Textarea(
"Type here. This text will be copied.",
id="text-to-copy",
autosize=True,
minRows=3,
w=300
),
dmc.CopyButton(
target_id="text-to-copy",
children=DashIconify(icon="fa-regular:copy"),
copiedChildren=DashIconify(icon="fa-regular:check-circle"),
color="var(--mantine-color-dimmed)",
copiedColor="gray",
variant="outline",
size="xs"
)
], gap=0, align="flex-start" )
```
### Copy in a callback
Set `triggerCopy=True` to trigger the copy from a callback. This property automatically resets to `False` after copying.
Note that the `value` and `triggerCopy` properties can be updated in the same callback.
In this example, the `CopyButton` is hidden, and `triggerCopy` is set to `True` when the `value` of the `Select` component changes.
```python
import dash_mantine_components as dmc
from dash import Input, Output, callback
component = dmc.Box([
dmc.Select(
id="copy-select",
data=["Job A", "Job B", "Job C"],
label="Select Job",
description="Results are copied to the clipboard"
),
dmc.Text(id="copy-select-output"),
dmc.CopyButton(
id="copy-trigger",
style={"visibility": "hidden"},
value=""
)
])
@callback(
Output("copy-select-output", "children"),
Output("copy-trigger", "value"),
Output("copy-trigger", "triggerCopy"),
Input("copy-select", "value")
)
def update_clipboard(v):
results = f"Results from {v}"
return results, results, True
```
### Timeout
The `timeout` prop controls how long the "copied" state is displayed (in milliseconds). The default is 1000ms.
```python
import dash_mantine_components as dmc
component = dmc.CopyButton(
value="copied text",
children="Copy",
copiedChildren="Copied",
color="dark.3",
copiedColor="gray.2",
autoContrast=True,
timeout="2000"
)
```
### Custom Copy Button
Create a custom copy button using a JavaScript function. This example uses an `ActionIcon` and `Tooltip` that respond to the copied state.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.CustomCopyButton(
value="Custom Copy demo",
children={"function": "copyActionIcon"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
var DashIconify = window.dash_iconify.DashIconify;
dmcfuncs.copyActionIcon = function({ copied, copy }) {
return React.createElement(
dmc.Tooltip,
{
label: copied ? 'Copied' : 'Copy',
withArrow: true,
position: 'right'
},
React.createElement(
dmc.ActionIcon,
{
color: copied ? 'teal' : 'gray',
variant: 'subtle',
onClick: copy
},
copied
? React.createElement(DashIconify, { icon: 'tabler:check', style: { width: 16, height: 16 } })
: React.createElement(DashIconify, { icon: 'tabler:copy', style: { width: 16, height: 16 } })
)
);
};
```
### Security
Due to security reasons `CopyButton` components will not work in iframes and may not work with local files opened with `file://` protocol.
It will work with local websites using `http://` protocol, but when deployed it must use `https//` (secure).
Learn more about [navigator.clipboard](https://web.dev/articles/async-clipboard).
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### CopyButton Selectors
| Selector | Static selector | Description |
|----------|---------------------------|----------------------------------------------------|
| root | .mantine-Button-root | Root element |
| loader | .mantine-Button-loader | Loader component, displayed only when `loading` prop is set |
| inner | .mantine-Button-inner | Contains all other elements, child of the root element |
| section | .mantine-Button-section | Left and right sections of the button |
| label | .mantine-Button-label | Button children |
#### CopyButton CSS Variables
| Selector | Variable | Description |
|----------|---------------------------|---------------------------------------------------|
| root | --button-bg | Controls background |
| | --button-bd | Controls border |
| | --button-hover | Controls background when hovered |
| | --button-color | Controls text color |
| | --button-hover-color | Controls text color when hovered |
| | --button-radius | Controls border-radius |
| | --button-height | Controls height of the button |
| | --button-padding-x | Controls horizontal padding of the button |
| | --button-fz | Controls font-size of the button |
| | --button-justify | Controls `justify-content` of the inner element |
#### CopyButton Data Attributes
| Selector | Attribute | Condition | Value |
|----------------|------------------------|--------------------------|---------------------------------|
| root | data-disabled | `disabled` prop is set | – |
| root | data-block | `fullWidth` prop is set | – |
### Keyword Arguments
#### CopyButton
- children (a list of or a singular dash component, string or number; optional):
Button content displayed before copying.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether button text color with filled variant should
depend on `background-color`. If luminosity of the `color` prop is
less than `theme.luminosityThreshold`, then `theme.white` will be
used for text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- buttonProps (dict; optional):
Props passed down to the `Button` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color, used when the value
has not been copied yet.
- copiedChildren (a list of or a singular dash component, string or number; optional):
Button content displayed after the value has been copied to
clipboard.
- copiedColor (optional):
Key of `theme.colors` or any valid CSS color, used after the value
has been copied to clipboard.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- disabled (boolean; optional):
Indicates disabled state.
- fullWidth (boolean; optional):
Determines whether button should take 100% width of its parent
container, `False` by default.
- gradient (dict; optional):
Gradient configuration used when `variant="gradient"`, default
value is `theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- n_clicks (number; default 0):
An integer that represents the number of times that this element
has been clicked on.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, `theme.defaultRadius` by default.
- size (optional):
Controls button `height`, `font-size` and horizontal `padding`,
`'sm'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- target_id (string; optional):
The id of target component containing text to copy to the
clipboard. The inner text of the `children` prop will be copied to
the clipboard. If none, then the text from the `value` prop will
be copied.
- timeout (number; default 1000):
Copied status timeout in ms, `1000` by default.
- triggerCopy (boolean; default False):
Set to True to trigger copy in a callback - will auto-reset to
False after copy.
- value (string; default ''):
Value to be copied to clipboard.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### CustomCopyButton
- children (boolean | number | string | dict | list; optional):
Function that receives {copied, copy} and returns a component See
https://www.dash-mantine-components.com/functions-as-props.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- timeout (number; default 1000):
Copied status timeout in ms, `1000` by default.
- value (string; required):
Value to be copied to clipboard.
## An Introduction to Charts
Getting started with chart components.
Category: Charts
### CSS Extensions
As of DMC 1.2.0, Chart component styles are bundled automatically, so you no longer need to include a separate CSS file.
If you're using an older version of DMC, refer to the [migration guide](/migration) for instructions on including optional stylesheets.
### Based on recharts
Most of the chart components are based on [recharts](https://recharts.org/) library. If you need advanced features that are not covered in dmc charts documentation, please refer to the [recharts documentation](https://recharts.org/en-US/api) for more information.
## AreaChart
Area chart component with stacked, percent and split variants.
Category: Charts
### Introduction
Use `AreaChart` component without `type` prop to render a regular area chart. In a regular area chart, each data series
is plotted on its own and does not interact with other series.
```python
import dash_mantine_components as dmc
from .data import data
dmc.AreaChart(
h=300,
dataKey="date",
data=data,
series = [
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"}
],
curveType="linear",
tickLine="xy",
withGradient=False,
withXAxis=False,
withDots=False,
)
```
### Data
Here is the data imported for the examples on this page:
```python
data = [
{"date": "Mar 22", "Apples": 2890, "Oranges": 2338, "Tomatoes": 2452},
{"date": "Mar 23", "Apples": 2756, "Oranges": 2103, "Tomatoes": 2402},
{"date": "Mar 24", "Apples": 3322, "Oranges": 986, "Tomatoes": 1821},
{"date": "Mar 25", "Apples": 3470, "Oranges": 2108, "Tomatoes": 2809},
{"date": "Mar 26", "Apples": 3129, "Oranges": 1726, "Tomatoes": 2290}
]
```
### Stacked area chart
Set type="stacked" to render a stacked area chart. In this type of area chart stacking is applied along the vertical
axis, allowing you to see the overall trend as well as the contribution of each individual series to the total.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Percent area chart
Set type="percent" to render a percent area chart. In this type of area chart the y-axis scale is always normalized to
100%, making it easier to compare the contribution of each series in terms of percentages.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="percent",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Split area chart
Set type="split" to render a split area chart. In this type of area chart fill color is split into two colors, one for
positive values and one for negative values. Split area chart supports only one data series.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 110},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": -80},
{"date": "Mar 25", "Apples": 40},
{"date": "Mar 26", "Apples": -40},
{"date": "Mar 27", "Apples": 80},
]
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="split",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Streamgraph
Set `type="stream"` to render a streamgraph (also known as ThemeRiver). A streamgraph is a stacked area chart whose
baseline flows around a central axis instead of being fixed to zero, producing the characteristic organic "river" shape.
It is useful for showing how the composition of a total shifts over time when the overall flow and proportions matter more
than exact values.
Since the baseline floats, the y-axis values are not meaningful to read off – the y-axis is hidden by default for `type="stream"`.
You can set `withYAxis` back to `True` if you need it.
```python
import dash_mantine_components as dmc
data = [
{"month": "Jan", "Apples": 220, "Oranges": 140, "Tomatoes": 90, "Grapes": 60},
{"month": "Feb", "Apples": 260, "Oranges": 180, "Tomatoes": 120, "Grapes": 90},
{"month": "Mar", "Apples": 300, "Oranges": 240, "Tomatoes": 180, "Grapes": 140},
{"month": "Apr", "Apples": 340, "Oranges": 320, "Tomatoes": 260, "Grapes": 200},
{"month": "May", "Apples": 380, "Oranges": 420, "Tomatoes": 360, "Grapes": 280},
{"month": "Jun", "Apples": 420, "Oranges": 520, "Tomatoes": 460, "Grapes": 360},
{"month": "Jul", "Apples": 400, "Oranges": 560, "Tomatoes": 520, "Grapes": 420},
{"month": "Aug", "Apples": 360, "Oranges": 520, "Tomatoes": 560, "Grapes": 460},
{"month": "Sep", "Apples": 300, "Oranges": 440, "Tomatoes": 520, "Grapes": 420},
{"month": "Oct", "Apples": 260, "Oranges": 340, "Tomatoes": 440, "Grapes": 360},
{"month": "Nov", "Apples": 220, "Oranges": 260, "Tomatoes": 340, "Grapes": 280},
{"month": "Dec", "Apples": 200, "Oranges": 200, "Tomatoes": 260, "Grapes": 200},
]
component = dmc.AreaChart(
h=300,
data=data,
dataKey="month",
type="stream",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
{"name": "Grapes", "color": "grape.6"},
],
)
```
### Split colors
Set `splitColors` prop to an array of two colors to customize the fill color of split area chart. The first color is
used for positive values and the second color for negative values. `splitColors` prop is ignored in other types of area charts.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 110},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": -80},
{"date": "Mar 25", "Apples": 40},
{"date": "Mar 26", "Apples": -40},
{"date": "Mar 27", "Apples": 80},
]
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="split",
strokeWidth=1,
activeDotProps={"r": 2, "strokeWidth": 1},
series=[{"name": "Apples", "color": "bright"}],
splitColors=["violet", "orange"],
)
```
### Legend
To display chart legend, set `withLegend` prop. When one of the items in the legend is hovered, the corresponding data
series is highlighted in the chart.Tooltip
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
withLegend=True,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Legend position
You can pass props down to recharts Legend component with `legendProps` prop. For example, setting the following will
render the legend at the bottom of the chart and set its height to 50px:
```python
legendProps={'verticalAlign': 'bottom', 'height': 50}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
withLegend=True,
legendProps={"verticalAlign": "bottom", "height": 50},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Series labels
By default, series `name` is used as a label. To change it, set `label` property in `series` object:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
withLegend=True,
legendProps={"verticalAlign": "bottom"},
series=[
{"name": "Apples", "label": "Apples sales", "color": "indigo.6"},
{"name": "Oranges", "label": "Oranges sales", "color": "blue.6"},
{"name": "Tomatoes", "label": "Tomatoes sales", "color": "teal.6"},
],
)
```
### Connect nulls
Use `connectNulls` prop to specify whether to connect a data point across null points. By default, `connectNulls` is true.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 110},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": -80},
{"date": "Mar 25", "Apples": 40},
{"date": "Mar 26", "Apples": None},
{"date": "Mar 27", "Apples": 80}
]
dmc.AreaChart(
h=300,
dataKey="date",
data=data,
connectNulls=True,
series=[{"name": "Apples", "color": "indigo.6"}],
curveType="linear",
)
```
### X and Y axis props
Use `xAxisProps` and `yAxisProps` to pass props down to recharts `XAxis` and `YAxis` components. For example, these props can
be used to change orientation of axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
tickLine="xy",
yAxisProps={"tickMargin": 15, "orientation": "right"},
xAxisProps={"tickMargin": 15, "orientation": "top"},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Axis labels
Use `xAxisLabel` and `yAxisLabel` props to display axis labels:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
xAxisLabel="Date",
yAxisLabel="Amount",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### X axis offset
Use xAxisProps to set padding between the charts ends and the x-axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
xAxisProps={"padding": {"left": 30, "right": 30}},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Y axis scale
Use `yAxisProps` to change domain of the Y axis. For example, if you know that your data will always be in the range
of 0 to 100, you can set domain to [0, 100]:
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 50},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": 40},
{"date": "Mar 25", "Apples": 30},
{"date": "Mar 26", "Apples": 0},
{"date": "Mar 27", "Apples": 20},
{"date": "Mar 28", "Apples": 20},
{"date": "Mar 29", "Apples": 10},
]
component = dmc.AreaChart(
h=300,
dataKey="date",
yAxisProps={"domain": [0, 100]},
data=data,
connectNulls=True,
series=[{"name": "Apples", "color": "indigo.6"}],
)
```
### Right Y axis
To display additional Y axis on the right side of the chart, set `withRightYAxis` prop. You can pass props down to
recharts `YAxis` component with `rightYAxisProps` prop and assign a label to the right Y axis with `rightYAxisLabel` prop.
Note that you need to bind data series to the right Y axis by setting `yAxisId` in the series object.
```python
import dash_mantine_components as dmc
data = biaxial_data = [
{"name": "Page A", "uv": 4000, "pv": 2400},
{"name": "Page B", "uv": 3000, "pv": 1398},
{"name": "Page C", "uv": 2000, "pv": 9800},
{"name": "Page D", "uv": 2780, "pv": 3908},
{"name": "Page E", "uv": 1890, "pv": 4800},
{"name": "Page F", "uv": 2390, "pv": 3800},
{"name": "Page G", "uv": 3490, "pv": 4300},
]
component = dmc.AreaChart(
h=300,
data=data,
dataKey="name",
withRightYAxis=True,
yAxisLabel="uv",
rightYAxisLabel="pv",
series=[
{"name": "uv", "color": "pink.6"},
{"name": "pv", "color": "cyan.6", "yAxisId": "right"},
],
)
```
### Rotate x-axis labels
To rotate x-axis labels, set `xAxisProps.angle` to a number of degrees to rotate:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
tickLine="xy",
xAxisProps={"angle": -20},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Value formatter
To format values in the tooltip and axis ticks, use `valueFormatter` prop. It accepts a function that takes number `value`
as an argument and returns formatted value:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
tickLine="xy",
valueFormatter={"function": "formatNumberIntl"},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatNumberIntl = (value) => {
return new Intl.NumberFormat('en-US').format(value);
};
```
### Area color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc.
Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 110},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": -80},
{"date": "Mar 25", "Apples": 40},
{"date": "Mar 26", "Apples": 60},
{"date": "Mar 27", "Apples": 80}
]
dmc.AreaChart(
h=300,
dataKey="date",
data=data,
withGradient=True,
series=[{"name": "Apples", "color": "orange.7"}],
)
```
### Change area color depending on color scheme
You can use CSS variables in color property. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
Example of area that is dark orange in light mode and lime in dark mode:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
withGradient=True,
series=[{"name": "Apples", "color": "var(--chart-color)"}],
)
```
```css
:root {
--chart-color: var(--mantine-color-orange-8)
}
:root[data-mantine-color-scheme="dark"] {
--chart-color: var(--mantine-color-lime-4);
}
```
### Stroke dash array
Set `strokeDasharray` prop to control the stroke dash array of the grid and cursor lines. The value represent the
lengths of alternating dashes and gaps. For example, strokeDasharray="10 5" will render a dashed line with 10px dashes
and 5px gaps.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
strokeDasharray="15 15",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Grid and text colors
Use `--chart-grid-color` and `--chart-text-color` to change colors of grid lines and text within the chart.
With CSS , you can change colors depending on color scheme. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
className="chart-grid-text-colors",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
```css
.chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-5);
--chart-text-color: var(--mantine-color-blue-8);
}
[data-mantine-color-scheme='dark'] .chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-3);
--chart-text-color: var(--mantine-color-blue-2);
}
```
If your application has only one color scheme, you can use `gridColor` and `textColor` props instead of CSS variables:
```python
dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
gridColor="gray.5",
textColor = "gray.9",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Tooltip animation
By default, tooltip animation is disabled. To enable it, set `tooltipAnimationDuration` prop to a number of
milliseconds to animate the tooltip position change.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
tooltipAnimationDuration=200,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Area animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `areaProps` to pass properties to the Recharts `Area` component.
```python
from random import randint
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-areachart-animation"),
dmc.AreaChart(
id="areachart-animation",
h=300,
dataKey="date",
data=[{}],
tooltipAnimationDuration=500,
areaProps={
"isAnimationActive": True,
"animationDuration": 500,
"animationEasing": "ease-in-out",
"animationBegin": 500,
},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
),
]
)
@callback(
Output("areachart-animation", "data"), Input("btn-areachart-animation", "n_clicks")
)
def update(n):
return [
{
"date": "Mar 22",
"Apples": 2890,
"Oranges": 2338,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 23",
"Apples": 2756,
"Oranges": 2103,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 24",
"Apples": 3322,
"Oranges": 986,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 25",
"Apples": 3470,
"Oranges": 2108,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 26",
"Apples": 3129,
"Oranges": 1726,
"Tomatoes": randint(1000, 4000),
},
]
```
### Units
Set `unit` prop to render a unit label next to the y-axis ticks and tooltip values:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
unit="$",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Remove tooltip
To remove tooltip, set `withTooltip=False`. It also removes the cursor line and disables interactions with the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
withTooltip=False,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Customize dots
Use `dotProps` to pass props down to recharts dot in regular state and `activeDotProps` to pass props down to recharts dot in active state (when cursor is over the current series).
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
dotProps={"r": 6, "strokeWidth": 2, "stroke": "#fff"},
activeDotProps={"r": 8, "strokeWidth": 1, "fill": "#fff"},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Stroke width
Use `strokeWidth` prop to control the stroke width of all areas:
```python
import dash_mantine_components as dmc
from .data import data
dmc.AreaChart(
h=300,
dataKey="date",
data=data,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"}
],
strokeWidth=2,
)
```
### Fill opacity
Use `fillOpacity` prop to control the fill opacity of all areas:
```python
import dash_mantine_components as dmc
from .data import data
dmc.AreaChart(
h=300,
dataKey="date",
data=data,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"}
],
fillOpacity="0.2",
withGradient=False,
)
```
### Sync multiple AreaCharts
You can pass props down to recharts AreaChart component with `areaChartProps` prop. For example, setting the following
will sync tooltip of multiple `AreaChart` components with the same `syncId` prop.
```python
areaChartProps={"syncId": "any-id"}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.Text("Apples sales:"),
dmc.AreaChart(
h=180,
dataKey="date",
data=data,
series=[{"name": "Apples", "color": "indigo.6"}],
areaChartProps={"syncId": "groceries"},
),
dmc.Text("Tomatoes sales"),
dmc.AreaChart(
h=180,
dataKey="date",
data=data,
series=[{"name": "Tomatoes", "color": "teal.6"}],
areaChartProps={"syncId": "groceries"},
),
]
)
```
### Vertical orientation
Set orientation="vertical" to render a vertical area chart:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
orientation="vertical",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Dashed area line
Set `strokeDasharray` property in series to change line style to dashed:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
strokeWidth=1,
dotProps={"r": 2},
activeDotProps={"r": 3, "strokeWidth": 1},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6", "strokeDasharray": "5 5"},
],
)
```
### Reference lines
Use `referenceLines` prop to render reference lines. Reference lines are always rendered behind the chart.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 50},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": 40},
{"date": "Mar 25", "Apples": 30},
{"date": "Mar 26", "Apples": 0},
{"date": "Mar 27", "Apples": 20},
{"date": "Mar 28", "Apples": 20},
{"date": "Mar 29", "Apples": 10},
]
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
yAxisProps={"domain": [0, 100]},
referenceLines=[
{"y": 40, "label": "Average sales", "color": "red.6"},
{"x": "Mar 25", "label": "Report out"},
],
series=[{"name": "Apples", "color": "indigo.6"}],
)
```
### Reference areas
Use the `referenceAreas` prop to highlight a rectangular region of the chart. Each area is bounded by x1/x2 (horizontal)
and y1/y2 (vertical) data values – omit one pair to span the full opposite axis, for example provide only x1/x2 to
highlight a time range across the entire height of the chart. Set `color` to any theme color or CSS color and label
to display text inside the area. Reference areas are rendered behind the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
data=data,
dataKey="date",
type="stacked",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
referenceAreas=[
{"x1": "Mar 23", "x2": "Mar 25", "color": "red.6", "label": "Weekend"},
],
)
```
### Reference dots
Use the `referenceDots` prop to mark individual points on the chart – a peak, an event, a record value or an anomaly.
Each dot is positioned by x and y data coordinates and supports `r` (radius), `color` (any theme color or CSS color) and
`label`. Reference dots are rendered on top of the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
data=data,
dataKey="date",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
referenceDots=[
{"x": "Mar 25", "y": 3470, "color": "red.6", "label": "Peak"},
],
)
```
### Brush (Range Slider)
Set the `withBrush` prop to display a brush (range slider) under the chart. Drag the brush handles to
zoom into a subset of the data. The chart updates to show only the selected range. The brush border and background are
themed to match the chart grid and adapt to the color scheme. `withBrush` is `False` by default and is supported by
`AreaChart`, `BarChart`, `LineChart` and `CompositeChart` components with `horizontal` orientation.
Use the `brushDragEnd` prop to get the `startIndex` and `endIndex` of the selected range when dragging ends.
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
data = [
{"date": "Mar 1", "Apples": 2200, "Oranges": 1400},
{"date": "Mar 2", "Apples": 2500, "Oranges": 1500},
{"date": "Mar 3", "Apples": 2800, "Oranges": 1700},
{"date": "Mar 4", "Apples": 3100, "Oranges": 1600},
{"date": "Mar 5", "Apples": 3000, "Oranges": 1800},
{"date": "Mar 6", "Apples": 2700, "Oranges": 2000},
{"date": "Mar 7", "Apples": 2400, "Oranges": 2100},
{"date": "Mar 8", "Apples": 2100, "Oranges": 1900},
{"date": "Mar 9", "Apples": 1900, "Oranges": 1700},
{"date": "Mar 10", "Apples": 2200, "Oranges": 1500},
{"date": "Mar 11", "Apples": 2600, "Oranges": 1600},
{"date": "Mar 12", "Apples": 3000, "Oranges": 1800},
{"date": "Mar 13", "Apples": 3300, "Oranges": 2000},
{"date": "Mar 14", "Apples": 3100, "Oranges": 2200},
{"date": "Mar 15", "Apples": 2800, "Oranges": 2100},
{"date": "Mar 16", "Apples": 2500, "Oranges": 1900},
]
component = dmc.Stack([
dmc.AreaChart(
h=300,
data=data,
dataKey="date",
withBrush=True,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
],
id="areachart-brush"
),
dmc.Text(id="areachart-brush-dragend")
])
@callback(
Output("areachart-brush-dragend", "children"),
Input("areachart-brush", "brushDragEnd"),
)
def brushDragEnd(brushDragEnd):
return f"Brush range selected: {brushDragEnd}"
```
### Brush props
Use the `brushProps` prop to pass props down to the underlying [recharts Brush](https://recharts.github.io/en-US/api/Brush/) component. For example, you can set the
initially selected range with `startIndex`/`endIndex`, change the brush height and more:
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 1", "Apples": 2200, "Oranges": 1400},
{"date": "Mar 2", "Apples": 2500, "Oranges": 1500},
{"date": "Mar 3", "Apples": 2800, "Oranges": 1700},
{"date": "Mar 4", "Apples": 3100, "Oranges": 1600},
{"date": "Mar 5", "Apples": 3000, "Oranges": 1800},
{"date": "Mar 6", "Apples": 2700, "Oranges": 2000},
{"date": "Mar 7", "Apples": 2400, "Oranges": 2100},
{"date": "Mar 8", "Apples": 2100, "Oranges": 1900},
{"date": "Mar 9", "Apples": 1900, "Oranges": 1700},
{"date": "Mar 10", "Apples": 2200, "Oranges": 1500},
{"date": "Mar 11", "Apples": 2600, "Oranges": 1600},
{"date": "Mar 12", "Apples": 3000, "Oranges": 1800},
{"date": "Mar 13", "Apples": 3300, "Oranges": 2000},
{"date": "Mar 14", "Apples": 3100, "Oranges": 2200},
{"date": "Mar 15", "Apples": 2800, "Oranges": 2100},
{"date": "Mar 16", "Apples": 2500, "Oranges": 1900},
]
component = dmc.AreaChart(
h=300,
data=data,
dataKey="date",
withBrush=True,
brushProps={"startIndex": 3, "endIndex": 10, "height": 30},
series=[{"name": "Apples", "color": "indigo.6"}],
)
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event.
To get the name of the clicked series, use the `clickSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.AreaChart(
id="figure-areachart",
h=300,
dataKey="date",
data=data,
type="stacked",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
),
dmc.Text(id="clickdata-areachart1"),
dmc.Text(id="clickdata-areachart2"),
]
)
@callback(
Output("clickdata-areachart1", "children"),
Output("clickdata-areachart2", "children"),
Input("figure-areachart", "clickData"),
Input("figure-areachart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event.
To get the name of the hovered series, use the `hoverSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.AreaChart(
id="figure-areachart-hover",
h=300,
dataKey="date",
data=data,
type="stacked",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
),
dmc.Text(id="hoverdata-areachart1"),
dmc.Text(id="hoverdata-areachart2"),
]
)
@callback(
Output("hoverdata-areachart1", "children"),
Output("hoverdata-areachart2", "children"),
Input("figure-areachart-hover", "hoverData"),
Input("figure-areachart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### highlightHover
Set `highlightHover=True` to highlight the series when hovered, mirroring the behavior of hovering over chart legend items.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.AreaChart(
h=300,
dataKey="date",
data=data,
type="stacked",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
highlightHover=True
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### AreaChart selectors
| Name | Static selector | Description |
|:----------------|:----------------------------------|:----------------------------------------------|
| root | .mantine-AreaChart-root | Root element |
| area | .mantine-AreaChart-area | Area of the chart |
| axis | .mantine-AreaChart-axis | X and Y axis of the chart |
| container | .mantine-AreaChart-container | Recharts ResponsiveContainer component |
| grid | .mantine-AreaChart-grid | Recharts CartesianGrid component |
| legend | .mantine-AreaChart-legend | Legend root element |
| legendItem | .mantine-AreaChart-legendItem | Legend item representing data series |
| legendItemColor | .mantine-AreaChart-legendItemColor | Legend item color |
| legendItemName | .mantine-AreaChart-legendItemName | Legend item name |
| tooltip | .mantine-AreaChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-AreaChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-AreaChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-AreaChart-tooltipItemBody | Tooltip item wrapper around item color and name|
| tooltipItemColor| .mantine-AreaChart-tooltipItemColor| Tooltip item color |
| tooltipItemName | .mantine-AreaChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-AreaChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-AreaChart-tooltipLabel | Label of the tooltip |
| referenceLine | .mantine-AreaChart-referenceLine | Reference line |
| axisLabel | .mantine-AreaChart-axisLabel | X and Y axis labels |
#### AreaChart CSS variables
| Selector | Variable | Description |
|:-------------------|:---------------------|:-------------------------------------------------|
| root | --chart-grid-color | Controls color of the grid and cursor lines |
| | --chart-text-color | Controls color of the axis labels |
### Keyword Arguments
#### AreaChart
- children (a list of or a singular dash component, string or number; optional):
Additional components that are rendered inside recharts
`AreaChart` component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- activeDotProps (dict; optional):
Props passed down to all active dots. Ignored if
`withDots={False}` is set.
- areaChartProps (dict; optional):
Props passed down to recharts `AreaChart` component.
- areaProps (dict; optional):
Props passed down to recharts `Area` component.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- brushDragEnd (dict; optional):
The startIndex and endIndex of the selected brush range when
dragging ends. Read only.
`brushDragEnd` is a dict with keys:
- brushProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Brush` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- connectNulls (boolean; optional):
Determines whether points with `None` values should be connected,
`True` by default.
- curveType (a value equal to: 'bump', 'linear', 'natural', 'monotone', 'step', 'stepBefore', 'stepAfter'; optional):
Type of the curve, `'monotone'` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts; required):
Data used to display chart.
`data` is a list of dicts with keys:
- data-* (string; optional):
Wild card data attributes.
- dataKey (string; required):
Key of the `data` object for x-axis values.
- dotProps (dict; optional):
Props passed down to all dots. Ignored if `withDots={False}` is
set.
- fillOpacity (number; optional):
Controls fill opacity of all areas, `0.2` by default.
- gridAxis (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which lines should be displayed in the grid, `'x'` by
default.
- gridColor (optional):
Color of the grid and cursor lines, by default depends on color
scheme.
- gridProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `CartesianGrid` component.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- highlightHover (boolean; optional):
Determines whether a hovered series is highlighted. False by
default. Mirrors the behaviour when hovering about chart legend
items.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- legendProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Chart orientation, `'horizontal'` by default.
- referenceAreas (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference areas that should be displayed on the chart.
- referenceDots (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference dots that should be displayed on the chart.
- referenceLines (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference lines that should be displayed on the chart.
- rightYAxisLabel (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- rightYAxisProps (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- series (list of dicts; required):
An array of objects with `name` and `color` keys. Determines which
data should be consumed from the `data` array.
`series` is a list of dicts with keys:
- splitColors (list of 2 elements: [, ]; optional):
A tuple of colors used when `type="split"` is set, ignored in
all other cases. A tuple may include theme colors reference or any
valid CSS colors `['green.7', 'red.7']` by default.
- splitOffset (number; optional):
Offset for the split gradient. By default, value is inferred from
`data` and `series` if possible. Must be generated from the data
array with `getSplitOffset` function.
- strokeDasharray (string | number; optional):
Dash array for the grid lines and cursor, `'5 5'` by default.
- strokeWidth (number; optional):
Stroke width for the chart areas, `2` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Color of the text displayed inside the chart, `'dimmed'` by
default.
- tickLine (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which axis should have tick line, `'y'` by default.
- tooltipAnimationDuration (number; optional):
Tooltip position animation duration in ms, `0` by default.
- tooltipProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Tooltip` component.
- type (a value equal to: 'default', 'stacked', 'percent', 'split', 'stream'; optional):
Controls how chart areas are positioned relative to each other,
`'default'` by default.
- unit (string; optional):
Unit displayed next to each tick in y-axis.
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values on Y axis and inside the tooltip. See
https://www.dash-mantine-components.com/functions-as-props.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBrush (boolean; optional):
Determines whether a brush (range selector) should be displayed
under the chart, `False` by default.
- withDots (boolean; optional):
Determines whether dots should be displayed, `True` by default.
- withGradient (boolean; optional):
Determines whether the chart area should be represented with a
gradient instead of the solid color, `False` by default.
- withLegend (boolean; optional):
Determines whether chart legend should be displayed, `False` by
default.
- withPointLabels (boolean; optional):
Determines whether each point should have associated label, False
by default.
- withRightYAxis (boolean; optional):
Determines whether additional y-axis should be displayed on the
right side of the chart, False by default.
- withTooltip (boolean; optional):
Determines whether chart tooltip should be displayed, `True` by
default.
- withXAxis (boolean; optional):
Determines whether x-axis should be hidden, `True` by default.
- withYAxis (boolean; optional):
Determines whether y-axis should be hidden, `True` by default.
- xAxisLabel (string; optional):
A label to display below the x-axis.
- xAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `XAxis` recharts component.
- yAxisLabel (string; optional):
A label to display next to the y-axis.
- yAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `YAxis` recharts component.
## BarChart
Use BarChart component without type prop to render a regular bar chart. In a regular bar chart, each data series is plotted on its own and does not interact with other series.
Category: Charts
### Introduction
```python
import dash_mantine_components as dmc
from .data import data
dmc.BarChart(
h=300,
dataKey="month",
data=data,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"}
],
tickLine="y",
gridAxis="y",
withXAxis=True,
withYAxis=True
)
```
### Data
Here is the data used in all the examples on this page:
```python
data = [
{"month": "January", "Smartphones": 1200, "Laptops": 900, "Tablets": 200},
{"month": "February", "Smartphones": 1900, "Laptops": 1200, "Tablets": 400},
{"month": "March", "Smartphones": 400, "Laptops": 1000, "Tablets": 200},
{"month": "April", "Smartphones": 1000, "Laptops": 200, "Tablets": 800},
{"month": "May", "Smartphones": 800, "Laptops": 1400, "Tablets": 1200},
{"month": "June", "Smartphones": 750, "Laptops": 600, "Tablets": 1000}
]
```
### Stacked bar chart
Set type="stacked" to render a stacked bar chart. In this type of bar chart stacking is applied along the vertical axis,
allowing you to see the overall trend as well as the contribution of each individual series to the total.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Mixed stacked bar chart
You can control how series are stacked by setting `stackId` property in `series` dictionary:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
series=[
{"name": "Smartphones", "color": "violet.6", "stackId": "a"},
{"name": "Laptops", "color": "blue.6", "stackId": "b"},
{"name": "Tablets", "color": "teal.6", "stackId": "b"},
],
)
```
### Percent bar chart
Set type="percent" to render a percent bar chart. In this type of bar chart the y-axis scale is always normalized
to 100%, making it easier to compare the contribution of each series in terms of percentages.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="percent",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Waterfall
Set `type="waterfall"` to render a waterfall bar chart. This chart type illustrates how an initial value is influenced
by subsequent positive or negative values, with each bar starting where the previous one ended. Use the `color` prop
inside data to color each bar individually. Note that the series color gets overwritten for this specific bar. Use the
`standalone` prop inside data to decouple the bar from the flow.
```python
import dash_mantine_components as dmc
data = [
{"item": "TaxRate", "Effective tax rate in %": 21, "color": "blue"},
{"item": "Foreign inc.", "Effective tax rate in %": -15.5, "color": "teal"},
{"item": "Perm. diff.", "Effective tax rate in %": -3, "color": "teal"},
{"item": "Credits", "Effective tax rate in %": -3, "color": "teal"},
{"item": "Loss carryf.", "Effective tax rate in %": -2, "color": "teal"},
{"item": "Law changes", "Effective tax rate in %": 2, "color": "red"},
{"item": "Reven. adj.", "Effective tax rate in %": 4, "color": "red"},
{
"item": "ETR",
"Effective tax rate in %": 3.5,
"color": "blue",
"standalone": True,
},
]
component = dmc.BarChart(
h=300,
data=data,
dataKey="item",
type="waterfall",
series=[{"name": "Effective tax rate in %", "color": "blue"}],
withLegend=True,
)
```
### SVG Pattern as bar fill
You can use SVG patterns as bar fill. To do so, set `fill` property in series object to a url of the SVG pattern.
Example of using diagonal stripes and crosshatch patterns as bar fill:
```python
import dash_mantine_components as dmc
from dash import html, dcc
from .data import data
# Define patterns for custom colors
pattern_definitions = dcc.Markdown('''
''', dangerously_allow_html=True)
component = html.Div([
pattern_definitions,
dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
series=[
{"name": "Smartphones", "color": "url(#crosshatch)"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "url(#diagonalStripes)"},
],
)
])
```
### Bar color based on value
Use `getBarColor` prop to assign color based on `value`. `getBarColor` function is called with two arguments: `value`
and `series` object. It should return a color string (theme color reference or any valid CSS color value).
Note that color returned by `getBarColor` does not impact colors of the legend and tooltip.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
data = [
{"month": "January", "Smartphones": 1200, "Laptops": 900, "Tablets": 200},
{"month": "February", "Smartphones": 1900, "Laptops": 1200, "Tablets": 400},
{"month": "March", "Smartphones": 400, "Laptops": 1000, "Tablets": 200},
{"month": "April", "Smartphones": 1000, "Laptops": 200, "Tablets": 800},
{"month": "May", "Smartphones": 800, "Laptops": 1400, "Tablets": 1200},
{"month": "June", "Smartphones": 750, "Laptops": 600, "Tablets": 1000},
]
component = dmc.BarChart(
h=300,
data=data,
dataKey="month",
series=[{"name": "Laptops", "color": "gray.6"}],
getBarColor={"function": "barColor"}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
// Highlights bars with value > 700 in teal, others in red
dmcfuncs.barColor = (value) => {
return value > 700 ? 'teal.8' : 'red.8';
};
```
### Legend
To display chart legend, set `withLegend` prop. When one of the items in the legend is hovered, the corresponding data
series is highlighted in the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
withLegend=True,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Legend position
You can pass props down to recharts `Legend` component with `legendProps` prop. For example, setting the following will
render the legend at the bottom of the chart and set its height to 50px.
```python
legendProps={"verticalAlign": "bottom", "height": 50}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
withLegend=True,
legendProps={"verticalAlign": "bottom", "height": 50},
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Series labels
By default, series `name` is used as a label. To change it, set `label` property in `series` object:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
withLegend=True,
legendProps={"verticalAlign": "bottom"},
series=[
{"name": "Smartphones", "label": "Smartphones sales", "color": "violet.6"},
{"name": "Laptops", "label": "Laptops sales", "color": "blue.6"},
{"name": "Tablets", "label": "Tablets sales", "color": "teal.6"},
],
)
```
### X and Y axis props
Use `xAxisProps` and `yAxisProps` to pass props down to recharts `XAxis` and `YAxis` components. For example, these
props can be used to change orientation of axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
tickLine="xy",
yAxisProps={"tickMargin": 15, "orientation": "right"},
xAxisProps={"tickMargin": 15, "orientation": "top"},
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Axis labels
Use `xAxisLabel` and `yAxisLabel` props to display axis labels:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
xAxisLabel="Date",
yAxisLabel="Amount",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### X axis offset
Use `xAxisProps` to set padding between the charts ends and the x-axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
xAxisProps={"padding": {"left": 30, "right": 30}},
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Y axis scale
Use `yAxisProps` to change domain of the Y axis. For example, if you know that your data will always be in the range
of 0 to 150, you can set domain to `[0, 150]`:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
yAxisProps={"domain": [0, 250]},
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Value formatter
To format values in the tooltip and axis ticks, use `valueFormat` prop. It accepts a function that takes number `value`
as an argument and returns formatted value:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
data=data,
dataKey="month",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
valueFormatter={"function": "formatNumberIntl"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatNumberIntl = (value) => {
return new Intl.NumberFormat('en-US').format(value);
};
```
### Area color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc.
Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
from .data import data
dmc.BarChart(
h=300,
dataKey="date",
data=data,
fillOpacity=0.5,
series=[{"name": "Smartphones", "color": "orange.7"}],
)
```
### Change area color depending on color scheme
You can use CSS variables in color property. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
Example of bar area color that is dark orange in light mode and lime in dark mode:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="date",
data=data,
series=[{"name": "Smartphones", "color": "var(--chart-color)"}],
)
```
```css
:root {
--chart-color: var(--mantine-color-orange-8)
}
:root[data-mantine-color-scheme="dark"] {
--chart-color: var(--mantine-color-lime-4);
}
```
### Bar props
You can pass props down to recharts [Bar](https://recharts.org/en-US/api/Bar) component with `barProps` prop. `barProps` accepts an object with rechart props.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
orientation="vertical",
yAxisProps={"width": 80},
barProps={"radius": 50},
series=[{"name": "Smartphones", "color": "violet.6"}],
)
```
### Bar animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `barProps` to pass properties to the Recharts `Bar` component.
```python
from random import randint
import dash
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-barchart-animation"),
dmc.BarChart(
id="barchart-animation",
h=300,
dataKey="month",
data=[{}],
type="stacked",
barProps={"isAnimationActive": True},
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
),
]
)
@callback(
Output("barchart-animation", "data"), Input("btn-barchart-animation", "n_clicks")
)
def update(n):
if n and n > 0:
return [
{
"month": month,
"Smartphones": randint(50, 300),
"Laptops": randint(30, 200),
"Tablets": randint(20, 150),
}
for month in ["January", "February", "March", "April", "May", "June"]
]
return dash.no_update
```
### Stroke dash array
Set `strokeDasharray` prop to control the stroke dash array of the grid and cursor lines. The value represent the lengths of alternating dashes and gaps. For example, strokeDasharray="10 5" will render a dashed line with 10px dashes and 5px gaps.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
strokeDasharray="15 15",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Grid and text colors
Use `--chart-grid-color` and `--chart-text-color` to change colors of grid lines and text within the chart.
With CSS , you can change colors depending on color scheme. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
className="chart-grid-text-colors",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
```css
.chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-5);
--chart-text-color: var(--mantine-color-blue-8);
}
[data-mantine-color-scheme='dark'] .chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-3);
--chart-text-color: var(--mantine-color-blue-2);
}
```
If your application has only one color scheme, you can use `gridColor` and `textColor` props instead of CSS variables:
```python
dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
gridColor="gray.5",
textColor = "gray.9",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Tooltip animation
By default, tooltip animation is disabled. To enable it, set `tooltipAnimationDuration` prop to a number of milliseconds to animate the tooltip position change.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
tooltipAnimationDuration=200,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Units
Set `unit` prop to render a unit label next to the y-axis ticks and tooltip values:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
unit="$",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Remove tooltip
To remove tooltip, set `withTooltip=false`. It also removes the cursor line and disables interactions with the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
withTooltip=False,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Custom tooltip
Use the `tooltipProps` `content` prop to to pass custom tooltip renderer to recharts Tooltip component. For example:
```python
tooltipProps={'content': {'functon': 'myFunction'}}
```
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"}
],
tickLine="y",
gridAxis="y",
withXAxis=True,
withYAxis=True,
tooltipProps={"content": {"function": "chartTooltip"}}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.chartTooltip = ({ label, payload }) => {
if (!payload || payload.length === 0) return null;
return React.createElement(
dmc.Paper,
{
px: "md",
py: "sm",
withBorder: true,
shadow: "md",
radius: "md",
},
[
React.createElement(
dmc.Text,
{
key: "tooltip-label",
fw: 500,
mb: 5,
},
label
),
...payload.map((item, index) =>
React.createElement(
dmc.Text,
{
key: `item-${index}`,
c: item.color,
fz: "sm",
},
`${item.name}: ${item.value}`
)
),
]
);
};
```
### Sync multiple BarCharts
You can pass props down to recharts [BarChart](https://recharts.org/en-US/api/BarChart) component with `barChartProps`
prop. For example, setting will sync tooltip of multiple BarChart components with the same `syncId` prop.
```python
barChartProps={"syncId": "any-id"}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.Text("Smartphone sales:"),
dmc.BarChart(
h=180,
dataKey="month",
data=data,
series=[{"name": "Smartphones", "color": "violet.6"}],
barChartProps={"syncId": "tech"},
),
dmc.Text("Laptop sales"),
dmc.BarChart(
h=180,
dataKey="month",
data=data,
series=[{"name": "Laptops", "color": "teal.6"}],
barChartProps={"syncId": "tech"},
),
]
)
```
### Vertical orientation
Set orientation="vertical" to render a vertical bar chart:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
orientation="vertical",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Reference lines
Use `referenceLines` prop to render reference lines. Reference lines are always rendered behind the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
withTooltip=False,
referenceLines=[
{
"y": 130,
"color": "red.5",
"label": "Profit reached",
"labelPosition": "insideTopRight",
}
],
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
```
### Reference areas
Use the `referenceAreas` prop to highlight a rectangular region of the chart. Each area is bounded by x1/x2 (horizontal)
and y1/y2 (vertical) data values – omit one pair to span the full opposite axis, for example provide only x1/x2 to
highlight a time range across the entire height of the chart. Set `color` to any theme color or CSS color and label
to display text inside the area. Reference areas are rendered behind the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
data=data,
dataKey="month",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
referenceAreas=[
{"x1": "January", "x2": "March", "color": "red.6", "label": "Q1"},
],
)
```
### Reference dots
Use the `referenceDots` prop to mark individual points on the chart – a peak, an event, a record value or an anomaly.
Each dot is positioned by x and y data coordinates and supports `r` (radius), `color` (any theme color or CSS color) and
`label`. Reference dots are rendered on top of the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
data=data,
dataKey="month",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
referenceDots=[
{"x": "February", "y": 1900, "color": "red.6", "label": "Peak"},
],
)
```
### Bar value label
To display value above each bar, set `withBarValueLabel=True`:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
withBarValueLabel=True,
withLegend=True,
withTooltip=False,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
valueFormatter={"function": "formatNumberIntl"},
)
```
### Bar value label props
You can pass props down to [recharts LabelList](https://recharts.org/en-US/api/LabelList) component with `valueLabelProps` prop.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
withBarValueLabel=True,
valueLabelProps={"position": 'inside', "fill": 'white'},
withLegend=True,
withTooltip=False,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
valueFormatter={"function": "formatNumberIntl"},
)
```
### Brush (Range Slider)
Set the `withBrush` prop to display a brush (range slider) under the chart. Drag the brush handles to
zoom into a subset of the data. The chart updates to show only the selected range. The brush border and background are
themed to match the chart grid and adapt to the color scheme. `withBrush` is `False` by default and is supported by
`AreaChart`, `BarChart`, `LineChart` and `CompositeChart` components with `horizontal` orientation.
Use the `brushDragEnd` prop to get the `startIndex` and `endIndex` of the selected range when dragging ends.
Use the `brushProps` prop to pass props down to the underlying [recharts Brush](https://recharts.github.io/en-US/api/Brush/) component. For example, you can set the
initially selected range with `startIndex`/`endIndex`, change the brush height and more.
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
from .data import data2
component = dmc.Stack([
dmc.BarChart(
h=300,
data=data2,
dataKey="month",
withBrush=True,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
],
id="barchart-brush",
),
dmc.Text(id="barchart-brush-dragend"),
])
@callback(
Output("barchart-brush-dragend", "children"),
Input("barchart-brush", "brushDragEnd"),
)
def update_brush_range(brush_drag_end):
return f"Brush range selected: {brush_drag_end}"
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event.
To get the name of the clicked series, use the `clickSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.BarChart(
id="figure-barchart",
h=300,
dataKey="month",
data=data,
type="stacked",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
withLegend=True,
withTooltip=False,
),
dmc.Text(id="clickdata-barchart1"),
dmc.Text(id="clickdata-barchart2"),
]
)
@callback(
Output("clickdata-barchart1", "children"),
Output("clickdata-barchart2", "children"),
Input("figure-barchart", "clickData"),
Input("figure-barchart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event.
To get the name of the hovered series, use the `hoverSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.BarChart(
id="figure-barchart-hover",
h=300,
dataKey="month",
data=data,
type="stacked",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
withLegend=True,
withTooltip=False,
),
dmc.Text(id="hoverdata-barchart1"),
dmc.Text(id="hoverdata-barchart2"),
]
)
@callback(
Output("hoverdata-barchart1", "children"),
Output("hoverdata-barchart2", "children"),
Input("figure-barchart-hover", "hoverData"),
Input("figure-barchart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### highlightHover
Set `highlightHover=True` to highlight the series when hovered, mirroring the behavior of hovering over chart legend items.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
withLegend=True,
withTooltip=False,
highlightHover=True
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### BarChart selectors
| Selector | Static selector | Description |
|:-------------------|:---------------------------------|:-------------------------------------------------|
| root | .mantine-BarChart-root | Root element |
| bar | .mantine-BarChart-bar | Bar of the chart |
| axis | .mantine-BarChart-axis | X and Y axis of the chart |
| container | .mantine-BarChart-container | Recharts ResponsiveContainer component |
| grid | .mantine-BarChart-grid | Recharts CartesianGrid component |
| legend | .mantine-BarChart-legend | Legend root element |
| legendItem | .mantine-BarChart-legendItem | Legend item representing data series |
| legendItemColor | .mantine-BarChart-legendItemColor| Legend item color |
| legendItemName | .mantine-BarChart-legendItemName | Legend item name |
| tooltip | .mantine-BarChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-BarChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-BarChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-BarChart-tooltipItemBody| Tooltip item wrapper around item color and name|
| tooltipItemColor | .mantine-BarChart-tooltipItemColor| Tooltip item color |
| tooltipItemName | .mantine-BarChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-BarChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-BarChart-tooltipLabel | Label of the tooltip |
| referenceLine | .mantine-BarChart-referenceLine | Reference line |
| axisLabel | .mantine-BarChart-axisLabel | X and Y axis labels |
### BarChart CSS variables
| Selector | Variable | Description |
|:-----------------|:---------------------|:-------------------------------------------------|
| root | --chart-grid-color | Controls color of the grid and cursor lines |
| | --chart-text-color | Controls color of the axis labels |
| | --chart-cursor-fill | Controls fill color of the cursor line |
### Keyword Arguments
#### BarChart
- children (a list of or a singular dash component, string or number; optional):
Additional components that are rendered inside recharts `BarChart`
component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- barChartProps (dict; optional):
Props passed down to recharts `BarChart` component.
- barLabelColor (optional):
Controls color of the bar label, by default the value is
determined by the chart orientation.
- barProps (dict; optional):
Props passed down to recharts `Bar` component.
- brushDragEnd (dict with strings as keys and values of type number; optional):
The startIndex and endIndex of the selected brush range when
dragging ends. Read only.
- brushProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Brush` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- cursorFill (optional):
Fill of hovered bar section, by default value is based on color
scheme.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts with strings as keys and values of type boolean | number | string | dict | list; required):
Data used to display chart.
- data-* (string; optional):
Wild card data attributes.
- dataKey (string; required):
Key of the `data` object for x-axis values.
- fillOpacity (number; optional):
Controls fill opacity of all bars, `1` by default.
- getBarColor (boolean | number | string | dict | list; optional):
A function to assign dynamic bar color based on its value.
Accepts value and series returns MantineColor. See
https://www.dash-mantine-components.com/functions-as-props.
- gridAxis (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which lines should be displayed in the grid, `'x'` by
default.
- gridColor (optional):
Color of the grid and cursor lines, by default depends on color
scheme.
- gridProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `CartesianGrid` component.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- highlightHover (boolean; optional):
Determines whether a hovered series is highlighted. False by
default. Mirrors the behaviour when hovering about chart legend
items.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- legendProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxBarWidth (number; optional):
Maximum bar width in px.
- minBarSize (number; optional):
Sets minimum height of the bar in px, `0` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Chart orientation, `'horizontal'` by default.
- referenceAreas (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference areas that should be displayed on the chart.
- referenceDots (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference dots that should be displayed on the chart.
- referenceLines (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference lines that should be displayed on the chart.
- rightYAxisLabel (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- rightYAxisProps (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- series (list of dicts; required):
An array of objects with `name` and `color` keys. Determines which
data should be consumed from the `data` array.
`series` is a list of dicts with keys:
- strokeDasharray (string | number; optional):
Dash array for the grid lines and cursor, `'5 5'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Color of the text displayed inside the chart, `'dimmed'` by
default.
- tickLine (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which axis should have tick line, `'y'` by default.
- tooltipAnimationDuration (number; optional):
Tooltip position animation duration in ms, `0` by default.
- tooltipProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Tooltip` component.
- type (a value equal to: 'default', 'stacked', 'percent', 'waterfall'; optional):
Controls how bars are positioned relative to each other,
`'default'` by default.
- unit (string; optional):
Unit displayed next to each tick in y-axis.
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values on Y axis and inside the tooltip. See
https://www.dash-mantine-components.com/functions-as-props.
- valueLabelProps (dict; optional):
Props passed down to recharts `LabelList` component. Can be an
object with props like "position" for valueLabel formatting.
Only relevant, if withBarValueLabel is True.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBarValueLabel (boolean; optional):
Determines whether a label with bar value should be displayed on
top of each bar. On type="stacked" or type="percent",
additionally use withBarValueLabel to customize the label (e.g.
use {position: 'inside'} to move the labels inside each bar).
False by default.
- withBrush (boolean; optional):
Determines whether a brush (range selector) should be displayed
under the chart, `False` by default.
- withLegend (boolean; optional):
Determines whether chart legend should be displayed, `False` by
default.
- withRightYAxis (boolean; optional):
Determines whether additional y-axis should be displayed on the
right side of the chart, False by default.
- withTooltip (boolean; optional):
Determines whether chart tooltip should be displayed, `True` by
default.
- withXAxis (boolean; optional):
Determines whether x-axis should be hidden, `True` by default.
- withYAxis (boolean; optional):
Determines whether y-axis should be hidden, `True` by default.
- xAxisLabel (string; optional):
A label to display below the x-axis.
- xAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `XAxis` recharts component.
- yAxisLabel (string; optional):
A label to display next to the y-axis.
- yAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `YAxis` recharts component.
## BubbleChart
Bubble Chart component
Category: Charts
### Usage
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BubbleChart(
gridColor="gray.5",
textColor="gray.9",
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="lime.6",
dataKey={"x": "hour", "y": "index", "z": "value"}
)
```
### Data
Here is the data used in all the examples on this page:
```python
data = [
{"hour": "08:00", "index": 1, "value": 150},
{"hour": "10:00", "index": 1, "value": 166},
{"hour": "12:00", "index": 1, "value": 170},
{"hour": "14:00", "index": 1, "value": 150},
{"hour": "16:00", "index": 1, "value": 200},
{"hour": "18:00", "index": 1, "value": 400},
{"hour": "20:00", "index": 1, "value": 100},
{"hour": "22:00", "index": 1, "value": 160},
]
```
### Change color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS color value is also accepted.
### Change line color depending on color scheme
You can use CSS variables in color property. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
Example of line color that is dark orange in light mode and lime in dark mode:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BubbleChart(
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="var(--chart-color)",
dataKey={"x": "hour", "y": "index", "z": "value"}
)
```
```css
:root {
--chart-color: var(--mantine-color-orange-8)
}
:root[data-mantine-color-scheme="dark"] {
--chart-color: var(--mantine-color-lime-4);
}
```
### Grid and text colors
Use `--chart-grid-color` and `--chart-text-color` to change colors of grid lines and text within the chart.
With CSS , you can change colors depending on color scheme. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BubbleChart(
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
className="chart-grid-text-colors",
dataKey={"x": "hour", "y": "index", "z": "value"}
)
```
```css
.chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-5);
--chart-text-color: var(--mantine-color-blue-8);
}
[data-mantine-color-scheme='dark'] .chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-3);
--chart-text-color: var(--mantine-color-blue-2);
}
```
If your application has only one color scheme, you can use `gridColor` and `textColor` props instead of CSS variables:
```python
dmc.BubbleChart(
gridColor="gray.5",
textColor="gray.9",
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="lime.6",
dataKey={"x": "hour", "y": "index", "z": "value"}
)
```
### Value formatter
To format values in the tooltip and axis ticks, use `valueFormatter` prop. It accepts a function that takes number `value`
as an argument and returns formatted value:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BubbleChart(
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="lime.6",
dataKey={"x": "hour", "y": "index", "z": "value"},
valueFormatter={"function": "formatUsd"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatUsd = function (value) {
return `${value.toFixed(2)} USD`;
};
```
### Remove tooltip
To remove tooltip, set `withTooltip=False`. It also removes the cursor line and disables interactions with the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BubbleChart(
gridColor="gray.5",
textColor="gray.9",
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="lime.6",
dataKey={"x": "hour", "y": "index", "z": "value"},
withTooltip=False
)
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.BubbleChart(
id="figure-bubblechart",
gridColor="gray.5",
textColor="gray.9",
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="lime.6",
dataKey={"x": "hour", "y": "index", "z": "value"}
),
dmc.Text(id="clickdata-bubblechart"),
]
)
@callback(
Output("clickdata-bubblechart", "children"),
Input("figure-bubblechart", "clickData"),
)
def update(data):
return f"clickData: {data}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.BubbleChart(
id="figure-bubblechart-hover",
gridColor="gray.5",
textColor="gray.9",
h=60,
data=data,
range=[16, 225],
label="Sales/hour",
color="lime.6",
dataKey={"x": "hour", "y": "index", "z": "value"}
),
dmc.Text(id="hoverdata-bubblechart"),
]
)
@callback(
Output("hoverdata-bubblechart", "children"),
Input("figure-bubblechart-hover", "hoverData"),
)
def update(data):
return f"hoverData: {data}"
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### BubbleChart selectors
| Selector | Static selector | Description |
|----------|------------------------------|----------------------------|
| root | .mantine-BubbleChart-root | Root element |
| axis | .mantine-BubbleChart-axis | X and Y axis of the chart |
| tooltip | .mantine-BubbleChart-tooltip | Tooltip root element |
#### BubbleChart CSS variables
| Selector | Variable | Description |
|----------|-----------------------|---------------------------------------------|
| root | --chart-grid-color | Controls color of the grid and cursor lines |
| | --chart-text-color | Controls color of the axis labels |
### Keyword Arguments
#### BubbleChart
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- color (optional):
Color of the chart items. Key of `theme.colors` or any valid CSS
color, `blue.6` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts with strings as keys and values of type boolean | number | string | dict | list; required):
Chart data.
- data-* (string; optional):
Wild card data attributes.
- dataKey (dict; required):
Data keys for x, y and z axis.
`dataKey` is a dict with keys:
- gridColor (optional):
Color of the grid and cursor lines, by default depends on color
scheme.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- label (string; optional):
Chart label displayed next to the x axis.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- range (list of 2 elements: [number, number]; required):
Z axis range.
- scatterProps (dict; optional):
Props passed down to the `Scatter` component.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Color of the text displayed inside the chart, `'dimmed'` by
default.
- tooltipProps (dict; optional):
Props passed down to the `Tooltip` component.
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values on Y axis and inside the tooltip. See
https://www.dash-mantine-components.com/functions-as-props.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withTooltip (boolean; optional):
Determines whether the tooltip should be displayed, `True` by
default.
- xAxisProps (dict; optional):
Props passed down to the `XAxis` recharts component.
- yAxisProps (dict; optional):
Props passed down to the `YAxis` recharts component.
- zAxisProps (dict; optional):
Props passed down to the `ZAxis` recharts component.
## CompositeChart
Composed chart with support for Area, Bar and Line charts
Category: Charts
### Introduction
```python
import dash_mantine_components as dmc
from .data import data
dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Data
Here is the data used in all the examples on this page:
```python
data = [
{
"date": "Mar 22",
"Apples": 2890,
"Oranges": 2338,
"Tomatoes": 2452,
},
{
"date": "Mar 23",
"Apples": 2756,
"Oranges": 2103,
"Tomatoes": 2402,
},
{
"date": "Mar 24",
"Apples": 3322,
"Oranges": 986,
"Tomatoes": 1821,
},
{
"date": "Mar 25",
"Apples": 3470,
"Oranges": 2108,
"Tomatoes": 2809,
},
{
"date": "Mar 26",
"Apples": 3129,
"Oranges": 1726,
"Tomatoes": 2290,
},
]
```
### Legend
To display chart legend, set `withLegend` prop. When one of the items in the legend is hovered, the corresponding data
series is highlighted in the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Legend position
You can pass props down to recharts `Legend` component with `legendProps` prop. For example, setting the following will
render the legend at the bottom of the chart and set its height to 50px.
```python
legendProps={"verticalAlign": "bottom", "height": 50}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
legendProps={"verticalAlign": "bottom", "height": 50},
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Series labels
By default, series `name` is used as a label. To change it, set `label` property in `series` object:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withLegend=True,
legendProps={"verticalAlign": "bottom"},
maxBarWidth=30,
series=[
{
"name": "Tomatoes",
"label": "Tomatoes sales",
"color": "rgba(18, 120, 255, 0.2)",
"type": "bar",
},
{
"name": "Apples",
"label": "Apples sales",
"color": "red.8",
"type": "line",
},
{
"name": "Oranges",
"label": "Oranges sales",
"color": "yellow.8",
"type": "area",
},
]
)
```
### Points labels
To display labels on data points, set `withPointLabels=True`. This feature is supported only for Line and Area charts:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withPointLabels=True,
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### X and Y axis props
Use `xAxisProps` and `yAxisProps` to pass props down to recharts `XAxis` and `YAxis` components. For example, these
props can be used to change orientation of axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
tickLine="xy",
yAxisProps={"tickMargin": 15, "orientation": "right"},
xAxisProps={"tickMargin": 15, "orientation": "top"},
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Axis labels
Use `xAxisLabel` and `yAxisLabel` props to display axis labels:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
xAxisLabel="Date",
yAxisLabel="Amount",
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
xAxisLabel="Date",
yAxisLabel="Amount",
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### X axis offset
Use `xAxisProps` to set padding between the charts ends and the x-axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.BarChart(
h=300,
dataKey="month",
data=data,
type="stacked",
xAxisProps={"padding": {"left": 30, "right": 30}},
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
{"name": "Tablets", "color": "teal.6"},
],
)
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
xAxisProps={"padding": {"left": 30, "right": 30}},
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Y axis scale
Use `yAxisProps` to change domain of the Y axis. For example, if you know that your data will always be in the range
of 0 to 150, you can set domain to `[0, 150]`:
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 50},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": 40},
{"date": "Mar 25", "Apples": 30},
{"date": "Mar 26", "Apples": 0},
{"date": "Mar 27", "Apples": 20},
{"date": "Mar 28", "Apples": 20},
{"date": "Mar 29", "Apples": 10},
]
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
yAxisProps={"domain": [0, 100]},
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Apples", "color": "red.8", "type": "line"},
]
)
```
### Chart color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Apples", "color": "blue", "type": "line"},
]
)
```
### Change chart color depending on color scheme
You can use CSS variables in color property. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
Example of line color that is dark orange in light mode and lime in dark mode:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
dataKey="date",
data=data,
series=[{"name": "Apples", "color": "var(--chart-color)", "type": "line" }],
)
```
```css
:root {
--chart-color: var(--mantine-color-orange-8)
}
:root[data-mantine-color-scheme="dark"] {
--chart-color: var(--mantine-color-lime-4);
}
```
### Stroke dash array
Set `strokeDasharray` prop to control the stroke dash array of the grid and cursor lines. The value represent the lengths of alternating dashes and gaps. For example, strokeDasharray="10 5" will render a dashed line with 10px dashes and 5px gaps.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
strokeDasharray="15 15",
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Grid and text colors
Use `--chart-grid-color` and `--chart-text-color` to change colors of grid lines and text within the chart.
With CSS , you can change colors depending on color scheme. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
dataKey="date",
data=data,
maxBarWidth=30,
className="chart-grid-text-colors",
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
```css
.chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-5);
--chart-text-color: var(--mantine-color-blue-8);
}
[data-mantine-color-scheme='dark'] .chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-3);
--chart-text-color: var(--mantine-color-blue-2);
}
```
If your application has only one color scheme, you can use `gridColor` and `textColor` props instead of CSS variables:
```python
dmc.CompositeChart(
h=300,
dataKey="date",
data=data,
maxBarWidth=30,
gridColor="gray.5",
textColor="gray.9",
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Tooltip animation
By default, tooltip animation is disabled. To enable it, set `tooltipAnimationDuration` prop to a number of milliseconds to animate the tooltip position change.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
tooltipAnimationDuration=200,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Value formatter
To format values in the tooltip and axis ticks, use `valueFormatter` prop. It accepts a function that takes number `value`
as an argument and returns formatted value:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
maxBarWidth=30,
valueFormatter={"function": "formatNumberIntl"},
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatNumberIntl = (value) => {
return new Intl.NumberFormat('en-US').format(value);
};
```
### Units
Set `unit` prop to render a unit label next to the y-axis ticks and tooltip values:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
unit="$",
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Remove tooltip
To remove tooltip, set `withTooltip=false`. It also removes the cursor line and disables interactions with the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withTooltip=False,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Custom tooltip
Use the `tooltipProps` `content` prop to to pass custom tooltip renderer to recharts Tooltip component. For example:
```python
tooltipProps={'content': {'functon': 'myFunction'}}
```
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
tooltipProps={"content": {"function": "chartTooltip"}},
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.chartTooltip = ({ label, payload }) => {
if (!payload || payload.length === 0) return null;
return React.createElement(
dmc.Paper,
{
px: "md",
py: "sm",
withBorder: true,
shadow: "md",
radius: "md",
},
[
React.createElement(
dmc.Text,
{
key: "tooltip-label",
fw: 500,
mb: 5,
},
label
),
...payload.map((item, index) =>
React.createElement(
dmc.Text,
{
key: `item-${index}`,
c: item.color,
fz: "sm",
},
`${item.name}: ${item.value}`
)
),
]
);
};
```
### Customize dots
Use `dotProps` to pass props down to recharts dot in regular state and `activeDotProps` to pass props down to recharts
dot in active state (when cursor is over the current series).
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
dotProps={"r": 6, "strokeWidth": 2, "stroke": "#fff"},
activeDotProps={"r": 8, "strokeWidth": 1, "fill": "#fff"},
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
)
```
### Stroke width
Use `strokeWidth` prop to control the stroke width of all areas/lines:
### Sync multiple charts
You can pass props down to recharts [ComposedChart](https://recharts.org/en-US/api/ComposedChart) component with
`composedChartProps` prop. For example, setting the following will sync tooltip of multiple `CompositeChart` components
with the same `syncId` prop.
```python
composedChartProps={"syncId": "any-id"}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.Text("Apples sales:", mb="md", pl="md"),
dmc.CompositeChart(
h=180,
data=data,
dataKey="date",
series=[{"name": "Apples", "color": "indigo.6", "type": "area"}],
composedChartProps={"syncId": "groceries"}
),
dmc.Text("Tomatoes sales:", mb="md", pl="md", mt="xl"),
dmc.CompositeChart(
h=180,
data=data,
dataKey="date",
series=[{"name": "Tomatoes", "color": "cyan.6", "type": "bar"}],
composedChartProps={"syncId": "groceries"}
)
]
)
```
### Dashed lines
Set `strokeDasharray` property in series to change line style to dashed:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
strokeWidth=1,
dotProps={"r": 2},
activeDotProps={"r": 3, "strokeWidth": 1},
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line", "strokeDasharray": "5 5"},
{"name": "Oranges", "color": "yellow.8", "type": "area", "strokeDasharray": "5 5"},
]
)
```
### Reference lines
Use `referenceLines` prop to render reference lines. Reference lines are always rendered behind the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
yAxisProps={"domain": [0, 100]},
referenceLines=[
{"y": 1200, "label": "Average sales", "color": "red.6"},
{"x": "Mar 25", "label": "Report out", "color": "blue.7"},
],
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
]
)
```
### Reference areas
Use the `referenceAreas` prop to highlight a rectangular region of the chart. Each area is bounded by x1/x2 (horizontal)
and y1/y2 (vertical) data values – omit one pair to span the full opposite axis, for example provide only x1/x2 to
highlight a time range across the entire height of the chart. Set `color` to any theme color or CSS color and label
to display text inside the area. Reference areas are rendered behind the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
],
referenceAreas=[
{"x1": "Mar 24", "x2": "Mar 26", "color": "blue.6", "label": "Promotion"},
],
)
```
### Reference dots
Use the `referenceDots` prop to mark individual points on the chart – a peak, an event, a record value or an anomaly.
Each dot is positioned by x and y data coordinates and supports `r` (radius), `color` (any theme color or CSS color) and
`label`. Reference dots are rendered on top of the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
],
referenceDots=[
{"x": "Mar 25", "y": 2764, "color": "red.8", "label": "Peak"},
],
)
```
### Brush (Range Slider)
Set the `withBrush` prop to display a brush (range slider) under the chart. Drag the brush handles to
zoom into a subset of the data. The chart updates to show only the selected range. The brush border and background are
themed to match the chart grid and adapt to the color scheme. `withBrush` is `False` by default and is supported by
`AreaChart`, `BarChart`, `LineChart` and `CompositeChart` components with `horizontal` orientation.
Use the `brushDragEnd` prop to get the `startIndex` and `endIndex` of the selected range when dragging ends.
Use the `brushProps` prop to pass props down to the underlying [recharts Brush](https://recharts.github.io/en-US/api/Brush/) component. For example, you can set the
initially selected range with `startIndex`/`endIndex`, change the brush height and more:
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
from .data import data2
component = dmc.Stack([
dmc.CompositeChart(
h=300,
data=data2,
dataKey="date",
maxBarWidth=30,
withBrush=True,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
],
id="compositechart-brush",
),
dmc.Text(id="compositechart-brush-dragend"),
])
@callback(
Output("compositechart-brush-dragend", "children"),
Input("compositechart-brush", "brushDragEnd"),
)
def update_brush_range(brush_drag_end):
return f"Brush range selected: {brush_drag_end}"
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event.
To get the name of the clicked series, use the `clickSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.CompositeChart(
id="figure-compositechart",
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
),
dmc.Text(id="clickdata-compositechart1"),
dmc.Text(id="clickdata-compositechart2"),
]
)
@callback(
Output("clickdata-compositechart1", "children"),
Output("clickdata-compositechart2", "children"),
Input("figure-compositechart", "clickData"),
Input("figure-compositechart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event.
To get the name of the hovered series, use the `hoverSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.CompositeChart(
id="figure-compositechart-hover",
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
]
),
dmc.Text(id="hoverdata-compositechart1"),
dmc.Text(id="hoverdata-compositechart2"),
]
)
@callback(
Output("hoverdata-compositechart1", "children"),
Output("hoverdata-compositechart2", "children"),
Input("figure-compositechart-hover", "hoverData"),
Input("figure-compositechart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### highlightHover
Set `highlightHover=True` to highlight the series when hovered, mirroring the behavior of hovering over chart legend items.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.CompositeChart(
h=300,
data=data,
dataKey="date",
withLegend=True,
maxBarWidth=30,
series=[
{"name": "Tomatoes", "color": "rgba(18, 120, 255, 0.2)", "type": "bar"},
{"name": "Apples", "color": "red.8", "type": "line"},
{"name": "Oranges", "color": "yellow.8", "type": "area"},
],
withTooltip=False,
highlightHover=True
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### CompositeChart selectors
| Selector | Static selector | Description |
|--------------------|-------------------------------------------|-----------------------------------------------|
| root | .mantine-CompositeChart-root | Root element |
| area | .mantine-CompositeChart-area | Area of the chart |
| line | .mantine-CompositeChart-line | Line of the chart |
| bar | .mantine-CompositeChart-bar | Bar of the chart |
| axis | .mantine-CompositeChart-axis | X and Y axis of the chart |
| container | .mantine-CompositeChart-container | Recharts ResponsiveContainer component |
| grid | .mantine-CompositeChart-grid | Recharts CartesianGrid component |
| legend | .mantine-CompositeChart-legend | Legend root element |
| legendItem | .mantine-CompositeChart-legendItem | Legend item representing data series |
| legendItemColor | .mantine-CompositeChart-legendItemColor | Legend item color |
| legendItemName | .mantine-CompositeChart-legendItemName | Legend item name |
| tooltip | .mantine-CompositeChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-CompositeChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-CompositeChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-CompositeChart-tooltipItemBody | Tooltip item wrapper around item color and name |
| tooltipItemColor | .mantine-CompositeChart-tooltipItemColor | Tooltip item color |
| tooltipItemName | .mantine-CompositeChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-CompositeChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-CompositeChart-tooltipLabel | Label of the tooltip |
| referenceLine | .mantine-CompositeChart-referenceLine | Reference line |
| axisLabel | .mantine-CompositeChart-axisLabel | X and Y axis labels |
### Composite CSS variables
| Selector | Variable | Description |
|:-----------------|:---------------------|:-------------------------------------------------|
| root | --chart-grid-color | Controls color of the grid and cursor lines |
| | --chart-text-color | Controls color of the axis labels |
### Keyword Arguments
#### CompositeChart
- children (a list of or a singular dash component, string or number; optional):
Additional components that are rendered inside `Composite`
component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- activeDotProps (boolean | number | string | dict | list; optional):
Props passed down to all active dots. Ignored if
`withDots={False}` is set.
- areaProps (dict; optional):
Props passed down to recharts `Area` component.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- barProps (dict; optional):
Props passed down to recharts `Bar` component.
- brushDragEnd (dict with strings as keys and values of type number; optional):
The startIndex and endIndex of the selected brush range when
dragging ends. Read only.
- brushProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Brush` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data for entire dataKey.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- composedChartProps (dict; optional):
Props passed down to recharts `Composite` component.
- connectNulls (boolean; optional):
Determines whether points with `None` values should be connected,
`True` by default.
- curveType (a value equal to: 'bump', 'linear', 'natural', 'monotone', 'step', 'stepBefore', 'stepAfter'; optional):
Controls how curve of lines and area series are displayed,
`'montone'` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts with strings as keys and values of type boolean | number | string | dict | list; required):
Data used to display chart.
- data-* (string; optional):
Wild card data attributes.
- dataKey (string; required):
Key of the `data` object for x-axis values.
- dotProps (boolean | number | string | dict | list; optional):
Props passed down to all dots. Ignored if `withDots={False}` is
set.
- gridAxis (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which lines should be displayed in the grid, `'x'` by
default.
- gridColor (optional):
Color of the grid and cursor lines, by default depends on color
scheme.
- gridProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `CartesianGrid` component.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- highlightHover (boolean; optional):
Determines whether a hovered series is highlighted. False by
default. Mirrors the behaviour when hovering about chart legend
items.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data for entire dataKey.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- legendProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- lineProps (dict; optional):
Props passed down to recharts `Line` component.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxBarWidth (number; optional):
Maximum bar width in px.
- minBarSize (number; optional):
Sets minimum height of the bar in px, `0` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- referenceAreas (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference areas that should be displayed on the chart.
- referenceDots (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference dots that should be displayed on the chart.
- referenceLines (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference lines that should be displayed on the chart.
- rightYAxisLabel (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- rightYAxisProps (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- series (list of dicts; required):
An array of objects with `name`, `color` and `type` keys.
Determines which data should be consumed from the `data` array.
`series` is a list of dicts with keys:
- strokeDasharray (string | number; optional):
Dash array for the grid lines and cursor, `'5 5'` by default.
- strokeWidth (number; optional):
Stroke width for the chart lines, `2` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Color of the text displayed inside the chart, `'dimmed'` by
default.
- tickLine (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which axis should have tick line, `'y'` by default.
- tooltipAnimationDuration (number; optional):
Tooltip position animation duration in ms, `0` by default.
- tooltipProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Tooltip` component.
- unit (string; optional):
Unit displayed next to each tick in y-axis.
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values on Y axis and inside the tooltip. See
https://www.dash-mantine-components.com/functions-as-props.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBarValueLabel (boolean; optional):
Determines whether a label with bar value should be displayed on
top of each bar, incompatible with `type="stacked"` and
`type="percent"`, `False` by default.
- withBrush (boolean; optional):
Determines whether a brush (range selector) should be displayed
under the chart, `False` by default.
- withDots (boolean; optional):
Determines whether dots should be displayed, `True` by default.
- withLegend (boolean; optional):
Determines whether chart legend should be displayed, `False` by
default.
- withPointLabels (boolean; optional):
Determines whether a label with value should be displayed on top
of a curve, This feature is supported only for Line and Area
series.
- withRightYAxis (boolean; optional):
Determines whether additional y-axis should be displayed on the
right side of the chart, False by default.
- withTooltip (boolean; optional):
Determines whether chart tooltip should be displayed, `True` by
default.
- withXAxis (boolean; optional):
Determines whether x-axis should be hidden, `True` by default.
- withYAxis (boolean; optional):
Determines whether y-axis should be hidden, `True` by default.
- xAxisLabel (string; optional):
A label to display below the x-axis.
- xAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `XAxis` recharts component.
- yAxisLabel (string; optional):
A label to display next to the y-axis.
- yAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `YAxis` recharts component.
## DonutChart
Donut chart component
Category: Charts
### Usage
`DonutChart` is based on [PieChart recharts component](https://recharts.org/en-US/api/PieChart):
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.DonutChart(data=data)
```
### Data
Here is the data imported for the examples on this page:
```python
data = [
{ "name": "USA", "value": 400, "color": "indigo.6" },
{ "name": "India", "value": 300, "color": "yellow.6" },
{ "name": "Japan", "value": 100, "color": "teal.6" },
{ "name": "Other", "value": 200, "color": "gray.6" }
]
```
### Legend
To display the legend, set the `withLegend` prop. The legend displays the name and color of each segment. Hover over
a legend item to highlight the corresponding segment.
You can pass props down to the recharts Legend component with the `legendProps` prop. For example, set
`legendProps={"verticalAlign": 'top'}` to display the legend above the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.DonutChart(data=data, withLegend=True)
```
### Segments labels
Set `withLabels` prop to display labels next to each segment:
```python
import dash_mantine_components as dmc
from .data import data
dmc.DonutChart(
data=data,
withLabels=True,
withLabelsLine=True
)
```
### Size and thickness
Set `size` prop to control width and height of the chart. Note that if `withLabels` prop is set, the chart height is
automatically increased by 80px to make room for labels. You can override this behavior by setting `h` style prop.
```python
import dash_mantine_components as dmc
from .data import data
dmc.DonutChart(
data=data,
size=160,
thickness=30
)
```
### Padding angle
Use `paddingAngle` prop to control the space between segments:
```python
import dash_mantine_components as dmc
from .data import data
dmc.DonutChart(
data=data,
paddingAngle=30,
)
```
### Segment color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc.
Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
data = [
{"name": "USA", "value": 400, "color": "blue"},
{"name": "Other", "value": 200, "color": "gray.6"},
]
component = dmc.DonutChart(data=data)
```
### Tooltip data source
By default, the tooltip displays data for all segments when hovered over any segment. To display data only for the hovered segment, set tooltipDataSource="segment":
```python
import dash_mantine_components as dmc
from dash import html
from .data import data
component = dmc.Group(
[
html.Div(
[
dmc.Text(
"Data only for hovered segment", fz="xs", mb="sm", ta="center"
),
dmc.DonutChart(
data=data,
withTooltip=True,
tooltipDataSource="segment",
mx="auto",
),
]
),
html.Div(
[
dmc.Text("Data only for all segments", fz="xs", mb="sm", ta="center"),
dmc.DonutChart(
data=data,
withTooltip=True,
mx="auto",
),
]
),
],
gap=50,
)
```
### Without tooltip
To remove the tooltip, set `withTooltip=False`:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.DonutChart(data=data, withTooltip=False)
```
### Chart label
To display a label in the center of the chart, use `chartLabel` prop. It accepts a string or a number:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.DonutChart(data=data, chartLabel="Users by country")
```
### Start and end angle
Use `startAngle` and `endAngle` props to control the start and end angle of the chart. For example, to display a
half-circle chart, set `startAngle=180` and `endAngle=0`:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.DonutChart(data=data, startAngle=180, endAngle=0)
```
### Segments stroke
Use `strokeWidth` prop to control the width of the stroke around each segment.
```python
import dash_mantine_components as dmc
from .data import data
dmc.DonutChart(
data=data,
strokeWidth=1.8
)
```
To change color of the stroke, use `strokeColor` prop. You can reference colors from theme the same way as in other
components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS color value is also accepted.
```python
dmc.DonutChart(
data=data,
strokeColor="red.5"
)
```
By default, segments stroke color is the same as the background color of the body element
(`--mantine-color-body` CSS variable). If you want to change it depending on the color scheme, define CSS variable
and pass it to the `strokeColor` prop:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.DonutChart(data=data, strokeColor="var(--card-bg)")
```
```css
.root {
--card-bg: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-5));
background-color: var(--card-bg);
padding: var(--mantine-spacing-md);
border-radius: var(--mantine-radius-md);
}
```
### Donut animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `pieProps` to pass properties to the Recharts `Pie` component.
```python
from random import randint
import dash_mantine_components as dmc
from dash import callback, Input, Output
def get_data(values):
return [
{"name": "A", "value": values[0], "color": "indigo.6"},
{"name": "B", "value": values[1], "color": "yellow.6"},
{"name": "C", "value": values[2], "color": "teal.6"},
{"name": "C", "value": values[3], "color": "gray.6"},
]
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-donutchart-animation", n_clicks=0, mb="md"),
dmc.DonutChart(
id="donutchart-animation",
data=get_data([100, 0, 0, 0]),
pieProps={"isAnimationActive": True},
),
]
)
@callback(
Output("donutchart-animation", "data"),
Input("btn-donutchart-animation", "n_clicks"),
)
def update(n):
if n % 2 == 0:
return get_data([400, 300, 600, 100])
return get_data([100, 0, 0, 0])
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event. To get the name of the
clicked series, use the `clickSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.DonutChart(id="figure-donutchart", data=data, withTooltip=False),
dmc.Text(id="clickdata-donutchart1"),
dmc.Text(id="clickdata-donutchart2"),
]
)
@callback(
Output("clickdata-donutchart1", "children"),
Output("clickdata-donutchart2", "children"),
Input("figure-donutchart", "clickData"),
Input("figure-donutchart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event. To get the name of the
hovered series, use the `hoverSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.DonutChart(id="figure-donutchart-hover", data=data, withTooltip=False),
dmc.Text(id="hoverdata-donutchart1"),
dmc.Text(id="hoverdata-donutchart2"),
]
)
@callback(
Output("hoverdata-donutchart1", "children"),
Output("hoverdata-donutchart2", "children"),
Input("figure-donutchart-hover", "hoverData"),
Input("figure-donutchart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### DonutChart selectors
| Selector | Static selector | Description |
|:------------|:-----------------------------|:----------------------------------------|
| root | .mantine-DonutChart-root | Root element |
| label | .mantine-DonutChart-label | Chart label, controlled by chartLabel prop |
#### DonutChart CSS variables
| Selector | Variable | Description |
|:-----------------|:-----------------------|:-----------------------------------------|
| root | --chart-labels-color | Controls color of the chart labels |
| | --chart-size | Controls size of the chart |
| | --chart-stroke-color | Controls color of the chart stroke |
### Keyword Arguments
#### DonutChart
- children (a list of or a singular dash component, string or number; optional):
Additional elements rendered inside `PieChart` component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- chartLabel (string | number; optional):
Chart label, displayed in the center of the chart.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts; required):
Data used to render chart.
`data` is a list of dicts with keys:
- data-* (string; optional):
Wild card data attributes.
- endAngle (number; optional):
Controls angle at which charts ends, `360` by default. Set to `0`
to render the chart as semicircle.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- labelColor (optional):
Controls text color of all labels, by default depends on color
scheme.
- labelsType (a value equal to: 'percent', 'value', 'name'; optional):
Type of labels to display, `'value'` by default.
- legendProps (dict; optional):
Props passed down to recharts `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- paddingAngle (number; optional):
Controls padding between segments, `0` by default.
- pieChartProps (dict; optional):
Props passed down to recharts `PieChart` component.
- pieProps (dict; optional):
Props passed down to recharts `Pie` component.
- size (number; optional):
Controls chart width and height, height is increased by 40 if
`withLabels` prop is set. Cannot be less than `thickness`. `80` by
default.
- startAngle (number; optional):
Controls angle at which chart starts, `0` by default. Set to `180`
to render the chart as semicircle.
- strokeColor (optional):
Controls color of the segments stroke, by default depends on color
scheme.
- strokeWidth (number; optional):
Controls width of segments stroke, `1` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- thickness (number; optional):
Controls thickness of the chart segments, `20` by default.
- tooltipAnimationDuration (number; optional):
Tooltip animation duration in ms, `0` by default.
- tooltipDataSource (a value equal to: 'segment', 'all'; optional):
Determines which data is displayed in the tooltip. `'all'` –
display all values, `'segment'` – display only hovered segment.
`'all'` by default.
- tooltipProps (dict; optional):
Props passed down to `Tooltip` recharts component.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withLabels (boolean; optional):
Determines whether each segment should have associated label,
`False` by default.
- withLabelsLine (boolean; optional):
Determines whether segments labels should have lines that connect
the segment with the label, `True` by default.
- withLegend (boolean; optional):
Determines whether the legend should be displayed default False.
- withTooltip (boolean; optional):
Determines whether the tooltip should be displayed when one of the
section is hovered, `True` by default.
## FunnelChart
FunnelChart component
Category: Charts
### Usage
`FunnelChart` is based on the [FunnelChart recharts component](https://recharts.org/en-US/api/FunnelChart):
```python
import dash_mantine_components as dmc
from .data import data
component=dmc.FunnelChart(data=data)
```
### Data
Here is the data imported for the examples on this page:
```python
data = [
{"name": "USA", "value": 400, "color": "indigo.6"},
{"name": "India", "value": 300, "color": "yellow.6"},
{"name": "Japan", "value": 100, "color": "teal.6"},
{"name": "Other", "value": 200, "color": "gray.6"},
]
```
### Legend
To display the legend, set the `withLegend` prop. The legend displays the name and color of each segment. Hover over
a legend item to highlight the corresponding segment.
You can pass props down to the recharts Legend component with the `legendProps` prop. For example, set
`legendProps={"verticalAlign": 'top'}` to display the legend above the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.FunnelChart(data=data, withLegend=True)
```
### Segments labels
Set the `withLabels` prop to display labels next to each segment.
Use the `labelPosition` prop to control the position of labels relative to the corresponding segment. Supported values are 'left', 'right', and 'inside'.
### Size and thickness
Set the `size` prop to control the width and height of the chart.
You can override this behavior by setting the `h` [style prop](/style-props).
### Segment color
You can reference colors from [theme](/theme-object) the same way as in
other components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS
color value is also accepted.
```python
import dash_mantine_components as dmc
component = dmc.FunnelChart(
data=[
{ 'name': 'USA', 'value': 400, 'color': 'blue' },
{ 'name': 'Other', 'value': 200, 'color': 'gray.6' },
]
)
```
### Without tooltip
To remove the tooltip, set `withTooltip=False`:
```python
import dash_mantine_components as dmc
from .data import data
component=dmc.FunnelChart(
data=data,
withTooltip=False
)
```
### Segments stroke
Use the `strokeWidth` prop to control the width of the stroke around each segment:
To change the color of the stroke, use the `strokeColor` prop. You can reference colors from the [theme](/colors) the same way as in
other components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
dmc.FunnelChart(data=data, strokeColor="red.5")
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event. To get the name of the
clicked series, use the `clickSeriesName` property.
```python
import dash_mantine_components as dmc
from dash import Input, Output, callback
from .data import data
component = dmc.Stack(
[
dmc.FunnelChart(
id="figure-funnelchart-click",
data=data,
),
dmc.Text(id="clickdata-funnelchart1"),
dmc.Text(id="clickdata-funnelchart2"),
]
)
@callback(
Output("clickdata-funnelchart1", "children"),
Output("clickdata-funnelchart2", "children"),
Input("figure-funnelchart-click", "clickData"),
Input("figure-funnelchart-click", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event. To get the name of the
hovered series, use the `hoverSeriesName` property.
```python
import dash_mantine_components as dmc
from dash import Input, Output, callback
from .data import data
component = dmc.Stack(
[
dmc.FunnelChart(
id="figure-funnelchart",
data=data,
),
dmc.Text(id="hoverdata-funnelchart1"),
dmc.Text(id="hoverdata-funnelchart2"),
]
)
@callback(
Output("hoverdata-funnelchart1", "children"),
Output("hoverdata-funnelchart2", "children"),
Input("figure-funnelchart", "hoverData"),
Input("figure-funnelchart", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### FunnelChart selectors
| Selector | Static selector | Description |
|----------|----------------|-------------|
| root | .mantine-FunnelChart-root | Root element |
| tooltip | .mantine-FunnelChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-FunnelChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-FunnelChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-FunnelChart-tooltipItemBody | Tooltip item wrapper around item color and name |
| tooltipItemColor | .mantine-FunnelChart-tooltipItemColor | Tooltip item color |
| tooltipItemName | .mantine-FunnelChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-FunnelChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-FunnelChart-tooltipLabel | Label of the tooltip |
#### FunnelChart CSS variables
| Selector | Variable | Description |
|----------|----------|-------------|
| root | --chart-labels-color | Controls color of the chart labels |
| root | --chart-size | Controls size of the chart |
| root | --chart-stroke-color | Controls color of the chart stroke |
### Keyword Arguments
#### FunnelChart
- children (a list of or a singular dash component, string or number; optional):
Additional elements rendered inside `FunnelChart` component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts; required):
Data used to render chart.
`data` is a list of dicts with keys:
- data-* (string; optional):
Wild card data attributes.
- funnelChartProps (dict; optional):
Props passed down to recharts `FunnelChart` component.
- funnelProps (dict; optional):
Props passed down to recharts `Funnel` component.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- labelColor (optional):
Controls text color of all labels Default 'white'.
- labelsPosition (a value equal to: 'left', 'right', 'inside'; optional):
Controls labels position relative to the segment.Default 'right'.
- legendProps (dict; optional):
Props passed down to recharts `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- size (number; optional):
Controls chart width and height Default 300.
- strokeColor (optional):
Controls color of the segments stroke, by default depends on color
scheme.
- strokeWidth (number; optional):
Controls width of segments stroke Default 1.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- tooltipAnimationDuration (number; optional):
Tooltip animation duration in ms Default 0.
- tooltipDataSource (a value equal to: 'segment', 'all'; optional):
Determines which data is displayed in the tooltip. `'all'` –
display all values, `'segment'` – display only hovered segment.
Default 'all'.
- tooltipProps (dict; optional):
Props passed down to `Tooltip` recharts component.
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values inside the tooltip and labels.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withLabels (boolean; optional):
Determines whether each segment should have associated label.
Default False.
- withLegend (boolean; optional):
Determines whether the legend should be displayed default False.
- withTooltip (boolean; optional):
Determines whether the tooltip should be displayed when a section
is hovered Default True.
## Heatmap
Heatmap component
Category: Charts
### Usage
`Heatmap` is used to display data in a table where each column represents a week.
The only required prop is `data`, a dictionary where keys are dates in `YYYY-MM-DD` format and values are numbers.
The `startDate` and `endDate` props are optional; they are used to define the heatmap range.
If not set, the heatmap will display data for the last year.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16"
)
```
## Data format
`Heatmap` expects data in the following format:
```python
data = {
'2025-02-14': 2,
'2025-02-11': 3,
'2025-02-06': 4,
'2025-02-05': 1,
'2025-02-03': 2,
'2025-02-01': 2,
'2025-01-31': 4,
'2025-01-30': 2,
# ...
}
```
### With tooltip
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
Set the `withTooltip` and `getTooltipLabel` props to display a tooltip when
`Heatmap` cells are hovered. `getTooltipLabel` is called with date and value
and must return a string to display in the tooltip.
This example uses [dayjs](https://day.js.org/) to simplify working with dates in JavaScript.
To use `dayjs` in your Dash app, load it as an external script:
```python
app = Dash(external_scripts=[
"https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.8/dayjs.min.js"
])
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
withTooltip=True,
withWeekdayLabels=True,
withMonthLabels=True,
getTooltipLabel={"function": "heatmapTooltip"}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dayjs = window.dayjs;
dmcfuncs.heatmapTooltip = ({ date, value }) =>
`${dayjs(date).format('DD MMM, YYYY')} – ${value === null || value === 0 ? 'No contributions' : `${value} contribution${value > 1 ? 's' : ''}`}`
```
### Change colors
`Heatmap` colors can be changed with the `colors` prop. It should be an array of any
valid CSS color values (hex, rgba, CSS variables, etc.). By default, `Heatmap`
uses 4 colors to indicate heat level, but you can pass any number of colors.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
colors=[
'var(--mantine-color-orange-4)',
'var(--mantine-color-orange-6)',
'var(--mantine-color-orange-7)',
'var(--mantine-color-orange-9)',
]
)
```
### Colors depending on color scheme
If you want to change colors depending on the color scheme,
you should define those colors in `.css` file:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
className="heatmap-light-dark",
)
```
```css
/* applied in light color-scheme */
.heatmap-light-dark {
--heatmap-level-1: var(--mantine-color-blue-2);
--heatmap-level-2: var(--mantine-color-blue-4);
--heatmap-level-3: var(--mantine-color-blue-6);
--heatmap-level-4: var(--mantine-color-blue-9);
}
/* applied in dark color-scheme */
[data-mantine-color-scheme='dark'] .heatmap-light-dark {
--heatmap-level-1: rgba(253, 126, 20, 0.35);
--heatmap-level-2: rgba(253, 126, 20, 0.65);
--heatmap-level-3: var(--mantine-color-orange-6);
--heatmap-level-4: var(--mantine-color-yellow-4);
}
```
Note that in this case, you can only use 4 colors without passing the `colors` prop.
If you need more colors, you should pass them manually to the component:
```python
dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
colors=[
'var(--heatmap-level-1)',
'var(--heatmap-level-2)',
'var(--heatmap-level-3)',
'var(--heatmap-level-4)',
'var(--heatmap-level-5)',
'var(--heatmap-level-6)',
]
)
```
### Values domain
By default, `Heatmap` calculates domain based on data values, for example, for
the following data, the domain will be `[1, 4]`:
```python
data = {
'2025-02-14': 2,
'2025-02-11': 3,
'2025-02-06': 4,
'2025-02-05': 1,
}
```
Based on the domain, `Heatmap` calculates colors for each rect: 1 (min heat level),
4 (max heat level). To specify the domain manually, use the `domain` prop. It is useful
when your data does not cover the whole range of possible values. For example,
the subset of data passed to the heatmap has values from 1 to 4, but the actual
range is from 1 to 10. In this case, you can pass `[1, 10]` to the `domain` prop:
```python
data = {
'2025-02-14': 2,
'2025-02-11': 3,
'2025-02-06': 4,
'2025-02-05': 1,
}
dmc.Heatmap(data=data, domain=[1, 10])
```
### Weekdays and months labels
Set `withMonthLabels=True` and `withWeekdayLabels=True` to display chart labels:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
withWeekdayLabels=True,
withMonthLabels=True,
)
```
### Month labels position
Set monthLabelsPosition="bottom" to display month labels below the heatmap:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
withWeekdayLabels=True,
withMonthLabels=True,
monthLabelsPosition="bottom"
)
```
### Change labels text
To change labels, use the `weekdayLabels` and `monthLabels` props.
The `weekdayLabels` prop must be an array of 7 strings with weekday names starting from Sunday.
The `monthLabels` prop must be an array of 12 strings with month names starting from January.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
withWeekdayLabels=True,
withMonthLabels=True,
weekdayLabels=["Dim", "Lun", "", "Mer", "", "Ven", ""],
monthLabels=[
"Jan",
"Fév",
"Mar",
"Avr",
"Mai",
"Jun",
"Jul",
"Aoû",
"Sep",
"Oct",
"Nov",
"Déc",
]
)
```
### Rect size, gap and radius
### hoverData and clickData
```python
from dash import Input, Output, callback
import dash_mantine_components as dmc
from .data import data
component = dmc.Box([
dmc.Heatmap(
id="heatmap-chart",
data=data,
startDate="2024-02-16",
endDate="2025-02-16"
),
dmc.Text(id="heatmap-clickdata"),
dmc.Text(id="heatmap-hoverdata")
])
@callback(
Output("heatmap-clickdata", "children"),
Input("heatmap-chart", "clickData")
)
def update_clickdata(clickData):
return f"You clicked on: {clickData}"
@callback(
Output("heatmap-hoverdata", "children"),
Input("heatmap-chart", "hoverData")
)
def update_hoverdata(hoverData):
return f"You hovered over: {hoverData}"
```
### Hide outside dates
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2024-04-16",
withWeekdayLabels=True,
withMonthLabels=True,
withOutsideDates=False
)
```
### First day of week
The default first day of the week is Monday; you can change it with the `firstDayOfWeek` prop:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2024-04-26",
withWeekdayLabels=True,
withMonthLabels=True,
firstDayOfWeek=0,
weekdayLabels=['', 'Mon', '', 'Wed', '', 'Fri', '']
)
```
### Split months
Use `splitMonths` to separate months visually with a spacer column and show only days that belong to the current month in each column. Month labels will be shifted by one column when `splitMonths` is enabled and months with fewer than 2 weeks are not labeled.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-26",
withMonthLabels=True,
splitMonths=True
)
```
### Legend
Set `withLegend=True` to display a color legend below the heatmap. Use `legendLabels` prop to customize the labels
(default: `['Less', 'More']`):
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Heatmap(
data=data,
startDate="2024-02-16",
endDate="2025-02-16",
withWeekdayLabels=True,
withMonthLabels=True,
withLegend=True,
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Heatmap selectors
| Selector | Static selector | Description |
|----------|----------------|-------------|
| root | .mantine-Heatmap-root | Root element |
| weekdayLabel | .mantine-Heatmap-weekdayLabel | Weekday text element |
| monthLabel | .mantine-Heatmap-monthLabel | Month text element |
| rect | .mantine-Heatmap-rect | Rect that represents date |
| legend | .mantine-Heatmap-legend | Legend group element |
| legendLabel | .mantine-Heatmap-legendLabel | Legend text label (Less/More) |
| legendRect | .mantine-Heatmap-legendRect | Legend color rect |
### Keyword Arguments
#### Heatmap
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type number; optional):
Clicked heatmap cell data containing date and value.
- colors (list of strings; optional):
Colors array, used to calculate color for each value, by default 4
shades of green colors are used.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (dict with strings as keys and values of type number; required):
Heatmap data, key is date in `YYYY-MM-DD` format (interpreted as a
UTC calendar day).
- data-* (string; optional):
Wild card data attributes.
- domain (list of 2 elements: [number, number]; optional):
Heatmap domain, array of 2 numbers, min and max values, calculated
from data by default.
- endDate (string; optional):
Heatmap end date. Current date by default. Date is normalized to
UTC midnight of the intended calendar day.
- firstDayOfWeek (a value equal to: 0, 2, 1, 3, 4, 5, 6; optional):
First day of week, 0 – Sunday, 1 – Monday. Default 1 – Monday.
- fontSize (number; optional):
Font size of month and weekday labels. Default 12.
- gap (number; optional):
Gap between rects in px. Default 1.
- getTooltipLabel (boolean | number | string | dict | list; optional):
A function to generate tooltip label based on the hovered rect
date and value, required for the tooltip to be visible.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hoverData (dict with strings as keys and values of type number; optional):
Hovered heatmap cell data containing date and value.
- legendLabels (list of 2 elements: [string, string]; optional):
Legend labels, array of 2 elements: [min label, max label] default
['Less', 'More'].
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- monthLabels (list of strings; optional):
Month labels, array of 12 elements, can be used for localization.
- monthLabelsPosition (a value equal to: 'top', 'bottom'; optional):
Month labels position relative to the heatmap default 'top'.
- monthsLabelsHeight (number; optional):
Height of month labels row. Default 30.
- rectRadius (number; optional):
Rect radius in px. Default 2.
- rectSize (number; optional):
Size of day rect in px. Default 10.
- splitMonths (boolean; optional):
If set, inserts a spacer column between months. Default False.
- startDate (string; optional):
Heatmap start date. Current date - 1 year by default. Date is
normalized to UTC midnight of the intended calendar day.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- tooltipProps (boolean | number | string | dict | list; optional):
Props passed down to the `Tooltip.Floating` component.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- weekdayLabels (list of strings; optional):
Weekday labels, array of 7 elements, can be used for localization.
- weekdaysLabelsWidth (number; optional):
Width of weekday labels column. Default 30.
- withLegend (boolean; optional):
If set, legend with color levels is displayed below the heatmap
default False.
- withMonthLabels (boolean; optional):
If set, month labels are displayed. Default False.
- withOutsideDates (boolean; optional):
If set, trailing dates that do not fall into the given `startDate`
– `endDate` range are displayed to fill empty space. Default True.
- withTooltip (boolean; optional):
If set, tooltip is displayed on rect hover. Default False.
- withWeekdayLabels (boolean; optional):
If set, weekday labels are displayed. Ddefault False.
## LineChart
Line chart component
Category: Charts
### Introduction
```python
import dash_mantine_components as dmc
from .data import data
dmc.LineChart(
h=300,
dataKey="date",
data=data,
series = [
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"}
],
curveType="linear",
tickLine="xy",
withXAxis=False,
withDots=False,
)
```
### Data
Here is the data imported for the examples on this page:
```python
data = [
{"date": "Mar 22", "Apples": 2890, "Oranges": 2338, "Tomatoes": 2452},
{"date": "Mar 23", "Apples": 2756, "Oranges": 2103, "Tomatoes": 2402},
{"date": "Mar 24", "Apples": 3322, "Oranges": 986, "Tomatoes": 1821},
{"date": "Mar 25", "Apples": 3470, "Oranges": 2108, "Tomatoes": 2809},
{"date": "Mar 26", "Apples": 3129, "Oranges": 1726, "Tomatoes": 2290}
]
```
### Gradient type
Set `type="gradient"` to render a line chart with gradient fill. To customize gradient colors, use `gradientStops` prop.
It accepts an array of objects with `offset` and `color` properties. `offset` is a number between 0 and 100 that defines
the position of the color in the gradient, `color` is a reference to `theme.colors` or any valid CSS color.
```python
import dash_mantine_components as dmc
data = [
{"date": "Jan", "temperature": -25},
{"date": "Feb", "temperature": -10},
{"date": "Mar", "temperature": 5},
{"date": "Apr", "temperature": 15},
{"date": "May", "temperature": 30},
{"date": "Jun", "temperature": 15},
{"date": "Jul", "temperature": 30},
{"date": "Aug", "temperature": 40},
{"date": "Sep", "temperature": 15},
{"date": "Oct", "temperature": 20},
{"date": "Nov", "temperature": 0},
{"date": "Dec", "temperature": -10},
]
component = dmc.LineChart(
h=300,
data=data,
series=[{"name": "temperature", "label": "Avg. Temperature"}],
dataKey="date",
type="gradient",
valueFormatter={"function": "celsiusLabel"},
gradientStops=[
{"offset": 0, "color": "red.6"},
{"offset": 20, "color": "orange.6"},
{"offset": 40, "color": "yellow.5"},
{"offset": 70, "color": "lime.5"},
{"offset": 80, "color": "cyan.5"},
{"offset": 100, "color": "blue.5"},
],
strokeWidth=5,
curveType="natural",
yAxisProps={"domain": [-25, 40]},
p="lg"
)
```
### Value formatter
To format values in the tooltip and axis ticks, use `valueFormatter` prop. It accepts a function that takes number `value`
as an argument and returns formatted value:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
valueFormatter={"function": "formatNumberIntl"},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatNumberIntl = (value) => {
return new Intl.NumberFormat('en-US').format(value);
};
```
### Legend
To display chart legend, set `withLegend` prop. When one of the items in the legend is hovered, the corresponding data
series is highlighted in the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
withLegend=True,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Legend position
You can pass props down to recharts Legend component with `legendProps` prop. For example, setting the following will
render the legend at the bottom of the chart and set its height to 50px:
```python
legendProps={'verticalAlign': 'bottom', 'height': 50}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
withLegend=True,
legendProps={"verticalAlign": "bottom", "height": 50},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Series labels
By default, series `name` is used as a label. To change it, set `label` property in `series` object:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
withLegend=True,
legendProps={"verticalAlign": "bottom"},
series=[
{"name": "Apples", "label": "Apples sales", "color": "indigo.6"},
{"name": "Oranges", "label": "Oranges sales", "color": "blue.6"},
{"name": "Tomatoes", "label": "Tomatoes sales", "color": "teal.6"},
],
)
```
### Connect nulls
Use `connectNulls` prop to specify whether to connect a data point across null points. By default, `connectNulls` is true.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 110},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": -80},
{"date": "Mar 25", "Apples": 40},
{"date": "Mar 26", "Apples": None},
{"date": "Mar 27", "Apples": 80}
]
dmc.LineChart(
h=300,
dataKey="date",
data=data,
connectNulls=True,
series=[{"name": "Apples", "color": "indigo.6"}],
curveType="linear",
)
```
### X and Y axis props
Use `xAxisProps` and `yAxisProps` to pass props down to recharts `XAxis` and `YAxis` components. For example, these props can
be used to change orientation of axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
tickLine="xy",
yAxisProps={"tickMargin": 15, "orientation": "right"},
xAxisProps={"tickMargin": 15, "orientation": "top"},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Axis labels
Use `xAxisLabel` and `yAxisLabel` props to display axis labels:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
xAxisLabel="Date",
yAxisLabel="Amount",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### X axis offset
Use xAxisProps to set padding between the charts ends and the x-axis:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
xAxisProps={"padding": {"left": 30, "right": 30}},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Y axis scale
Use `yAxisProps` to change domain of the Y axis. For example, if you know that your data will always be in the range
of 0 to 100, you can set domain to `[0, 100]`:
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 50},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": 40},
{"date": "Mar 25", "Apples": 30},
{"date": "Mar 26", "Apples": 0},
{"date": "Mar 27", "Apples": 20},
{"date": "Mar 28", "Apples": 20},
{"date": "Mar 29", "Apples": 10},
]
component = dmc.LineChart(
h=300,
dataKey="date",
yAxisProps={"domain": [0, 100]},
data=data,
connectNulls=True,
series=[{"name": "Apples", "color": "indigo.6"}],
)
```
### Right Y axis
To display additional Y axis on the right side of the chart, set `withRightYAxis` prop. You can pass props down to
recharts `YAxis` component with `rightYAxisProps` prop and assign a label to the right Y axis with `rightYAxisLabel` prop.
Note that you need to bind data series to the right Y axis by setting `yAxisId` in the series object.
```python
import dash_mantine_components as dmc
data = biaxial_data = [
{"name": "Page A", "uv": 4000, "pv": 2400},
{"name": "Page B", "uv": 3000, "pv": 1398},
{"name": "Page C", "uv": 2000, "pv": 9800},
{"name": "Page D", "uv": 2780, "pv": 3908},
{"name": "Page E", "uv": 1890, "pv": 4800},
{"name": "Page F", "uv": 2390, "pv": 3800},
{"name": "Page G", "uv": 3490, "pv": 4300},
]
component = dmc.LineChart(
h=300,
data=data,
dataKey="name",
withRightYAxis=True,
yAxisLabel="uv",
rightYAxisLabel="pv",
series=[
{"name": "uv", "color": "pink.6"},
{"name": "pv", "color": "cyan.6", "yAxisId": "right"},
],
)
```
### Rotate x-axis labels
To rotate x-axis labels, set `xAxisProps.angle` to a number of degrees to rotate:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
tickLine="xy",
xAxisProps={"angle": -20},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Line color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc.
Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
series=[{"name": "Apples", "color": "orange.7"}],
)
```
### Change line color depending on color scheme
You can use CSS variables in color property. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
Example of line color that is dark orange in light mode and lime in dark mode:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
series=[{"name": "Apples", "color": "var(--chart-color)"}],
)
```
```css
:root {
--chart-color: var(--mantine-color-orange-8)
}
:root[data-mantine-color-scheme="dark"] {
--chart-color: var(--mantine-color-lime-4);
}
```
### Stroke dash array
Set `strokeDasharray` prop to control the stroke dash array of the grid and cursor lines. The value represent the
lengths of alternating dashes and gaps. For example, strokeDasharray="10 5" will render a dashed line with 10px dashes
and 5px gaps.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
strokeDasharray="15 15",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Grid and text colors
Use `--chart-grid-color` and `--chart-text-color` to change colors of grid lines and text within the chart.
With CSS , you can change colors depending on color scheme. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
className="chart-grid-text-colors",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
```css
.chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-5);
--chart-text-color: var(--mantine-color-blue-8);
}
[data-mantine-color-scheme='dark'] .chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-3);
--chart-text-color: var(--mantine-color-blue-2);
}
```
If your application has only one color scheme, you can use `gridColor` and `textColor` props instead of CSS variables:
```python
dmc.LineChart(
h=300,
dataKey="date",
data=data,
gridColor="gray.5",
textColor = "gray.9",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Tooltip animation
By default, tooltip animation is disabled. To enable it, set `tooltipAnimationDuration` prop to a number of
milliseconds to animate the tooltip position change.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
tooltipAnimationDuration=200,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Line animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `lineProps` to pass properties to the Recharts `Line` component.
```python
from random import randint
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-linechart-animation"),
dmc.LineChart(
id="linechart-animation",
h=300,
dataKey="date",
data=[{}],
tooltipAnimationDuration=500,
lineProps={
"isAnimationActive": True,
"animationDuration": 500,
"animationEasing": "ease-in-out",
"animationBegin": 500,
},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
),
]
)
@callback(
Output("linechart-animation", "data"), Input("btn-linechart-animation", "n_clicks")
)
def update(n):
return [
{
"date": "Mar 22",
"Apples": 2890,
"Oranges": 2338,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 23",
"Apples": 2756,
"Oranges": 2103,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 24",
"Apples": 3322,
"Oranges": 986,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 25",
"Apples": 3470,
"Oranges": 2108,
"Tomatoes": randint(1000, 4000),
},
{
"date": "Mar 26",
"Apples": 3129,
"Oranges": 1726,
"Tomatoes": randint(1000, 4000),
},
]
```
### Units
Set `unit` prop to render a unit label next to the y-axis ticks and tooltip values:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
unit="$",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Remove tooltip
To remove tooltip, set `withTooltip=False`. It also removes the cursor line and disables interactions with the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
withTooltip=False,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Custom tooltip
Use the `tooltipProps` `content` prop to to pass custom tooltip renderer to recharts Tooltip component. For example:
```python
tooltipProps={'content': {'functon': 'myFunction'}}
```
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
tooltipProps={"content": {"function": "chartTooltip"}}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.chartTooltip = ({ label, payload }) => {
if (!payload || payload.length === 0) return null;
return React.createElement(
dmc.Paper,
{
px: "md",
py: "sm",
withBorder: true,
shadow: "md",
radius: "md",
},
[
React.createElement(
dmc.Text,
{
key: "tooltip-label",
fw: 500,
mb: 5,
},
label
),
...payload.map((item, index) =>
React.createElement(
dmc.Text,
{
key: `item-${index}`,
c: item.color,
fz: "sm",
},
`${item.name}: ${item.value}`
)
),
]
);
};
```
### Customize dots
Use `dotProps` to pass props down to recharts dot in regular state and `activeDotProps` to pass props down to recharts dot in active state (when cursor is over the current series).
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
dotProps={"r": 6, "strokeWidth": 2, "stroke": "#fff"},
activeDotProps={"r": 8, "strokeWidth": 1, "fill": "#fff"},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Stroke width
Use `strokeWidth` prop to control the stroke width of all areas:
```python
import dash_mantine_components as dmc
from .data import data
dmc.LineChart(
h=300,
dataKey="date",
data=data,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"}
],
strokeWidth=2,
)
```
### Sync multiple LineCharts
You can pass props down to recharts LineChart component with `lineChartProps` prop. For example, setting the following
will sync tooltip of multiple `LineChart` components with the same `syncId` prop.
```python
lineChartProps={"syncId": "any-id"}
```
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.Text("Apples sales:"),
dmc.LineChart(
h=180,
dataKey="date",
data=data,
series=[{"name": "Apples", "color": "indigo.6"}],
lineChartProps={"syncId": "groceries"},
),
dmc.Text("Tomatoes sales"),
dmc.LineChart(
h=180,
dataKey="date",
data=data,
series=[{"name": "Tomatoes", "color": "teal.6"}],
lineChartProps={"syncId": "groceries"},
),
]
)
```
### Vertical orientation
Set orientation="vertical" to render a vertical area chart:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
orientation="vertical",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
)
```
### Dashed area line
Set `strokeDasharray` property in series to change line style to dashed:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
strokeWidth=1,
dotProps={"r": 2},
activeDotProps={"r": 3, "strokeWidth": 1},
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6", "strokeDasharray": "5 5"},
],
)
```
### Reference lines
Use `referenceLines` prop to render reference lines. Reference lines are always rendered behind the chart.
```python
import dash_mantine_components as dmc
data = [
{"date": "Mar 22", "Apples": 50},
{"date": "Mar 23", "Apples": 60},
{"date": "Mar 24", "Apples": 40},
{"date": "Mar 25", "Apples": 30},
{"date": "Mar 26", "Apples": 0},
{"date": "Mar 27", "Apples": 20},
{"date": "Mar 28", "Apples": 20},
{"date": "Mar 29", "Apples": 10},
]
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
yAxisProps={"domain": [0, 100]},
referenceLines=[
{"y": 40, "label": "Average sales", "color": "red.6"},
{"x": "Mar 25", "label": "Report out"},
],
series=[{"name": "Apples", "color": "indigo.6"}],
)
```
### Reference areas
Use the `referenceAreas` prop to highlight a rectangular region of the chart. Each area is bounded by x1/x2 (horizontal)
and y1/y2 (vertical) data values – omit one pair to span the full opposite axis, for example provide only x1/x2 to
highlight a time range across the entire height of the chart. Set `color` to any theme color or CSS color and label
to display text inside the area. Reference areas are rendered behind the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
data=data,
dataKey="date",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
referenceAreas=[
{"y1": 2000, "y2": 3000, "color": "teal.6", "label": "Target range"},
],
)
```
### Reference dots
Use the `referenceDots` prop to mark individual points on the chart – a peak, an event, a record value or an anomaly.
Each dot is positioned by x and y data coordinates and supports `r` (radius), `color` (any theme color or CSS color) and
`label`. Reference dots are rendered on top of the chart series.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
data=data,
dataKey="date",
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
referenceDots=[
{"x": "Mar 25", "y": 3470, "color": "indigo.6", "label": "Peak"},
{"x": "Mar 24", "y": 986, "color": "red.6", "label": "Low"},
],
)
```
### Brush (Range Slider)
Set the `withBrush` prop to display a brush (range slider) under the chart. Drag the brush handles to
zoom into a subset of the data. The chart updates to show only the selected range. The brush border and background are
themed to match the chart grid and adapt to the color scheme. `withBrush` is `False` by default and is supported by
`AreaChart`, `BarChart`, `LineChart` and `CompositeChart` components with `horizontal` orientation.
Use the `brushDragEnd` prop to get the `startIndex` and `endIndex` of the selected range when dragging ends.
Use the `brushProps` prop to pass props down to the underlying [recharts Brush](https://recharts.github.io/en-US/api/Brush/) component. For example, you can set the
initially selected range with `startIndex`/`endIndex`, change the brush height and more.
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
from .data import data2
component = dmc.Stack([
dmc.LineChart(
h=300,
data=data2,
dataKey="month",
withBrush=True,
series=[
{"name": "Smartphones", "color": "violet.6"},
{"name": "Laptops", "color": "blue.6"},
],
id="linechart-brush",
),
dmc.Text(id="linechart-brush-dragend"),
])
@callback(
Output("linechart-brush-dragend", "children"),
Input("linechart-brush", "brushDragEnd"),
)
def update_brush_range(brush_drag_end):
return f"Brush range selected: {brush_drag_end}"
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event.
To get the name of the clicked series, use the `clickSeriesName` property.
Note: To enable `clickSeriesName` when clicking on the dots, set `withTooltip=True`.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.LineChart(
id="figure-linechart",
h=300,
dataKey="date",
data=data,
withLegend=True,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
activeDotProps={"r": 8, "strokeWidth": 1, "fill": "#fff"},
strokeWidth=4
),
dmc.Text(id="clickdata-linechart1"),
dmc.Text(id="clickdata-linechart2"),
]
)
@callback(
Output("clickdata-linechart1", "children"),
Output("clickdata-linechart2", "children"),
Input("figure-linechart", "clickData"),
Input("figure-linechart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event.
To get the name of the hovered series, use the `hoverSeriesName` property.
Note: To enable `hoverSeriesName` when hovering on the dots, set `withTooltip=True`.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
import dash_mantine_components as dmc
from .data import data
component = dmc.Group(
[
dmc.LineChart(
id="figure-linechart-hover",
h=300,
dataKey="date",
data=data,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
activeDotProps={"r": 8, "strokeWidth": 1, "fill": "#fff"},
strokeWidth=4
),
dmc.Text(id="hoverdata-linechart1"),
dmc.Text(id="hoverdata-linechart2"),
]
)
@callback(
Output("hoverdata-linechart1", "children"),
Output("hoverdata-linechart2", "children"),
Input("figure-linechart-hover", "hoverData"),
Input("figure-linechart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### highlightHover
Set `highlightHover=True` to highlight the series when hovered, mirroring the behavior of hovering over chart legend items.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.LineChart(
h=300,
dataKey="date",
data=data,
series=[
{"name": "Apples", "color": "indigo.6"},
{"name": "Oranges", "color": "blue.6"},
{"name": "Tomatoes", "color": "teal.6"},
],
withLegend=True,
highlightHover=True,
withTooltip=False,
strokeWidth=4
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### LineChart selectors
| Selector | Static selector | Description |
|:-----------------|:----------------------------------|:-------------------------------------------------|
| root | .mantine-LineChart-root | Root element |
| line | .mantine-LineChart-line | Line of the chart |
| axis | .mantine-LineChart-axis | X and Y axis of the chart |
| container | .mantine-LineChart-container | Recharts ResponsiveContainer component |
| grid | .mantine-LineChart-grid | Recharts CartesianGrid component |
| legend | .mantine-LineChart-legend | Legend root element |
| legendItem | .mantine-LineChart-legendItem | Legend item representing data series |
| legendItemColor | .mantine-LineChart-legendItemColor| Legend item color |
| legendItemName | .mantine-LineChart-legendItemName | Legend item name |
| tooltip | .mantine-LineChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-LineChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-LineChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-LineChart-tooltipItemBody| Tooltip item wrapper around item color and name|
| tooltipItemColor | .mantine-LineChart-tooltipItemColor| Tooltip item color |
| tooltipItemName | .mantine-LineChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-LineChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-LineChart-tooltipLabel | Label of the tooltip |
| referenceLine | .mantine-LineChart-referenceLine | Reference line |
| axisLabel | .mantine-LineChart-axisLabel | X and Y axis labels |
#### LineChart CSS variables
| Selector | Variable | Description |
|:-----------------|:---------------------|:-------------------------------------------------|
| root | --chart-grid-color | Controls color of the grid and cursor lines |
| | --chart-text-color | Controls color of the axis labels |
### Keyword Arguments
#### LineChart
- children (a list of or a singular dash component, string or number; optional):
Additional components that are rendered inside recharts
`AreaChart` component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- activeDotProps (boolean | number | string | dict | list; optional):
Props passed down to all active dots. Ignored if
`withDots={False}` is set.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- brushDragEnd (dict with strings as keys and values of type number; optional):
The startIndex and endIndex of the selected brush range when
dragging ends. Read only.
- brushProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Brush` component.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- connectNulls (boolean; optional):
Determines whether points with `None` values should be connected,
`True` by default.
- curveType (a value equal to: 'bump', 'linear', 'natural', 'monotone', 'step', 'stepBefore', 'stepAfter'; optional):
Type of the curve, `'monotone'` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts with strings as keys and values of type boolean | number | string | dict | list; required):
Data used to display chart.
- data-* (string; optional):
Wild card data attributes.
- dataKey (string; required):
Key of the `data` object for x-axis values.
- dotProps (boolean | number | string | dict | list; optional):
Props passed down to all dots. Ignored if `withDots={False}` is
set.
- fillOpacity (number; optional):
Controls fill opacity of all lines, `1` by default.
- gradientStops (list of dicts; optional):
Data used to generate gradient stops, [{ offset: 0, color: 'red'
}, { offset: 100, color: 'blue' }] by default.
`gradientStops` is a list of dicts with keys:
- gridAxis (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which lines should be displayed in the grid, `'x'` by
default.
- gridColor (optional):
Color of the grid and cursor lines, by default depends on color
scheme.
- gridProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `CartesianGrid` component.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- highlightHover (boolean; optional):
Determines whether a hovered series is highlighted. False by
default. Mirrors the behaviour when hovering about chart legend
items.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- legendProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- lineChartProps (boolean | number | string | dict | list; optional):
Props passed down to recharts `LineChart` component.
- lineProps (boolean | number | string | dict | list; optional):
Props passed down to recharts `Line` component.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Chart orientation, `'horizontal'` by default.
- referenceAreas (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference areas that should be displayed on the chart.
- referenceDots (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference dots that should be displayed on the chart.
- referenceLines (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference lines that should be displayed on the chart.
- rightYAxisLabel (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- rightYAxisProps (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- series (list of dicts; required):
An array of objects with `name` and `color` keys. Determines which
data should be consumed from the `data` array.
`series` is a list of dicts with keys:
- strokeDasharray (string | number; optional):
Dash array for the grid lines and cursor, `'5 5'` by default.
- strokeWidth (number; optional):
Stroke width for the chart lines, `2` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Color of the text displayed inside the chart, `'dimmed'` by
default.
- tickLine (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which axis should have tick line, `'y'` by default.
- tooltipAnimationDuration (number; optional):
Tooltip position animation duration in ms, `0` by default.
- tooltipProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Tooltip` component.
- type (a value equal to: 'default', 'gradient'; optional):
Controls styles of the line 'default' | 'gradient'. 'default' by
default.
- unit (string; optional):
Unit displayed next to each tick in y-axis.
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values on Y axis and inside the tooltip. See
https://www.dash-mantine-components.com/functions-as-props.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBrush (boolean; optional):
Determines whether a brush (range selector) should be displayed
under the chart, `False` by default.
- withDots (boolean; optional):
Determines whether dots should be displayed, `True` by default.
- withLegend (boolean; optional):
Determines whether chart legend should be displayed, `False` by
default.
- withPointLabels (boolean; optional):
Determines whether each point should have associated label, False
by default.
- withRightYAxis (boolean; optional):
Determines whether additional y-axis should be displayed on the
right side of the chart, False by default.
- withTooltip (boolean; optional):
Determines whether chart tooltip should be displayed, `True` by
default.
- withXAxis (boolean; optional):
Determines whether x-axis should be hidden, `True` by default.
- withYAxis (boolean; optional):
Determines whether y-axis should be hidden, `True` by default.
- xAxisLabel (string; optional):
A label to display below the x-axis.
- xAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `XAxis` recharts component.
- yAxisLabel (string; optional):
A label to display next to the y-axis.
- yAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `YAxis` recharts component.
## PieChart
Pie chart component
Category: Charts
### Introduction
PieChart is based on [PieChart recharts](https://recharts.org/en-US/api/PieChart) component:
### Usage
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.PieChart(data=data)
```
### Data
Here is the data imported for the examples on this page:
```python
data = [
{ "name": "USA", "value": 400, "color": "indigo.6" },
{ "name": "India", "value": 300, "color": "yellow.6" },
{ "name": "Japan", "value": 100, "color": "teal.6" },
{ "name": "Other", "value": 200, "color": "gray.6" }
]
```
### Legend
To display the legend, set the `withLegend` prop. The legend displays the name and color of each segment. Hover over
a legend item to highlight the corresponding segment.
You can pass props down to the recharts Legend component with the `legendProps` prop. For example, set
`legendProps={"verticalAlign": 'top'}` to display the legend above the chart.
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.PieChart(data=data, withLegend=True)
```
### Segment labels
Set `withLabels` prop to display labels next to each segment. Use `labelPosition` prop to control the position of labels
relative to the corresponding segment. Note that if your chart has a lot of segments and labelPosition="inside" is
set, labels might overlap. In this case, use labelPosition="outside".
```python
import dash_mantine_components as dmc
from .data import data
dmc.PieChart(
data=data,
withLabelsLine=True,
labelsPosition="inside",
labelsType="percent",
withLabels=True,
)
```
### Size
Set `size` prop to control width and height of the chart. Note that if `withLabels` and labelPosition="outside" prop
are set, the chart height is automatically increased by 80px to make room for labels. You can override this behavior
by setting `h` and `w` style prop.
```python
import dash_mantine_components as dmc
from .data import data
dmc.PieChart(
data=data,
size=275
)
```
### Segment color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc.
Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
data = [
{"name": "USA", "value": 400, "color": "blue"},
{"name": "Other", "value": 200, "color": "gray.6"},
]
component = dmc.PieChart(data=data)
```
### Enable Tooltip
To enable the tooltip, set `withTooltip` prop:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.PieChart(data=data, withTooltip=True)
```
### Tooltip data source
By default, the tooltip displays data for all segments when hovered over any segment. To display data only for the hovered segment, set tooltipDataSource="segment":
```python
import dash_mantine_components as dmc
from dash import html
from .data import data
component = dmc.Group(
[
html.Div(
[
dmc.Text(
"Data only for hovered segment", fz="xs", mb="sm", ta="center"
),
dmc.PieChart(
data=data,
withTooltip=True,
tooltipDataSource="segment",
mx="auto",
),
]
),
html.Div(
[
dmc.Text("Data only for all segments", fz="xs", mb="sm", ta="center"),
dmc.PieChart(
data=data,
withTooltip=True,
mx="auto",
),
]
),
],
gap=50,
)
```
### Start and end angle
Use `startAngle` and `endAngle` props to control the start and end angle of the chart. For example, to display a
half-circle chart, set `startAngle=180` and `endAngle=0`:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.PieChart(data=data, startAngle=180, endAngle=0)
```
### Segments stroke
Use `strokeWidth` prop to control the width of the stroke around each segment.
```python
import dash_mantine_components as dmc
from .data import data
dmc.PieChart(
data=data,
strokeWidth=1
)
```
To change color of the stroke, use `strokeColor` prop. You can reference colors from theme the same way as in other
components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS color value is also accepted.
```python
dmc.PieChart(
data=data,
strokeWidth=1.8,
strokeColor="red.5"
)
```
By default, segments stroke color is the same as the background color of the body element
(`--mantine-color-body` CSS variable). If you want to change it depending on the color scheme, define CSS variable
and pass it to the `strokeColor` prop:
```python
import dash_mantine_components as dmc
from .data import data
component = dmc.PieChart(data=data, strokeColor="var(--card-bg)")
```
```css
.root {
--card-bg: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-5));
background-color: var(--card-bg);
padding: var(--mantine-spacing-md);
border-radius: var(--mantine-radius-md);
}
```
### Pie animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `pieProps` to pass properties to the Recharts `Pie` component.
```python
from random import randint
import dash_mantine_components as dmc
from dash import callback, Input, Output
def get_data(values):
return [
{"name": "A", "value": values[0], "color": "indigo.6"},
{"name": "B", "value": values[1], "color": "yellow.6"},
{"name": "C", "value": values[2], "color": "teal.6"},
{"name": "C", "value": values[3], "color": "gray.6"},
]
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-piechart-animation", n_clicks=0, mb="md"),
dmc.PieChart(
id="piechart-animation",
data=get_data([100, 0, 0, 0]),
pieProps={"isAnimationActive": True},
),
]
)
@callback(
Output("piechart-animation", "data"), Input("btn-piechart-animation", "n_clicks")
)
def update(n):
if n % 2 == 0:
return get_data([400, 300, 600, 100])
return get_data([100, 0, 0, 0])
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event. To get the name of the
clicked series, use the `clickSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.PieChart(
id="figure-piechart",
data=data,
),
dmc.Text(id="clickdata-piechart1"),
dmc.Text(id="clickdata-piechart2"),
]
)
@callback(
Output("clickdata-piechart1", "children"),
Output("clickdata-piechart2", "children"),
Input("figure-piechart", "clickData"),
Input("figure-piechart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event. To get the name of the
hovered series, use the `hoverSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data
component = dmc.Stack(
[
dmc.PieChart(
id="figure-piechart-hover",
data=data,
),
dmc.Text(id="hoverdata-piechart1"),
dmc.Text(id="hoverdata-piechart2"),
]
)
@callback(
Output("hoverdata-piechart1", "children"),
Output("hoverdata-piechart2", "children"),
Input("figure-piechart-hover", "hoverData"),
Input("figure-piechart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### PieChart selectors
| Selector | Static selector | Description |
|:------------|:--------------------------|:----------------------------------------|
| root | .mantine-PieChart-root | Root element |
#### PieChart CSS variables
| Selector | Variable | Description |
|:-----------------|:-----------------------|:-----------------------------------------|
| root | --chart-labels-color | Controls color of the chart labels |
| | --chart-size | Controls size of the chart |
| | --chart-stroke-color | Controls color of the chart stroke |
### Keyword Arguments
#### PieChart
- children (a list of or a singular dash component, string or number; optional):
Additional elements rendered inside `PieChart` component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts; required):
Data used to render chart.
`data` is a list of dicts with keys:
- data-* (string; optional):
Wild card data attributes.
- endAngle (number; optional):
Controls angle at which charts ends, `360` by default. Set to `0`
to render the chart as semicircle.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- labelColor (optional):
Controls text color of all labels, white by default.
- labelsPosition (a value equal to: 'inside', 'outside'; optional):
Controls labels position relative to the segment, `'outside'` by
default.
- labelsType (a value equal to: 'percent', 'value', 'name'; optional):
Type of labels to display, `'value'` by default.
- legendProps (dict; optional):
Props passed down to recharts `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- paddingAngle (number; optional):
Controls padding between segments, `0` by default.
- pieChartProps (dict; optional):
Props passed down to recharts `PieChart` component.
- pieProps (boolean | number | string | dict | list; optional):
Props passed down to recharts `Pie` component.
- size (number; optional):
Controls chart width and height, height is increased by 40 if
`withLabels` prop is set. Cannot be less than `thickness`. `80` by
default.
- startAngle (number; optional):
Controls angle at which chart starts, `0` by default. Set to `180`
to render the chart as semicircle.
- strokeColor (optional):
Controls color of the segments stroke, by default depends on color
scheme.
- strokeWidth (number; optional):
Controls width of segments stroke, `1` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- tooltipAnimationDuration (number; optional):
Tooltip animation duration in ms, `0` by default.
- tooltipDataSource (a value equal to: 'segment', 'all'; optional):
Determines which data is displayed in the tooltip. `'all'` –
display all values, `'segment'` – display only hovered segment.
`'all'` by default.
- tooltipProps (boolean | number | string | dict | list; optional):
Props passed down to `Tooltip` recharts component.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withLabels (boolean; optional):
Determines whether each segment should have associated label,
`False` by default.
- withLabelsLine (boolean; optional):
Determines whether segments labels should have lines that connect
the segment with the label, `True` by default.
- withLegend (boolean; optional):
Determines whether the legend should be displayed default False.
- withTooltip (boolean; optional):
Determines whether the tooltip should be displayed when one of the
section is hovered, `True` by default.
## RadarChart
Radar chart component
Category: Charts
### Usage
RadarChart is based on recharts [RadarChart](https://recharts.org/en-US/api/RadarChart) component:
```python
import dash_mantine_components as dmc
data = [
{"product": "Apples", "sales": 120},
{"product": "Oranges", "sales": 98},
{"product": "Tomatoes", "sales": 86},
{"product": "Grapes", "sales": 99},
{"product": "Bananas", "sales": 85},
{"product": "Lemons", "sales": 65},
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
withPolarRadiusAxis=True,
series=[{"name": "sales", "color": "blue.4", "opacity": 0.2}],
)
```
### Multiple series
You can display multiple series on the same radar chart:
```python
import dash_mantine_components as dmc
data = [
{"product": "Apples", "sales_january": 120, "sales_february": 100},
{"product": "Oranges", "sales_january": 98, "sales_february": 90},
{"product": "Tomatoes", "sales_january": 86, "sales_february": 70},
{"product": "Grapes", "sales_january": 99, "sales_february": 80},
{"product": "Bananas", "sales_january": 85, "sales_february": 120},
{"product": "Lemons", "sales_january": 65, "sales_february": 150},
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
withPolarRadiusAxis=True,
series=[
{"name": "sales_january", "color": "lime.4", "opacity": 0.1},
{"name": "sales_february", "color": "cyan.4", "opacity": 0.1},
],
)
```
### Change Color
You can reference colors from theme the same way as in other components, for example, `blue`, `red.5`, `orange.7`, etc. Any valid CSS color value is also accepted.
```python
import dash_mantine_components as dmc
data = [
{"product": "Apples", "sales": 120},
{"product": "Oranges", "sales": 98},
{"product": "Tomatoes", "sales": 86},
{"product": "Grapes", "sales": 99},
{"product": "Bananas", "sales": 85},
{"product": "Lemons", "sales": 65},
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
series=[{"name": "sales", "color": "green", "strokeColor": "blue"}],
)
```
### Hide/show chart parts
```python
import dash_mantine_components as dmc
data = [
{"product": "Apples", "sales_january": 120, "sales_february": 100},
{"product": "Oranges", "sales_january": 98, "sales_february": 90},
{"product": "Tomatoes", "sales_january": 86, "sales_february": 70},
{"product": "Grapes", "sales_january": 99, "sales_february": 80},
{"product": "Bananas", "sales_january": 85, "sales_february": 120},
{"product": "Lemons", "sales_january": 65, "sales_february": 150}
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
series=[
{"name": "sales_january", "color": "lime.4", "opacity": 0.1},
{"name": "sales_february", "color": "cyan.4", "opacity": 0.1}
],
withPolarGrid=True,
withPolarAngleAxis=False,
withPolarRadiusAxis=True,
withTooltip=False,
withDots=False,
)
```
### With tooltip and dots
```python
import dash_mantine_components as dmc
data = [
{"product": "Apples", "sales_january": 120, "sales_february": 100},
{"product": "Oranges", "sales_january": 98, "sales_february": 90},
{"product": "Tomatoes", "sales_january": 86, "sales_february": 70},
{"product": "Grapes", "sales_january": 99, "sales_february": 80},
{"product": "Bananas", "sales_january": 85, "sales_february": 120},
{"product": "Lemons", "sales_january": 65, "sales_february": 150},
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
series=[
{"name": "sales_january", "color": "lime.4", "opacity": 0.1},
{"name": "sales_february", "color": "cyan.4", "opacity": 0.1},
],
withTooltip=True,
withDots=True,
)
```
### Rechart props
To pass props down to the underlying Recharts components, use the following props:
- `radarProps` passed props to [RadarChart](https://recharts.org/en-US/api/RadarChart) component
- `radarChartProps` passed props to [RadarChart](https://recharts.org/en-US/api/RadarChart) component
- `polarGridProps` passed props to [PolarGrid](https://recharts.org/en-US/api/PolarGrid) component
- `polarAngleAxisProps` passed props to [PolarAngleAxis](https://recharts.org/en-US/api/PolarAngleAxis) component
- `polarRadiusAxisProps` passed props to [PolarRadiusAxis](https://recharts.org/en-US/api/PolarRadiusAxis) component
- Also available: `legendProps`, `dotProps`, `activeDotProps`, `tooltipProps`
It's also possible to pass functions to the Recharts component. This example passes props to `PolarRadiusAxis` component.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
data = [
{"product": "Apples", "sales_january": 12000, "sales_february": 10000},
{"product": "Oranges", "sales_january": 9800, "sales_february": 9000},
{"product": "Tomatoes", "sales_january": 8600, "sales_february": 7000},
{"product": "Grapes", "sales_january": 9900, "sales_february": 8000},
{"product": "Bananas", "sales_january": 8500, "sales_february": 12000},
{"product": "Lemons", "sales_january": 6500, "sales_february": 15000},
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
withPolarRadiusAxis=True,
polarRadiusAxisProps={"angle": 30, "tickFormatter": {"function": "formatNumberIntl"}},
series=[
{"name": "sales_january", "color": "lime.4", "opacity": 0.1},
{"name": "sales_february", "color": "cyan.4", "opacity": 0.1},
],
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatNumberIntl = (value) => {
return new Intl.NumberFormat('en-US').format(value);
};
```
### Radar animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `radarProps` to pass properties to the Recharts `Radar` component.
```python
from random import randint
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-radarchart-animation"),
dmc.RadarChart(
id="radarchart-animation",
h=300,
data=[{}],
dataKey="product",
withPolarRadiusAxis=True,
radarProps={
"isAnimationActive": True,
},
series=[{"name": "sales", "color": "blue.4", "opacity": 0.2}],
),
]
)
@callback(
Output("radarchart-animation", "data"),
Input("btn-radarchart-animation", "n_clicks"),
)
def update(n):
return [
{"product": "Apples", "sales": randint(20, 100)},
{"product": "Oranges", "sales": randint(20, 100)},
{"product": "Tomatoes", "sales": randint(20, 100)},
{"product": "Grapes", "sales": randint(20, 100)},
{"product": "Bananas", "sales": randint(20, 100)},
{"product": "Lemons", "sales": randint(20, 100)},
]
```
### Legend
Set the `withLegend` prop to display the legend:
```python
import dash_mantine_components as dmc
data = [
{
"product": "Apples",
"Sales January": 120,
"Sales February": 100,
},
{
"product": "Oranges",
"Sales January": 98,
"Sales February": 90,
},
{
"product": "Tomatoes",
"Sales January": 86,
"Sales February": 70,
},
{
"product": "Grapes",
"Sales January": 99,
"Sales February": 80,
},
{
"product": "Bananas",
"Sales January": 85,
"Sales February": 120,
},
{
"product": "Lemons",
"Sales January": 65,
"Sales February": 150,
},
]
component = dmc.RadarChart(
h=300,
data=data,
dataKey="product",
withPolarRadiusAxis=True,
withLegend=True,
series=[
{
"name": "Sales January",
"color": "blue.6",
"opacity": 0.2,
},
{
"name": "Sales February",
"color": "orange.6",
"opacity": 0.2,
},
],
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### RadarChart selectors
| Selector | Static selector | Description |
|----------|----------------|-------------|
| root | .mantine-RadarChart-root | Root element |
| container | .mantine-RadarChart-container | Recharts ResponsiveContainer component |
| tooltip | .mantine-RadarChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-RadarChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-RadarChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-RadarChart-tooltipItemBody | Tooltip item wrapper around item color and name |
| tooltipItemColor | .mantine-RadarChart-tooltipItemColor | Tooltip item color |
| tooltipItemName | .mantine-RadarChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-RadarChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-RadarChart-tooltipLabel | Label of the tooltip |
| legend | .mantine-RadarChart-legend | Legend root element |
| legendItem | .mantine-RadarChart-legendItem | Legend item representing data series |
| legendItemColor | .mantine-RadarChart-legendItemColor | Legend item color |
| legendItemName | .mantine-RadarChart-legendItemName | Legend item name |
#### RadarChart CSS variables
| Selector | Variable | Description |
|----------|----------|-------------|
| root | --chart-grid-color | Controls color of the chart grid |
| root | --chart-text-color | Controls color of all text elements in the chart |
### Keyword Arguments
#### RadarChart
- children (a list of or a singular dash component, string or number; optional):
Additional components that are rendered inside recharts
`RadarChart` component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- activeDotProps (dict; optional):
Props passed down to all active dots. Ignored if `withDots=False`
is set.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts with strings as keys and values of type boolean | number | string | dict | list; required):
Data used in the chart.
- data-* (string; optional):
Wild card data attributes.
- dataKey (string; required):
Key of the `data` object for axis values.
- dotProps (dict; optional):
Props passed down to all dots. Ignored if `withDots=False` is set.
- gridColor (optional):
Controls color of the grid lines. By default, color depends on the
color scheme.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- legendProps (dict; optional):
Props passed down to recharts Legend component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- polarAngleAxisProps (dict; optional):
Props passed down to recharts PolarAngleAxis component.
- polarGridProps (dict; optional):
Props passed down to recharts PolarGrid component.
- polarRadiusAxisProps (dict; optional):
Props passed down to recharts PolarRadiusAxis component.
- radarChartProps (dict; optional):
Props passed down to recharts RadarChart component.
- radarProps (boolean | number | string | dict | list; optional):
Props passed down to recharts Radar component in a dict.
- series (list of dicts; required):
Determines which data should be consumed from the `data` array.
`series` is a list of dicts with keys:
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Controls color of all text elements. By default, color depends on
the color scheme.
- tooltipAnimationDuration (number; optional):
Tooltip position animation duration in ms. Default 0.
- tooltipProps (dict; optional):
Props passed down to recharts Tooltip component.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withDots (boolean; optional):
Determines whether dots should be displayed. Default False.
- withLegend (boolean; optional):
Determines whether chart legend should be displayed, `False` by
default.
- withPolarAngleAxis (boolean; optional):
Determines whether PolarAngleAxis component should be displayed,
`True` by default.
- withPolarGrid (boolean; optional):
Determines whether PolarGrid component should be displayed, `True`
by default.
- withPolarRadiusAxis (boolean; optional):
Determines whether PolarRadiusAxisProps component should be
displayed, `False` by default.
- withTooltip (boolean; optional):
Determines whether Tooltip component should be displayed. Default
False.
## ScatterChart
Scatter chart component
Category: Charts
### Usage
ScaltterChart is based on recharts [ScatterChart](https://recharts.org/en-US/api/ScatterChart) component:
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
)
```
### Data
There are two datasets imported on this page. A single series `data1` and a multiple series `data2`:
```python
data1 = [
{
"color": "blue.5",
"name": "Group 1",
"data": [
{"age": 25, "BMI": 20},
{"age": 30, "BMI": 22},
{"age": 35, "BMI": 18},
{"age": 40, "BMI": 25},
{"age": 45, "BMI": 30},
{"age": 28, "BMI": 15},
{"age": 22, "BMI": 12},
{"age": 50, "BMI": 28},
{"age": 32, "BMI": 19},
{"age": 48, "BMI": 31},
{"age": 26, "BMI": 24},
{"age": 38, "BMI": 27},
{"age": 42, "BMI": 29},
{"age": 29, "BMI": 16},
{"age": 34, "BMI": 23},
{"age": 44, "BMI": 33},
{"age": 23, "BMI": 14},
{"age": 37, "BMI": 26},
{"age": 49, "BMI": 34},
{"age": 27, "BMI": 17},
{"age": 41, "BMI": 32},
{"age": 31, "BMI": 21},
{"age": 46, "BMI": 35},
{"age": 24, "BMI": 13},
{"age": 33, "BMI": 22},
{"age": 39, "BMI": 28},
{"age": 47, "BMI": 30},
{"age": 36, "BMI": 25},
{"age": 43, "BMI": 29},
{"age": 21, "BMI": 11}
]
}
]
```
```python
data2 = [
{
"color": "blue.5",
"name": "Group 1",
"data": [
{"age": 25, "BMI": 20},
{"age": 30, "BMI": 22},
{"age": 35, "BMI": 18},
{"age": 40, "BMI": 25},
{"age": 45, "BMI": 30},
{"age": 28, "BMI": 15},
{"age": 22, "BMI": 12},
{"age": 50, "BMI": 28},
{"age": 32, "BMI": 19},
{"age": 48, "BMI": 31},
{"age": 26, "BMI": 24},
{"age": 38, "BMI": 27},
{"age": 42, "BMI": 29},
{"age": 29, "BMI": 16},
{"age": 34, "BMI": 23},
{"age": 44, "BMI": 33},
{"age": 23, "BMI": 14},
{"age": 37, "BMI": 26},
{"age": 49, "BMI": 34},
{"age": 27, "BMI": 17},
{"age": 41, "BMI": 32},
{"age": 31, "BMI": 21},
{"age": 46, "BMI": 35},
{"age": 24, "BMI": 13},
{"age": 33, "BMI": 22},
{"age": 39, "BMI": 28},
{"age": 47, "BMI": 30},
{"age": 36, "BMI": 25},
{"age": 43, "BMI": 29},
{"age": 21, "BMI": 11}
]
},
{
"color": "red.5",
"name": "Group 2",
"data": [
{"age": 26, "BMI": 21},
{"age": 31, "BMI": 24},
{"age": 37, "BMI": 19},
{"age": 42, "BMI": 27},
{"age": 29, "BMI": 32},
{"age": 35, "BMI": 18},
{"age": 40, "BMI": 23},
{"age": 45, "BMI": 30},
{"age": 27, "BMI": 15},
{"age": 33, "BMI": 20},
{"age": 38, "BMI": 25},
{"age": 43, "BMI": 29},
{"age": 30, "BMI": 16},
{"age": 36, "BMI": 22},
{"age": 41, "BMI": 28},
{"age": 46, "BMI": 33},
{"age": 28, "BMI": 17},
{"age": 34, "BMI": 22},
{"age": 39, "BMI": 26},
{"age": 44, "BMI": 31},
{"age": 32, "BMI": 18},
{"age": 38, "BMI": 23},
{"age": 43, "BMI": 28},
{"age": 48, "BMI": 35},
{"age": 25, "BMI": 14},
{"age": 31, "BMI": 20},
{"age": 36, "BMI": 25},
{"age": 41, "BMI": 30},
{"age": 29, "BMI": 16}
]
}
]
```
### Multiple Series
```python
import dash_mantine_components as dmc
from .data import data2
component = dmc.ScatterChart(
h=300,
data=data2,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
)
```
### Legend
To display chart legend, set `withLegend` prop. When one of the items in the legend is hovered, the corresponding data
series is highlighted in the chart.
```python
import dash_mantine_components as dmc
from .data import data2
component = dmc.ScatterChart(
h=300,
data=data2,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
withLegend=True,
)
```
### Legend position
You can pass props down to recharts Legend component with `legendProps` prop. For example, setting the following will
render the legend at the bottom of the chart and set its height to 50px:
```python
legendProps={'verticalAlign': 'bottom', 'height': 50}
```
```python
import dash_mantine_components as dmc
from .data import data2
component = dmc.ScatterChart(
h=300,
data=data2,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
withLegend=True,
legendProps={"verticalAlign": "bottom", "height": 20},
)
```
### X and Y axis props
Use `xAxisProps` and `yAxisProps` to pass props down to recharts `XAxis` and `YAxis` components. For example, these props can
be used to change orientation of axis:
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
tickLine="xy",
yAxisProps={"tickMargin": 15, "orientation": "right"},
xAxisProps={"tickMargin": 15, "orientation": "top"},
)
```
### Right Y axis
To display an additional Y axis on the right side of the chart, set the `withRightYAxis` prop. You can pass props down
to the recharts `YAxis` component with the `rightYAxisProps` prop and assign a label to the right Y axis with the
`rightYAxisLabel` prop. Note that you need to bind data series to the right Y axis by setting `yAxisId: 'right'` in the
data object. Series that do not have `yAxisId` are bound to the left Y axis. Both axes use the same `dataKey.y` value,
but their scales are calculated independently from the series assigned to them.
```python
import dash_mantine_components as dmc
from .data import data3
component = dmc.ScatterChart(
h=350,
data=data3,
dataKey={"x": "month", "y": "value"},
withLegend=True,
withRightYAxis=True,
xAxisLabel="Month",
yAxisLabel="Revenue",
rightYAxisLabel="Conversion rate",
rightYAxisProps={"unit": "%"},
)
```
### Point labels
Set `pointLabels` prop to `x` or `y` to display labels on data points for the corresponding axis:
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
tickLine="xy",
xAxisLabel="Age",
yAxisLabel="BMI",
pointLabels="x",
)
```
### Stroke dash array
Set `strokeDasharray` prop to control the stroke dash array of the grid and cursor lines. The value represent the
lengths of alternating dashes and gaps. For example, strokeDasharray="10 5" will render a dashed line with 10px dashes
and 5px gaps.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
strokeDasharray="15, 15",
)
```
### Grid and text colors
Use `--chart-grid-color` and `--chart-text-color` to change colors of grid lines and text within the chart.
With CSS , you can change colors depending on color scheme. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
tickLine="xy",
xAxisLabel="Age",
yAxisLabel="BMI",
className="chart-grid-text-colors",
)
```
```css
.chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-5);
--chart-text-color: var(--mantine-color-blue-8);
}
[data-mantine-color-scheme='dark'] .chart-grid-text-colors {
--chart-grid-color: var(--mantine-color-blue-3);
--chart-text-color: var(--mantine-color-blue-2);
}
```
If your application has only one color scheme, you can use `gridColor` and `textColor` props instead of CSS variables:
```python
dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
tickLine="xy",
xAxisLabel="Age",
yAxisLabel="BMI",
gridColor="gray.5",
textColor = "gray.9",
)
```
### Units
Set `unit` prop to render a unit label next to the y-axis ticks and tooltip values:
```python
import dash_mantine_components as dmc
spending_data = [
{
"color": "cyan",
"name": "Average monthly spending",
"data": [
{"age": a, "average_monthly_spending": b}
for a, b in zip(
[
25,
30,
35,
40,
45,
28,
22,
50,
32,
48,
26,
38,
42,
29,
34,
44,
23,
37,
49,
27,
41,
31,
46,
24,
33,
39,
47,
36,
43,
21,
],
[
1400,
2100,
1800,
2400,
2300,
1600,
1200,
3200,
1900,
2700,
1700,
2200,
2600,
1500,
2000,
2500,
1300,
2100,
2900,
1600,
2500,
1800,
2700,
1400,
2100,
2400,
2800,
2200,
2600,
1100,
],
)
],
}
]
component = dmc.ScatterChart(
h=300,
data=spending_data,
dataKey={"x": "age", "y": "average_monthly_spending"},
yAxisProps={"domain": [800, 3500]},
unit={"y": "$"},
labels={"x": "Age", "y": "Spending"},
)
```
### Value formatter
To format values in the tooltip and axis ticks, use `valueFormatter` prop. It accepts a function that takes number value
as an argument and returns formatted value. Use two functions to format x and y values separately:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
spending_data = [
{
"color": "cyan",
"name": "Average monthly spending",
"data": [
{"age": a, "average_monthly_spending": b}
for a, b in zip(
[
25,
30,
35,
40,
45,
28,
22,
50,
32,
48,
26,
38,
42,
29,
34,
44,
23,
37,
49,
27,
41,
31,
46,
24,
33,
39,
47,
36,
43,
21,
],
[
1400,
2100,
1800,
2400,
2300,
1600,
1200,
3200,
1900,
2700,
1700,
2200,
2600,
1500,
2000,
2500,
1300,
2100,
2900,
1600,
2500,
1800,
2700,
1400,
2100,
2400,
2800,
2200,
2600,
1100,
],
)
],
}
]
component = dmc.ScatterChart(
h=300,
data=spending_data,
dataKey={"x": "age", "y": "average_monthly_spending"},
yAxisProps={"domain": [800, 3500]},
valueFormatter={
"x": {"function": "formatYears"},
"y": {"function": "formatCurrency"}
}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatCurrency = (value) => {
return `$${new Intl.NumberFormat('en-US').format(value)}`;
};
dmcfuncs.formatYears = (value) => {
return `${value} years`
};
```
### Tooltip labels
To customize labels displayed in the tooltip, use `labels` prop:
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=350,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
labels={"x": "Age", "y": "Body Mass Index"},
)
```
### Custom tooltip
Use the `tooltipProps` `content` prop to to pass custom tooltip renderer to recharts Tooltip component. For example:
```python
tooltipProps={'content': {'functon': 'myFunction'}}
```
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=350,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
tooltipProps={"content": {"function": "chartTooltip"}}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.chartTooltip = ({ label, payload }) => {
if (!payload || payload.length === 0) return null;
return React.createElement(
dmc.Paper,
{
px: "md",
py: "sm",
withBorder: true,
shadow: "md",
radius: "md",
},
[
React.createElement(
dmc.Text,
{
key: "tooltip-label",
fw: 500,
mb: 5,
},
label
),
...payload.map((item, index) =>
React.createElement(
dmc.Text,
{
key: `item-${index}`,
c: item.color,
fz: "sm",
},
`${item.name}: ${item.value}`
)
),
]
);
};
```
### Remove tooltip
To remove tooltip, set `withTooltip=False`. It also removes the cursor line and disables interactions with the chart.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
withTooltip=False,
)
```
### Tooltip animation
By default, tooltip animation is disabled. To enable it, set `tooltipAnimationDuration` prop to a number of
milliseconds to animate the tooltip position change.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
tooltipAnimationDuration=200,
)
```
### Points animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `scatterProps` to pass properties to the Recharts `Scatter` component.
```python
from random import randint
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-scatterchart-animation"),
dmc.ScatterChart(
h=300,
data=[{"color": "blue.5", "name": "Group 1", "data": [{}]}],
scatterProps={
"isAnimationActive": True,
"animationDuration": 500,
"animationEasing": "ease-in-out",
"animationBegin": 500,
},
dataKey={"x": "x", "y": "y"},
xAxisLabel="X data",
yAxisLabel="Y data",
id="scatterchart-animation",
),
]
)
@callback(
Output("scatterchart-animation", "data"),
Input("btn-scatterchart-animation", "n_clicks"),
)
def update(n):
return [
{
"color": "blue.5",
"name": "Group 1",
"data": [
{"x": randint(1000, 4000), "y": randint(1000, 4000)} for _ in range(20)
],
}
]
```
### Reference lines
Use `referenceLines` prop to render reference lines. Reference lines are always rendered behind the chart.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=300,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
referenceLines=[
{"y": 14, "label": "Underweight ↓", "color": "red.7"},
{"y": 19, "label": "Normal weight", "color": "teal.7"},
{"y": 30, "label": "Overweight ↑", "color": "red.7"},
],
)
```
### Reference areas
Use the `referenceAreas` prop to highlight a rectangular region of the chart. Each area is bounded by x1/x2 (horizontal)
and y1/y2 (vertical) data values – omit one pair to span the full opposite axis, for example provide only x1/x2 to
highlight a time range across the entire height of the chart. Set `color` to any theme color or CSS color and label
to display text inside the area. Reference areas are rendered behind the chart series.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=350,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
referenceAreas=[
{"y1": 18.5, "y2": 25, "color": "teal.7", "label": "Normal weight"},
],
)
```
### Reference dots
Use the `referenceDots` prop to mark individual points on the chart – a peak, an event, a record value or an anomaly.
Each dot is positioned by x and y data coordinates and supports `r` (radius), `color` (any theme color or CSS color) and
`label`. Reference dots are rendered on top of the chart series.
```python
import dash_mantine_components as dmc
from .data import data1
component = dmc.ScatterChart(
h=350,
data=data1,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
referenceDots=[{"x": 46, "y": 35, "color": 'red.6', "label": 'Max BMI'}]
)
```
### clickData
Use the `clickData` property in a callback to retrieve data from the most recent click event. To get the name of the
clicked series, use the `clickSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data2
component = dmc.Group(
[
dmc.ScatterChart(
id="figure-scatterchart",
h=300,
data=data2,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
),
dmc.Text(id="clickdata-scatterchart1"),
dmc.Text(id="clickdata-scatterchart2"),
]
)
@callback(
Output("clickdata-scatterchart1", "children"),
Output("clickdata-scatterchart2", "children"),
Input("figure-scatterchart", "clickData"),
Input("figure-scatterchart", "clickSeriesName"),
)
def update(data, name):
return f"clickData: {data}", f"clickSeriesName: {name}"
```
### hoverData
Use the `hoverData` property in a callback to retrieve data from the most recent hover event. To get the name of the
hovered series, use the `hoverSeriesName` property.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
from .data import data2
component = dmc.Group(
[
dmc.ScatterChart(
id="figure-scatterchart-hover",
h=300,
data=data2,
dataKey={"x": "age", "y": "BMI"},
xAxisLabel="Age",
yAxisLabel="BMI",
withTooltip=False,
),
dmc.Text(id="hoverdata-scatterchart1"),
dmc.Text(id="hoverdata-scatterchart2"),
]
)
@callback(
Output("hoverdata-scatterchart1", "children"),
Output("hoverdata-scatterchart2", "children"),
Input("figure-scatterchart-hover", "hoverData"),
Input("figure-scatterchart-hover", "hoverSeriesName"),
)
def update(data, name):
return f"hoverData: {data}", f"hoverSeriesName: {name}"
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### ScatterChart selectors
| Selector | Static selector | Description |
|-------------------|---------------------------------|-------------------------------------------------|
| root | .mantine-ScatterChart-root | Root element |
| scatter | .mantine-ScatterChart-scatter | Recharts Scatter component |
| axis | .mantine-ScatterChart-axis | X and Y axis of the chart |
| container | .mantine-ScatterChart-container | Recharts ResponsiveContainer component |
| grid | .mantine-ScatterChart-grid | Recharts CartesianGrid component |
| legend | .mantine-ScatterChart-legend | Legend root element |
| legendItem | .mantine-ScatterChart-legendItem | Legend item representing data series |
| legendItemColor | .mantine-ScatterChart-legendItemColor | Legend item color |
| legendItemName | .mantine-ScatterChart-legendItemName | Legend item name |
| tooltip | .mantine-ScatterChart-tooltip | Tooltip root element |
| tooltipBody | .mantine-ScatterChart-tooltipBody | Tooltip wrapper around all items |
| tooltipItem | .mantine-ScatterChart-tooltipItem | Tooltip item representing data series |
| tooltipItemBody | .mantine-ScatterChart-tooltipItemBody | Tooltip item wrapper around item color and name |
| tooltipItemColor | .mantine-ScatterChart-tooltipItemColor | Tooltip item color |
| tooltipItemName | .mantine-ScatterChart-tooltipItemName | Tooltip item name |
| tooltipItemData | .mantine-ScatterChart-tooltipItemData | Tooltip item data |
| tooltipLabel | .mantine-ScatterChart-tooltipLabel | Label of the tooltip |
| referenceLine | .mantine-ScatterChart-referenceLine | Reference line |
| axisLabel | .mantine-ScatterChart-axisLabel | X and Y axis labels |
#### ScatterChart CSS variables
| Selector | Variable | Description |
|----------------|--------------------|------------------------------------------|
| root | --chart-grid-color | Controls color of the grid and cursor lines |
| | --chart-text-color | Controls color of the axis labels |
### Keyword Arguments
#### ScatterChart
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- accessibilityLayer (boolean; optional):
Determines whether the chart should be keyboard-navigable with the
recharts accessibility layer, `True` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- brushDragEnd (dict with strings as keys and values of type number; optional):
The startIndex and endIndex of the selected brush range when
dragging ends. Read only.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clickData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Click data.
- clickSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that was clicked.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of dicts; required):
Data that is used to build the chart.
`data` is a list of dicts with keys:
- data-* (string; optional):
Wild card data attributes.
- dataKey (dict; required):
Keys that should be used to retrieve data from the data array on x
and y axis.
`dataKey` is a dict with keys:
- gridAxis (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which lines should be displayed in the grid, `'x'` by
default.
- gridColor (optional):
Color of the grid and cursor lines, by default depends on color
scheme.
- gridProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `CartesianGrid` component.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hoverData (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Hover data.
- hoverSeriesName (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Name of the series that is hovered.
- labels (dict; optional):
Labels that should be used instead of keys names in the tooltip.
`labels` is a dict with keys:
- legendProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Legend` component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Chart orientation, `'horizontal'` by default.
- pointLabels (a value equal to: 'x', 'y'; optional):
If set, displays labels next to points for the given axis.
- referenceAreas (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference areas that should be displayed on the chart.
- referenceDots (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference dots that should be displayed on the chart.
- referenceLines (list of dicts with strings as keys and values of type boolean | number | string | dict | list; optional):
Reference lines that should be displayed on the chart.
- rightYAxisLabel (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- rightYAxisProps (boolean | number | string | dict | list; optional):
Props passed down to the YAxis recharts component rendered on the
right side.
- scatterChartProps (dict; optional):
Props passed down to recharts `ScatterChart` component.
- scatterProps (dict; optional):
Props passed down to recharts `Scatter` component.
- strokeDasharray (string | number; optional):
Dash array for the grid lines and cursor, `'5 5'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- textColor (optional):
Color of the text displayed inside the chart, `'dimmed'` by
default.
- tickLine (a value equal to: 'none', 'x', 'y', 'xy'; optional):
Specifies which axis should have tick line, `'y'` by default.
- tooltipAnimationDuration (number; optional):
Tooltip position animation duration in ms, `0` by default.
- tooltipProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Tooltip` component.
- unit (dict; optional):
Units displayed after value on axis and inside the tooltip.
`unit` is a dict with keys:
- valueFormatter (boolean | number | string | dict | list; optional):
A function to format values on Y axis and inside the tooltip. See
https://www.dash-mantine-components.com/functions-as-props.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withLegend (boolean; optional):
Determines whether chart legend should be displayed, `False` by
default.
- withRightYAxis (boolean; optional):
Determines whether additional y-axis should be displayed on the
right side of the chart, False by default.
- withTooltip (boolean; optional):
Determines whether chart tooltip should be displayed, `True` by
default.
- withXAxis (boolean; optional):
Determines whether x-axis should be hidden, `True` by default.
- withYAxis (boolean; optional):
Determines whether y-axis should be hidden, `True` by default.
- xAxisLabel (string; optional):
A label to display below the x-axis.
- xAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `XAxis` recharts component.
- yAxisLabel (string; optional):
A label to display next to the y-axis.
- yAxisProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `YAxis` recharts component.
## Sparkline
Simplified area chart to show trends
Category: Charts
### Introduction
Sparkline is a simplified version of AreaChart. It can be used to display a single series of data in a small space.
### Trend Colors
Use `trendColors` prop instead of `color` to change chart color depending on the trend. The prop accepts an object with `positive`, `negative` and `neutral` properties:
- `positive` - color for positive trend (first value is less than the last value in data array)
- `negative` - color for negative trend (first value is greater than the last value in data array)
- `neutral` - color for neutral trend (first and last values are equal)
`neutral` is optional, if not provided, the color will be the same as `positive`.
```python
import dash_mantine_components as dmc
from dash import html
positive_trend = [10, 20, 40, 20, 40, 10, 50]
negative_trend = [50, 40, 20, 40, 20, 40, 10]
neutral_trend = [10, 20, 40, 20, 40, 10, 50, 5, 10]
def make_sparkline(trend):
return dmc.Sparkline(
w=200,
h=60,
data=trend,
trendColors={"positive": "teal.6", "negative": "red.6", "neutral": "gray.5"},
fillOpacity=0.2,
)
component = dmc.Stack(
[
dmc.Text("Positive Trend"),
make_sparkline(positive_trend),
dmc.Text("Negative Trend", mt="md"),
make_sparkline(negative_trend),
dmc.Text("Neutral Trend", mt="md"),
make_sparkline(neutral_trend),
],
gap="md",
)
```
### Change area color depending on color scheme
You can use CSS variables in color property. Learn more in the Theming section under [Colors.](/colors#colors-in-light-and-dark-mode)
Example of area color that is dark orange in light mode and lime in dark mode:
```python
import dash_mantine_components as dmc
component = dmc.Sparkline(w=200, h=60, data=[10, 20, 40, 20, 40, 10, 50], className="chart-color")
```
```css
:root {
--chart-color: var(--mantine-color-orange-8)
}
:root[data-mantine-color-scheme="dark"] {
--chart-color: var(--mantine-color-lime-4);
}
```
### Sparkline animation
By default, the Recharts data animation is disabled. To enable and customize the animation, use `areaProps` to pass properties to the Recharts `Area` component.
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Box(
[
dmc.Button("Update Chart", id="btn-spark-animation", n_clicks=0),
dmc.Sparkline(
w=200,
h=60,
data=[],
areaProps={"isAnimationActive": True},
color="blue",
id="spark-animation",
),
]
)
@callback(Output("spark-animation", "data"), Input("btn-spark-animation", "n_clicks"))
def update(n):
if n % 2 == 0:
return [10, 20, 40, 20, 40, 10, 50]
return [50, 10, 30, 10, 40, 50, 10]
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Sparkline selectors
| Selector | Static selector | Description |
|:------------|:------------------------|:----------------------------------------|
| root | .mantine-Sparkline-root | Root element |
#### Sparkline CSS variables
| Selector | Variable | Description |
|:-----------------|:---------------------|:-----------------------------------|
| root | --chart-color | Controls stroke and fill colors |
### Keyword Arguments
#### Sparkline
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- areaProps (dict; optional):
Props passed down to recharts `Area` component.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color, `theme.primaryColor`
by default.
- connectNulls (boolean; optional):
Determines whether points with `None` values should be connected,
`True` by default.
- curveType (a value equal to: 'bump', 'linear', 'natural', 'monotone', 'step', 'stepBefore', 'stepAfter'; optional):
Type of the curve, `'linear'` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of numbers; required):
Data used to render the chart.
- data-* (string; optional):
Wild card data attributes.
- fillOpacity (number; optional):
Controls fill opacity of the area, `0.6` by default.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- strokeWidth (number; optional):
Area stroke width, `2` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- trendColors (dict; optional):
If set, `color` prop is ignored and chart color is determined by
the difference between first and last value.
`trendColors` is a dict with keys:
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withGradient (boolean; optional):
Determines whether the chart fill should be a gradient, `True` by
default.
## Autocomplete
Autocomplete user input with any list of options.
Category: Combobox
> Need users to select multiple items? See `MultiSelect` or `TagsInput`.
Use `Autocomplete` component in the following cases:
- You want to allow user to enter any value
- You want to display suggestions to the user based on the input value
- You want to preserve user input on blur if option was not selected from the dropdown
- `value` and `label` of the option are the same.
### Not a searchable select
`Autocomplete` is not a searchable select, it is a text input with suggestions. Values are not enforced to be one of
the suggestions, user can type anything. If you need a searchable select, use `Select` component instead.
To learn more about the differences between Autocomplete and Select, check [help center article](https://help.mantine.dev/q/select-autocomplete-difference).
### Made with Combobox
`Autocomplete` is built on top of [Combobox](https://mantine.dev/core/combobox/) and covers common use cases. If you need more advanced behavior or want to extend
its functionality, you can create your own custom `Autocomplete` component. See this [GitHub repository](https://github.com/AnnMarieW/dmc_custom_components) for custom DMC component examples.
### Simple Example
`Autocomplete` provides user a list of suggestions based on the input, however user is not limited to suggestions and can type anything.
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
id="framework-autocomplete",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
mb=10,
),
dmc.Text(id="autocomplete-value"),
]
)
@callback(Output("autocomplete-value", "children"), Input("framework-autocomplete", "value"))
def select_value(value):
return f" You selected {value}"
```
### Select first option on change
Set the `selectFirstOptionOnChange` prop to automatically select the first option in the dropdown when the input value
changes. This feature allows users to type a value and immediately press Enter to select the first matching option,
without needing to press the arrow down key first.
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Select your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value or enter anything",
selectFirstOptionOnChange=True,
)
```
### autoSelectOnBlur
Set `autoSelectOnBlur=True` to automatically select the highlighted option when the input loses focus. To see this
feature in action: select an option with up/down arrows, then click outside the input:
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
autoSelectOnBlur=True,
clearable=True,
)
```
### Data Format
`Autoselect` `data` prop accepts data in one of the following formats:
```python
data = ["Pandas", "NumPy", "TensorFlow", "PyTorch"]
# or
data = [
{"group": "US", "items": ["New York", "Seattle"]},
{"group": "Canada", "items": ["Montreal", "Vancouver"]}
]
```
### Options filtering
By default, `Autocomplete` filters options by checking if the option label contains input value. You can change this behavior
with `filter`. The filter function receives an object with the following properties as a single argument:
- `options` – array of options or options groups, all options are in `{ value: string; label: string; disabled?: boolean }` format
- `search` – current search query
- `limit` – value of limit prop passed to `Autocomplete`
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
Example of a custom filter function that matches options by words instead of letters sequence:
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your country",
placeholder="Pick value or enter anything",
data=[
"Great Britain",
"Canada",
"United States",
],
filter={"function": "filterCountries"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterCountries = function ({ options, search }) {
const queryWords = search.toLowerCase().trim().split(" ");
return options.filter((option) => {
const words = option.label.toLowerCase().trim().split(" ");
return queryWords.every((word) =>
words.some((labelWord) => labelWord.includes(word))
);
});
};
```
### Sort options
By default, options are sorted by their position in the data array. You can change this behavior with `filter` function:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite Python library",
placeholder="Pick value or enter anything",
data=[
"4 – NumPy",
"1 – Pandas",
"3 – Scikit-learn",
"2 – Plotly",
],
filter={"function": "filterPythonLibs"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterPythonLibs = function ({ options, search }) {
const query = search.toLowerCase().trim();
const result = options.filter((option) =>
option.label.toLowerCase().trim().includes(query)
);
result.sort((a, b) => a.label.localeCompare(b.label));
return result;
};
```
### Large Data Sets
The best strategy for large data sets is to limit the number of options that are rendered at the same time. You can
do it with limit prop.
Note that if you use a custom `filter` function, you need to implement your own logic to limit the number of options in filter
Example of `Autocomplete` with 100 000 options, 10 options are rendered at the same time:
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="100,000 options",
data=[f"Option {i}" for i in range(100000)],
placeholder="use limit to optimize performance",
limit=10,
)
```
### renderOption
`renderOption` function allows you to customize option rendering.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Autocomplete(
label="Select with renderOption",
placeholder="Select text align",
data=[
{ "value": 'left', "label": 'left' },
{ "value": 'center', "label": 'center' },
{ "value": 'right', "label": 'right' },
{ "value": 'justify', "label": 'justify' },
],
renderOption={"function": "renderOptionSelect"},
clearable=True
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
var iconify = window.dash_iconify;
dmcfuncs.renderOptionSelect = function ({ option, checked }) {
const icons = {
left: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-left", width: 24 }),
center: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-center", width: 24 }),
right: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-right", width: 24 }),
justify: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-justify", width: 24 }),
};
const checkedIcon = React.createElement(iconify.DashIconify, {
icon: "mdi:check",
width: 24,
});
return React.createElement(
dmc.Group,
{ flex: "1", gap: "xs" },
icons[option.value],
option.label,
checked ? checkedIcon : null
);
};
```
### Nothing found message
`Autocomplete` component does not support nothing found message. It is designed to accept any string as a value, so it
does not make sense to show nothing found message. If you want to limit user input to suggestions, you can use
searchable `Select` component instead. To learn more about the differences between `Autocomplete` and `Select`, check this [help center article](https://help.mantine.dev/q/select-autocomplete-difference).
### Scrollable dropdown
By default, the options list is wrapped with `ScrollArea.Autosize`. You can control dropdown max-height with
`maxDropdownHeight` prop if you do not change the default settings.
If you want to use native scrollbars, set `withScrollArea=False`. Note that in this case, you will need to change
dropdown styles with `Styles API`.
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.Autocomplete(
label="Scrollable dropdown",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value or enter anything",
maxDropdownHeight=300,
),
dmc.Autocomplete(
label="With native scroll",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value or enter anything",
withScrollArea=False,
styles={"dropdown": {"maxHeight": 200, "overflowY": "auto"}},
mt="md",
),
]
)
```
### Fit dropdown to viewport height
Set `floatingHeight="viewport"` to make the dropdown grow to fill the available vertical space in the viewport. The
flip middleware is disabled in this mode – the dropdown always opens in the configured direction and is constrained
to the viewport edges instead of flipping to the other side. Useful when working with large option lists:
```python
import dash_mantine_components as dmc
data = [f"Option {i}" for i in range(100)]
component = dmc.Autocomplete(
label="Fits viewport height",
placeholder="Pick value",
data=data,
floatingHeight="viewport",
)
```
### Group options
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
data=[
{
"group": "Data Analysis",
"items": ["Pandas", "NumPy"],
},
{
"group": "Deep Learning",
"items": ["TensorFlow", "PyTorch"],
},
],
)
```
### Disabled options
When option is disabled, it cannot be selected and is ignored in keyboard navigation.
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library:",
data=[
{"value":"Pandas"},
{"value": "NumPy"},
{"value":"TensorFlow", "disabled": True},
{"value":"PyTorch", "disabled": True}
],
)
```
### Combobox props
You can override `Combobox` props with `comboboxProps`. It is useful when you need to change some of the props that are
not exposed by `Autocomplete`, for example `withinPortal`:
```python
dmc.Autocomplete(comboboxProps={"withinPortal": False})
```
### Change dropdown z-index
```python
dmc.Autocomplete(comboboxProps={"zIndex": 1000})
```
### Inside Popover
To use `Autocomplete` inside popover, you need to set `withinPortal=False`:
```python
import dash_mantine_components as dmc
component = dmc.Popover(
position="bottom",
withArrow=True,
shadow="md",
children=[
dmc.PopoverTarget(dmc.Button("Toggle Popover")),
dmc.PopoverDropdown(
dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"withinPortal": False},
)
),
],
)
```
### Clearable
Set `clearable` prop to display the clear button in the right section. The button is not displayed when:
- The component does not have a value
- The component is disabled
- The component is read only
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
value="Pandas",
clearable=True,
)
```
### Clear section mode
The `clearSectionMode` prop determines how the `clear` button and `rightSection` are rendered:
- 'both' (default) – render both the `clear` button and `rightSection`
- 'rightSection' – render only the user-supplied `rightSection`, ignore `clear` button
- 'clear' – render only the `clear` button, ignore `rightSection`
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
data = ["Mercury", "Venus", "Earth", "Mars"]
component = dmc.Stack([
dmc.Autocomplete(
label="clearSectionMode='both' (default)",
placeholder="Pick a planet",
data=data,
value="Earth",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="both",
),
dmc.Autocomplete(
label="clearSectionMode='rightSection'",
placeholder="Pick a planet",
data=data,
value="Earth",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="rightSection",
),
dmc.Autocomplete(
label="clearSectionMode='clear'",
placeholder="Pick a planet",
data=data,
value="Earth",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="clear",
),
])
```
### Dropdown open in a callback
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.Button("Toggle dropdown", id="btn-autocomplete-opened", n_clicks=0),
dmc.Autocomplete(
label="Select your favorite library",
placeholder="Select value",
id="autocomplete-opened",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "bottom", "middlewares": {"flip": False, "shift": False}},
mb=10,
),
]
)
@callback(
Output("autocomplete-opened", "dropdownOpened"), Input("btn-autocomplete-opened", "n_clicks")
)
def select_value(n):
if n % 2 == 0:
return False
return True
```
### Dropdown position
By default, the dropdown is displayed below the input if there is enough space; otherwise it is displayed above the
input. You can change this behavior by setting `position` and `middlewares` props, which are passed down to the
underlying `Popover` component.
Example of dropdown that is always displayed above the input:
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "top", "middlewares": {"flip": False, "shift": False}},
)
```
### Dropdown width
To change dropdown width, set `width` prop in `comboboxProps`. By default, dropdown width is equal to the input width.
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "bottom-start", "width": 200},
)
```
### Dropdown offset
To change dropdown offset, set `offset` prop in `comboboxProps`:
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={
"position": "bottom",
"middlewares": {"flip": False, "shift": False},
"offset": 0,
},
)
```
### Dropdown animation
By default, dropdown animations are disabled. To enable them, you can set `transitionProps`, which will be passed
down to the underlying `Transition` component.
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"transitionProps": {"transition": "pop", "duration": 200}},
)
```
### Dropdown padding
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.Autocomplete(
label="Zero padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value or enter anything",
comboboxProps={"dropdownPadding": 0},
),
dmc.Autocomplete(
label="10px padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value or enter anything",
comboboxProps={"dropdownPadding": 10},
mt="md",
),
]
)
```
### Dropdown shadow
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library",
placeholder="Pick value or enter anything",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"shadow": "md"},
)
```
### Left and right sections
`Autocomplete` supports `leftSection` and `rightSection` props. These sections are rendered with absolute position
inside the input wrapper. You can use them to display icons, input controls or any other elements.
You can use the following props to control sections styles and content:
- `rightSection`/`leftSection` – component to render on the corresponding side of input
- `rightSectionWidth`/`leftSectionWidth` – controls width of the right section and padding on the corresponding side of the input. By default, it is controlled by component size prop.
- `rightSectionPointerEvents`/`leftSectionPointerEvents` – controls pointer-events property of the section. If you want to render a non-interactive element, set it to none to pass clicks through to the input.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Paper(
[
dmc.Autocomplete(
label="Your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value or enter anythings",
leftSectionPointerEvents="none",
leftSection=DashIconify(icon="bi-book"),
),
dmc.Autocomplete(
label="Your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value or enter anything",
rightSectionPointerEvents="none",
rightSection=DashIconify(icon="bi-book"),
mt="md",
),
]
)
```
### Input Props
`Autocomplete` component supports `Input` and Input Wrapper components features and all input element props.
`Autocomplete` documentation does not include all features supported by the component – see Input documentation to learn about all available features.
### Read only
Set `readOnly` to make the input read only. When readOnly is set, `Autocomplete` will not show suggestions and will not
call onChange function.
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
readOnly=True,
)
```
### Error State
Note: Dash adds some css by default which can lead you to see a red box when setting the `required` or `error`
prop to True. Use the below css snippet to counteract it.
```css
input:invalid {
outline: none !important;
}
```
You can let the user know if the selected value is invalid. In the example below, you will get an error message if you
select less than 2 currency pairs.
```python
import dash_mantine_components as dmc
from dash import Output, Input, callback
component = dmc.Autocomplete(
data=["USDINR", "EURUSD", "USDTWD", "USDJPY"],
id="autocomplete-error",
value="USDJPY",
)
@callback(Output("autocomplete-error", "error"), Input("autocomplete-error", "value"))
def select_value(value):
return "JPY is not allowed!" if value == "USDJPY" else ""
```
### Success State
```python
import dash_mantine_components as dmc
component = dmc.Autocomplete(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
success="Looks good"
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
### Autocomplete Selectors
| Selector | Static selector | Description |
|--------------|----------------------------------------|----------------------------------------------------------|
| `wrapper` | `.mantine-Autocomplete-wrapper` | Root element of the Input |
| `input` | `.mantine-Autocomplete-input` | Input element |
| `section` | `.mantine-Autocomplete-section` | Left and right sections |
| `root` | `.mantine-Autocomplete-root` | Root element |
| `label` | `.mantine-Autocomplete-label` | Label element |
| `required` | `.mantine-Autocomplete-required` | Required asterisk element, rendered inside label |
| `description`| `.mantine-Autocomplete-description` | Description element |
| `error` | `.mantine-Autocomplete-error` | Error element |
| `dropdown` | `.mantine-Autocomplete-dropdown` | Dropdown root element |
| `options` | `.mantine-Autocomplete-options` | Options wrapper |
| `option` | `.mantine-Autocomplete-option` | Option |
| `group` | `.mantine-Autocomplete-group` | Options group wrapper |
| `groupLabel` | `.mantine-Autocomplete-groupLabel` | Options group label |
### Keyword Arguments
#### Autocomplete
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoSelectOnBlur (boolean; optional):
If set, the highlighted option is selected when the input loses
focus @,default,`False`.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clearButtonProps (dict; optional):
Props passed down to the clear button.
`clearButtonProps` is a dict with keys:
- clearSectionMode (a value equal to: 'rightSection', 'both', 'clear'; optional):
Determines how the clear button and rightSection are rendered
default 'both'.
- clearable (boolean; optional):
Determines whether the clear button should be displayed in the
right section when the component has value, `False` by default.
- comboboxProps (dict; optional):
Props passed down to `Combobox` component.
`comboboxProps` is a dict with keys:
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of strings; optional):
Data displayed in the dropdown.
- data-* (string; optional):
Wild card data attributes.
- debounce (number | boolean; default False):
(boolean | number; default False): If True, changes to input will
be sent back to the Dash server only on enter or when losing
focus. If it's False, it will send the value back on every change.
If a number, it will not send anything back to the Dash server
until the user has stopped typing for that number of milliseconds.
- description (a list of or a singular dash component, string or number; optional):
Contents of `Input.Description` component. If not set, description
is not rendered.
- descriptionProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Description` component.
- disabled (boolean; optional):
Sets `disabled` attribute on the `input` element.
- dropdownOpened (boolean; optional):
Controlled dropdown opened state.
- error (a list of or a singular dash component, string or number; optional):
Contents of `Input.Error` component. If not set, error is not
rendered.
- errorProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Error` component.
- filter (boolean | number | string | dict | list; optional):
A Function based on which items are filtered and sorted. See
https://www.dash-mantine-components.com/functions-as-props.
- floatingHeight (string; optional):
If set to `'viewport'`, the dropdown grows to fill the available
vertical space in the viewport. Disables the `flip` middleware.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- inputProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input` component.
- inputWrapperOrder (list of a value equal to: 'label', 'description', 'error', 'input's; optional):
Controls order of the elements, `['label', 'description', 'input',
'error']` by default.
- label (a list of or a singular dash component, string or number; optional):
Contents of `Input.Label` component. If not set, label is not
rendered.
- labelProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Label` component.
- leftSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the left side of the input.
- leftSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `leftSection` element,
`'none'` by default.
- leftSectionProps (dict; optional):
Props passed down to the `leftSection` element.
- leftSectionWidth (string | number; optional):
Left section width, used to set `width` of the section and input
`padding-left`, by default equals to the input height.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- limit (number; optional):
Maximum number of options displayed at a time, `Infinity` by
default.
- loading (boolean; optional):
Displays loading indicator in the left or right section default
False.
- loadingPosition (a value equal to: 'left', 'right'; optional):
Position of the loading indicator default 'right'.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxDropdownHeight (string | number; optional):
`max-height` of the dropdown, only applicable when
`withScrollArea` prop is `True`, `250` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- n_blur (number; default 0):
An integer that represents the number of times that this element
has lost focus.
- n_submit (number; default 0):
An integer that represents the number of times that this element
has been submitted.
- name (string; optional):
Name prop.
- openOnFocus (boolean; optional):
If set, the dropdown opens when the input receives focus default
`True`.
- persisted_props (list of strings; optional):
Properties whose user interactions will persist after refreshing
the component or the page. Since only `value` is allowed this prop
can normally be ignored.
- persistence (string | number | boolean; optional):
Used to allow user interactions in this component to be persisted
when the component - or the page - is refreshed. If `persisted` is
truthy and hasn't changed from its previous value, a `value` that
the user has changed while using the app will keep that change, as
long as the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`. Note: The component
must have an `id` for persistence to work.
- persistence_type (a value equal to: 'local', 'session', 'memory'; optional):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data
is cleared once the browser quit.
- placeholder (string; optional):
Placeholder.
- pointer (boolean; optional):
Determines whether the input should have `cursor: pointer` style,
`False` by default.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem,
`theme.defaultRadius` by default.
- readOnly (boolean; optional):
Readonly.
- renderOption (boolean | number | string | dict | list; optional):
A function to render content of the option, replaces the default
content of the option. See
https://www.dash-mantine-components.com/functions-as-props.
- required (boolean; optional):
Adds required attribute to the input and a red asterisk on the
right side of label, `False` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the right side of the input.
- rightSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `rightSection` element,
`'none'` by default.
- rightSectionProps (dict; optional):
Props passed down to the `rightSection` element.
- rightSectionWidth (string | number; optional):
Right section width, used to set `width` of the section and input
`padding-right`, by default equals to the input height.
- scrollAreaProps (dict; optional):
Props passed down to the underlying `ScrollArea` component in the
dropdown.
`scrollAreaProps` is a dict with keys:
- selectFirstOptionOnChange (boolean; optional):
Determines whether the first option should be selected when value
changes, `False` by default.
- selectFirstOptionOnDropdownOpen (boolean; optional):
If set, the first option is selected when dropdown opens, `False`
by default.
- size (optional):
Controls input `height` and horizontal `padding`, `'sm'` by
default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- success (a list of or a singular dash component, string or number; optional):
Determines whether the input should have success styles.
- successProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Success` component.
- tabIndex (number; optional):
tab-index.
- value (string; default ''):
Controlled component value.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withAsterisk (boolean; optional):
Determines whether the required asterisk should be displayed.
Overrides `required` prop. Does not add required attribute to the
input. `False` by default.
- withErrorStyles (boolean; optional):
Determines whether the input should have red border and red text
color when the `error` prop is set, `True` by default.
- withScrollArea (boolean; optional):
Determines whether the options should be wrapped with
`ScrollArea.AutoSize`, `True` by default.
- withSuccessStyles (boolean; optional):
Determines whether the input should have green border when the
`success` prop is set @,default,True.
- wrapperProps (dict; optional):
Props passed down to the root element.
`wrapperProps` is a dict with keys:
## MultiSelect
MultiSelect enables users to select multiple options in a dropdown.
Category: Combobox
### Made with Combobox
`MultiSelect` is built on top of [Combobox](https://mantine.dev/core/combobox/) and covers common use cases. If you need more advanced behavior or want to extend
its functionality, you can create your own custom `MultiSelect` component. See this [GitHub repository](https://github.com/AnnMarieW/dmc_custom_components) for custom DMC component examples.
### Simple Example
MultiSelect component allows user to pick any number of option from the given data.
If you would like users to be able to enter custom values, see `TagsInput`.
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.MultiSelect(
label="Select your favorite libraries",
placeholder="Select all you like!",
id="framework-multi-select",
value=["pd", "torch"],
data=[
{"value": "pd", "label": "Pandas"},
{"value": "np", "label": "NumPy"},
{"value": "tf", "label": "TensorFlow"},
{"value": "torch", "label": "PyTorch"},
],
w=400,
mb=10,
),
dmc.Text(id="multi-selected-value"),
]
)
@callback(
Output("multi-selected-value", "children"), Input("framework-multi-select", "value")
)
def select_value(value):
return ", ".join(value)
```
### Data Format
The data can be provided as either:
* a list of primitive values (strings, numbers, booleans): - use when label and value are same.
* a list of dicts with `label` and `value` properties.
* a list of dict with `group` and `items` as keys where items are one of the previous two types.
```python
data = ["Pandas", "NumPy", "TensorFlow", "PyTorch"]
# or
data = [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
]
# or
data = [
{"group": "Data Analysis", "items": ["Pandas", "NumPy"]},
{"group": "Deep Learning", "items": ["TensorFlow", "Pytorch"]}
]
# or
data = [
{
"group": "Data Analysis",
"items": [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
],
},
{
"group": "Deep Learning",
"items": [
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
],
},
]
```
### Clearable
Set `clearable` prop to display the clear button in the right section. The button is not displayed when:
- The component does not have a value
- The component is disabled
- The component is read only
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Select your favorite library",
placeholder="Select all you like!",
value=["Pandas", "TensorFlow"],
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
clearable=True,
w=400,
mb=180,
)
```
### Clear section mode
The `clearSectionMode` prop determines how the `clear` button and `rightSection` are rendered:
- 'both' (default) – render both the `clear` button and `rightSection`
- 'rightSection' – render only the user-supplied `rightSection`, ignore `clear` button
- 'clear' – render only the `clear` button, ignore `rightSection`
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
data = [f"Option-{i}" for i in range(6)]
component = dmc.Stack([
dmc.MultiSelect(
label="clearSectionMode='both' (default)",
placeholder="Select options",
data=data,
value=["Option-1", "Option-2"],
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="both",
),
dmc.MultiSelect(
label="clearSectionMode='rightSection'",
placeholder="Select options",
data=data,
value=["Option-1", "Option-2"],
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="rightSection",
),
dmc.MultiSelect(
label="clearSectionMode='clear'",
placeholder="Select options",
data=data,
value=["Option-1", "Option-2"],
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="clear",
),
])
```
### Searchable
Set `searchable` prop to allow filtering options by user input.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Pick your favorite libraries",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
searchable=True,
w=400,
)
```
### Nothing Found
Set the `nothingFoundMessage` prop to display a given message when no options match the search query or there is
no data available. If the `nothingFoundMessage` prop is not set, the `MultiSelect` dropdown will be hidden.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Pick your favorite libraries",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
searchable=True,
nothingFoundMessage="Nothing found...",
w=400,
)
```
### Clear search on change
Set the `clearSearchOnChange=False` to enable selecting multiple items using the same search query.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
data=["aa", "ab", "ac", "ba", "bb", "bc"],
value=["aa"],
searchable=True,
clearSearchOnChange=False
)
```
### Checked option icon
Set `checkIconPosition` prop to `left` or `right` to control position of check icon in active option.
To remove the check icon, set `withCheckIcon=False`.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Control check icon",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
value=["Pandas", "NumPy"],
checkIconPosition="right",
dropdownOpened=True,
w=400,
pb=150,
id="multi-select-check-icon",
comboboxProps={"withinPortal": False}
)
```
### Max Selected Values
You can limit the number of selected values with `maxValues` prop. This will not allow adding more values
once the limit is reached.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Select your favorite",
description="You can select a maximum of 3 frameworks.",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
maxValues=3,
w=400,
)
```
### Hide selected options
To remove selected options from the list of available options, set `hidePickedOptions` prop:
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Select your favorite libraries",
placeholder="Select all you like!",
hidePickedOptions=True,
value=["Pandas", "TensorFlow"],
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
w=400,
mb=140,
dropdownOpened=True,
comboboxProps={"withinPortal":False}
)
```
### Large Data Sets
The best strategy for large data sets is to limit the number of options that are rendered at the same time. You can
do it with limit prop.
Example of `MultiSelect` with 100 000 options, 10 options are rendered at the same time:
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="100,000 options",
data=[f"Option {i}" for i in range(100000)],
placeholder="use limit to optimize performance",
limit=10,
searchable=True,
w=400,
)
```
### renderOption
`renderOption` function allows you to customize option rendering.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
users_data = {
"Emily Johnson": {
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-7.png",
"email": "emily92@gmail.com",
},
"Ava Rodriguez": {
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-8.png",
"email": "ava_rose@gmail.com",
},
"Olivia Chen": {
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-4.png",
"email": "livvy_globe@gmail.com",
},
"Ethan Barnes": {
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-1.png",
"email": "ethan_explorer@gmail.com",
},
"Mason Taylor": {
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-2.png",
"email": "mason_musician@gmail.com",
},
}
component = dmc.MultiSelect(
data=list(users_data.keys()),
label="Employees of the month",
placeholder="Search for employee",
maxDropdownHeight=300,
searchable=True,
hidePickedOptions=True,
renderOption={
"function": "renderUserOption",
"options": {"users": users_data},
},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.renderUserOption = function ({ option }, { users }) {
const user = users[option.value];
return React.createElement(
dmc.Group,
{ gap: "sm" },
React.createElement(dmc.Avatar, {
key: "avatar",
src: user.image,
size: 36,
radius: "xl",
}),
React.createElement(
"div",
{ key: "text-block" },
React.createElement(dmc.Text, { size: "sm", key: "name" }, option.value),
React.createElement(dmc.Text, {
size: "xs",
opacity: 0.5,
key: "email",
children: user.email,
})
)
);
};
```
### renderPill
The `renderPill` function allows you to customize pill rendering. The function receives the `option` (that was passed to data),
`value`, `onRemove` and `disabled` props. It must return a React node.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from dash import Input, Output, callback
users = [
{
"value": "Emily Johnson",
"label": "Emily Johnson",
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-7.png",
},
{
"value": "Ava Rodriguez",
"label": "Ava Rodriguez",
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-8.png",
},
{
"value": "Olivia Chen",
"label": "Olivia Chen",
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-4.png",
},
{
"value": "Ethan Barnes",
"label": "Ethan Barnes",
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-1.png",
},
{
"value": "Mason Taylor",
"label": "Mason Taylor",
"image": "https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-2.png",
},
]
component = dmc.Box([
dmc.MultiSelect(
id="multi-select-render-pill",
data=users,
label="Candidates",
placeholder="Select candidates",
value=["Emily Johnson", "Ava Rodriguez"],
renderPill={ "function": "renderUserPill", "options": {"users": users}},
),
dmc.Text(id="multi-select-render-pill-val")
])
@callback(
Output("multi-select-render-pill-val", "children"),
Input("multi-select-render-pill", "value"),
)
def update(value):
return f"You selected {value}"
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.renderUserPill = function ({ option, onRemove }, { users }) {
const usersMap = new Map(
users.map((user) => [user.value.toString(), user])
);
const user = usersMap.get(option?.value.toString());
return React.createElement(
dmc.Pill,
{
withRemoveButton: true,
onRemove: onRemove,
},
React.createElement(
"div",
{
style: {
display: "flex",
alignItems: "center",
gap: 8,
},
},
React.createElement(dmc.Avatar, {
src: user?.image,
size: 16,
}),
option?.label
)
);
};
```
### Reorder pills
Set the `withPillsReorder` prop to allow reordering pills. Dropping a pill before or after another pill updates the
component `value` accordingly. Reordering is automatically disabled when `disabled` or `readOnly` is set.
You can reorder pills with a mouse (drag-and-drop) or keyboard:
- Pills are not part of the `Tab` order. With focus on the input, press `ArrowLeft` (when the caret is at the start of the input) to move focus to the last pill.
- `ArrowLeft` and `ArrowRight` move focus between pills (RTL-aware). Pressing `ArrowRight` on the last pill returns focus to the input.
- `Alt + ArrowLeft` and `Alt + ArrowRight` reorder the focused pill (RTL-aware).
-
Focus follows the moved pill so multiple moves can be chained without re-focusing. Reordering is automatically disabled when disabled or readOnly is set.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Select your favorite superpowers",
description="Drag pills to put them in order of preference.",
data=["Teleport", "Time Travel", "Fly", "Invisibility", "Mind Reading"],
value=["Teleport", "Time Travel", "Fly", "Invisibility", "Mind Reading"],
withPillsReorder=True,
)
```
### Options filtering
By default, `MultiSelect` filters options by checking if the option label contains input value. You can change this behavior
with `filter`. The filter function receives an object with the following properties as a single argument:
- `options` – array of options or options groups, all options are in `{ value: string; label: string; disabled?: boolean }` format
- `search` – current search query
- `limit` – value of limit prop passed to `Select`
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
Example of a custom filter function that matches options by words instead of letters sequence:
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your country",
placeholder="Pick value",
searchable=True,
data=[
"Great Britain",
"Canada",
"United States",
],
filter={"function": "filterCountries"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterCountries = function ({ options, search }) {
const queryWords = search.toLowerCase().trim().split(" ");
return options.filter((option) => {
const words = option.label.toLowerCase().trim().split(" ");
return queryWords.every((word) =>
words.some((labelWord) => labelWord.includes(word))
);
});
};
```
### Sort options
By default, options are sorted by their position in the data array. You can change this behavior with `filter` function:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite Python library",
placeholder="Pick value",
searchable=True,
nothingFoundMessage="Nothing found...",
data=[
"4 – NumPy",
"1 – Pandas",
"3 – Scikit-learn",
"2 – Plotly",
],
filter={"function": "filterPythonLibs"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterPythonLibs = function ({ options, search }) {
const query = search.toLowerCase().trim();
const result = options.filter((option) =>
option.label.toLowerCase().trim().includes(query)
);
result.sort((a, b) => a.label.localeCompare(b.label));
return result;
};
```
### Scrollable dropdown
By default, the options list is wrapped with `ScrollArea.Autosize`. You can control dropdown max-height with
`maxDropdownHeight` prop if you do not change the default settings.
If you want to use native scrollbars, set `withScrollArea=False`. Note that in this case, you will need to change
dropdown styles with `Styles API`.
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.MultiSelect(
label="Scrollable dropdown",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value",
maxDropdownHeight=300,
w=400,
),
dmc.MultiSelect(
label="With native scroll",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value",
withScrollArea=False,
styles={"dropdown": {"maxHeight": 200, "overflowY": "auto"}},
w=400,
mt="md",
),
]
)
```
### Fit dropdown to viewport height
Set `floatingHeight="viewport"` to make the dropdown grow to fill the available vertical space in the viewport. The
flip middleware is disabled in this mode – the dropdown always opens in the configured direction and is constrained
to the viewport edges instead of flipping to the other side. Useful when working with large option lists:
```python
import dash_mantine_components as dmc
data = [f"Option {i}" for i in range(100)]
component = dmc.MultiSelect(
label="Fits viewport height",
placeholder="Pick value",
data=data,
floatingHeight="viewport",
)
```
### Grouping
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
data=[
{
"group": "Data Analysis",
"items": [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
],
},
{
"group": "Deep Learning",
"items": [
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
],
},
],
w=400,
)
```
### Combobox props
You can override `Combobox` props with `comboboxProps`. It is useful when you need to change some of the props that are
not exposed by `MultiSelect`, for example `withinPortal`:
```python
dmc.MultiSelect(comboboxProps={"withinPortal": False})
```
### Change dropdown z-index
```python
dmc.MultiSelect(comboboxProps={"zIndex": 1000})
```
### Inside Popover
To use MultiSelect inside popover, you need to set `withinPortal=False`:
```python
import dash_mantine_components as dmc
component = dmc.Popover(
width=300,
position="bottom",
withArrow=True,
shadow="md",
children=[
dmc.PopoverTarget(dmc.Button("Toggle Popover")),
dmc.PopoverDropdown(
dmc.MultiSelect(
label="Your favorite libraries",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"withinPortal": False},
)
),
],
)
```
### Dropdown open in a callback
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.Button("Toggle dropdown", id="btn-multi-select-opened", n_clicks=0),
dmc.MultiSelect(
label="Select your favorite libraries",
placeholder="Select all you like!",
id="multi-select-opened",
value=["pd", "torch"],
data=[
{"value": "pd", "label": "Pandas"},
{"value": "np", "label": "NumPy"},
{"value": "tf", "label": "TensorFlow"},
{"value": "torch", "label": "PyTorch"},
],
comboboxProps={"position": "bottom", "middlewares": {"flip": False, "shift": False}},
w=400,
mb=10,
),
]
)
@callback(
Output("multi-select-opened", "dropdownOpened"),
Input("btn-multi-select-opened", "n_clicks"),
)
def select_value(n):
if n % 2 == 0:
return False
return True
```
### Dropdown position
By default, the dropdown is displayed below the input if there is enough space; otherwise it is displayed above the
input. You can change this behavior by setting `position` and `middlewares` props, which are passed down to the
underlying `Popover` component.
Example of dropdown that is always displayed above the input:
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite libraries",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "top", "middlewares": {"flip": False, "shift": False}},
)
```
### Dropdown width
To change dropdown width, set `width` prop in `comboboxProps`. By default, dropdown width is equal to the input width.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite libraries",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "bottom-start", "width": 200},
)
```
### Dropdown offset
To change dropdown offset, set `offset` prop in `comboboxProps`:
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite libraries",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={
"position": "bottom",
"middlewares": {"flip": False, "shift": False},
"offset": 0,
},
)
```
### Dropdown animation
By default, dropdown animations are disabled. To enable them, you can set `transitionProps`, which will be passed
down to the underlying `Transition` component.
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite libraries",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"transitionProps": {"transition": "pop", "duration": 200}},
)
```
### Dropdown padding
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.MultiSelect(
label="Zero padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
comboboxProps={"dropdownPadding": 0},
w=400,
),
dmc.MultiSelect(
label="10px padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
comboboxProps={"dropdownPadding": 10},
w=400,
mt="md",
),
]
)
```
### Dropdown shadow
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite libraries",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"shadow": "md"},
)
```
### Left and right sections
`MultiSelect` supports `leftSection` and `rightSection` props. These sections are rendered with absolute position
inside the input wrapper. You can use them to display icons, input controls or any other elements.
You can use the following props to control sections styles and content:
- `rightSection`/`leftSection` – component to render on the corresponding side of input
- `rightSectionWidth`/`leftSectionWidth` – controls width of the right section and padding on the corresponding side of the input. By default, it is controlled by component size prop.
- `rightSectionPointerEvents`/`leftSectionPointerEvents` – controls pointer-events property of the section. If you want to render a non-interactive element, set it to none to pass clicks through to the input.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Paper(
[
dmc.MultiSelect(
label="Your favorite libraries",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
leftSectionPointerEvents="none",
leftSection=DashIconify(icon="bi-book"),
w=400,
),
dmc.MultiSelect(
label="Your favorite libraries",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
rightSectionPointerEvents="none",
rightSection=DashIconify(icon="bi-book"),
w=400,
mt="md",
),
]
)
```
### Error State
You can let the user know if the selected value is invalid. In the example below, you will get an error message if you
select less than 2 currency pairs.
```python
import dash_mantine_components as dmc
from dash import Output, Input, callback
component = dmc.MultiSelect(
data=["USDINR", "EURUSD", "USDTWD", "USDJPY"],
id="multi-select-error",
value=["USDJPY"],
w=400,
)
@callback(Output("multi-select-error", "error"), Input("multi-select-error", "value"))
def select_value(value):
return "Select at least 2." if len(value) < 2 else ""
```
### Success State
```python
import dash_mantine_components as dmc
component = dmc.MultiSelect(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
success="Looks good"
)
```
### Input Props
`MultiSelect` component supports `Input` and Input Wrapper components features and all input element props.
`MultiSelect` documentation does not include all features supported by the component – see Input documentation to learn about all available features.
### Removing placeholder after values selected
`MultiSelect` component uses placeholder to indicate that there are values available for selection. It is different
from `Select` component where placeholder is removed when value is selected – user can select only one value.
You can use CSS to remove the placeholder in the `MultiSelect` component when values are selected:
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Paper(
[
dmc.MultiSelect(
label="Default Placeholder",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
value=["Pandas"],
w=400,
),
dmc.MultiSelect(
label="Placeholder removed when values are selected",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
value=["Pandas"],
className="dmc-docs-demo",
w=400,
mt="md",
),
]
)
```
```css
.dmc-docs-demo .mantine-MultiSelect-inputField {
&:not(:only-child)::placeholder {
color: transparent;
}
}
```
### Dash 4 dcc.Dropdown
The Dash 4 [dcc.Dropdown](https://dash.plotly.com/dash-core-components/dropdown) supports some features that are not
available in DMC. For example, virtualization, which renders only the visible options instead of the entire list. This improves performance and responsiveness when working
with large data sets. It also includes a search input and Select all / Deselect all buttons inside the dropdown menu.
When `multi=True`, it displays a count of selected items, preventing the input from resizing as selections grow.
The `dmc.InputWrapper` can be used to add elements like `label`, `description`, and `error` to the `dcc.Dropdown`,
making it consistent with the other DMC inputs. The `htmlFor` prop links the label to the component for focus and accessibility.
To style the `dcc.Dropdown` with a Mantine theme see the [Dash 4 components](/dash4-components) section.
```python
from dash import dcc
import dash_mantine_components as dmc
component = dmc.InputWrapper(
dcc.Dropdown([f"option {i}" for i in range(100)], value=["option 1", "option 2", "option 3"], multi=True, id="dcc4-dropdown"),
label="dcc.Dropdown with a dmc.InputWrapper",
htmlFor="dcc4-dropdown",
className="dmc" # styles with Mantine theme
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:------------|:---------------------------------|:-------------------------------------------------|
| wrapper | .mantine-MultiSelect-wrapper | Root element of the Input |
| input | .mantine-MultiSelect-input | Input element |
| section | .mantine-MultiSelect-section | Left and right sections |
| root | .mantine-MultiSelect-root | Root element |
| label | .mantine-MultiSelect-label | Label element |
| required | .mantine-MultiSelect-required | Required asterisk element, rendered inside label |
| description | .mantine-MultiSelect-description | Description element |
| error | .mantine-MultiSelect-error | Error element |
| dropdown | .mantine-MultiSelect-dropdown | Dropdown root element |
| options | .mantine-MultiSelect-options | Options wrapper |
| option | .mantine-MultiSelect-option | Option |
| empty | .mantine-MultiSelect-empty | Nothing found message |
| group | .mantine-MultiSelect-group | Options group wrapper |
| groupLabel | .mantine-MultiSelect-groupLabel | Options group label |
| pill | .mantine-MultiSelect-pill | Value pill |
| inputField | .mantine-MultiSelect-inputField | Input field |
| pillsList | .mantine-MultiSelect-pillsList | List of pills, also contains input field |
### Keyword Arguments
#### MultiSelect
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- checkIconPosition (a value equal to: 'left', 'right'; optional):
Position of the check icon relative to the option label, `'left'`
by default.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clearButtonProps (dict; optional):
Props passed down to the clear button.
`clearButtonProps` is a dict with keys:
- clearSearchOnChange (boolean; optional):
Clear search value when item is selected. Default True.
- clearSectionMode (a value equal to: 'rightSection', 'both', 'clear'; optional):
Determines how the clear button and rightSection are rendered
default 'both'.
- clearable (boolean; optional):
Determines whether the clear button should be displayed in the
right section when the component has value, `False` by default.
- comboboxProps (dict; optional):
Props passed down to `Combobox` component.
`comboboxProps` is a dict with keys:
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of strings; optional):
Data used to generate options.
- data-* (string; optional):
Wild card data attributes.
- debounce (number | boolean; default False):
(boolean | number; default False): If True, changes to input will
be sent back to the Dash server only on enter or when losing
focus. If it's False, it will send the value back on every change.
If a number, it will not send anything back to the Dash server
until the user has stopped typing for that number of milliseconds.
- description (a list of or a singular dash component, string or number; optional):
Contents of `Input.Description` component. If not set, description
is not rendered.
- descriptionProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Description` component.
- disabled (boolean; optional):
Sets `disabled` attribute on the `input` element.
- dropdownOpened (boolean; optional):
Controlled dropdown opened state.
- error (a list of or a singular dash component, string or number; optional):
Contents of `Input.Error` component. If not set, error is not
rendered.
- errorProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Error` component.
- filter (boolean | number | string | dict | list; optional):
A Function based on which items are filtered and sorted. See
https://www.dash-mantine-components.com/functions-as-props.
- floatingHeight (string; optional):
If set to `'viewport'`, the dropdown grows to fill the available
vertical space in the viewport. Disables the `flip` middleware.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hiddenInputProps (dict; optional):
Props passed down to the hidden input.
- hiddenInputValuesDivider (string; optional):
Divider used to separate values in the hidden input `value`
attribute, `','` by default.
- hidePickedOptions (boolean; optional):
Determines whether picked options should be removed from the
options list, `False` by default.
- inputProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input` component.
- inputWrapperOrder (list of a value equal to: 'label', 'description', 'error', 'input's; optional):
Controls order of the elements, `['label', 'description', 'input',
'error']` by default.
- label (a list of or a singular dash component, string or number; optional):
Contents of `Input.Label` component. If not set, label is not
rendered.
- labelProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Label` component.
- leftSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the left side of the input.
- leftSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `leftSection` element,
`'none'` by default.
- leftSectionProps (dict; optional):
Props passed down to the `leftSection` element.
- leftSectionWidth (string | number; optional):
Left section width, used to set `width` of the section and input
`padding-left`, by default equals to the input height.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- limit (number; optional):
Maximum number of options displayed at a time, `Infinity` by
default.
- loading (boolean; optional):
Displays loading indicator in the left or right section default
False.
- loadingPosition (a value equal to: 'left', 'right'; optional):
Position of the loading indicator default 'right'.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxDropdownHeight (string | number; optional):
`max-height` of the dropdown, only applicable when
`withScrollArea` prop is `True`, `250` by default.
- maxValues (number; optional):
Maximum number of values, `Infinity` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- n_blur (number; default 0):
An integer that represents the number of times that this element
has lost focus.
- n_submit (number; default 0):
An integer that represents the number of times that this element
has been submitted.
- name (string; optional):
Name prop.
- nothingFoundMessage (a list of or a singular dash component, string or number; optional):
Message displayed when no option matched current search query,
only applicable when `searchable` prop is set.
- openOnFocus (boolean; optional):
If set, the dropdown opens when the input receives focus default
`True`.
- persisted_props (list of strings; optional):
Properties whose user interactions will persist after refreshing
the component or the page. Since only `value` is allowed this prop
can normally be ignored.
- persistence (string | number | boolean; optional):
Used to allow user interactions in this component to be persisted
when the component - or the page - is refreshed. If `persisted` is
truthy and hasn't changed from its previous value, a `value` that
the user has changed while using the app will keep that change, as
long as the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`. Note: The component
must have an `id` for persistence to work.
- persistence_type (a value equal to: 'local', 'session', 'memory'; optional):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data
is cleared once the browser quit.
- placeholder (string; optional):
Placeholder.
- pointer (boolean; optional):
Determines whether the input should have `cursor: pointer` style,
`False` by default.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem,
`theme.defaultRadius` by default.
- readOnly (boolean; optional):
Readonly.
- renderOption (boolean | number | string | dict | list; optional):
A function to render content of the option, replaces the default
content of the option. See
https://www.dash-mantine-components.com/functions-as-props.
- renderPill (boolean | number | string | dict | list; optional):
A function to render content of the pill. See
https://www.dash-mantine-components.com/functions-as-props.
- required (boolean; optional):
Adds required attribute to the input and a red asterisk on the
right side of label, `False` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the right side of the input.
- rightSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `rightSection` element,
`'none'` by default.
- rightSectionProps (dict; optional):
Props passed down to the `rightSection` element.
- rightSectionWidth (string | number; optional):
Right section width, used to set `width` of the section and input
`padding-right`, by default equals to the input height.
- scrollAreaProps (dict; optional):
Props passed down to the underlying `ScrollArea` component in the
dropdown.
`scrollAreaProps` is a dict with keys:
- searchValue (string; optional):
Controlled search value.
- searchable (boolean; optional):
Determines whether the select should be searchable, `False` by
default.
- selectFirstOptionOnChange (boolean; optional):
Determines whether the first option should be selected when value
changes, `False` by default.
- selectFirstOptionOnDropdownOpen (boolean; optional):
If set, the first option is selected when dropdown opens, `False`
by default.
- size (optional):
Controls input `height` and horizontal `padding`, `'sm'` by
default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- success (a list of or a singular dash component, string or number; optional):
Determines whether the input should have success styles.
- successProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Success` component.
- tabIndex (number; optional):
tab-index.
- value (list of strings; optional):
Controlled component value.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withAlignedLabels (boolean; optional):
If set, unchecked labels are aligned with the checked one
@,default,`False`.
- withAsterisk (boolean; optional):
Determines whether the required asterisk should be displayed.
Overrides `required` prop. Does not add required attribute to the
input. `False` by default.
- withCheckIcon (boolean; optional):
Determines whether check icon should be displayed near the
selected option label, `True` by default.
- withErrorStyles (boolean; optional):
Determines whether the input should have red border and red text
color when the `error` prop is set, `True` by default.
- withPillsReorder (boolean; optional):
If set, selected values can be reordered by dragging pills.
Disabled when `disabled` or `readOnly` is set. @,default,False.
- withScrollArea (boolean; optional):
Determines whether the options should be wrapped with
`ScrollArea.AutoSize`, `True` by default.
- withSuccessStyles (boolean; optional):
Determines whether the input should have green border when the
`success` prop is set @,default,True.
- wrapperProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the root element.
## Select
Select enables users to select an option in a dropdown.
Category: Combobox
> Need users to select multiple items? See `MultiSelect`. Need users to type their own options? See `TagsInput` or `Autocomplete`
### Made with Combobox
`Select` is built on top of [Combobox](https://mantine.dev/core/combobox/) and covers common use cases. If you need more advanced behavior or want to extend
its functionality, you can create your own custom `Select` component. See this [GitHub repository](https://github.com/AnnMarieW/dmc_custom_components) for custom DMC component examples.
### Simple Example
`Select` component allows user to pick one option from the given data. Unlike `Autocomplete`, `Select` does not allow entering custom values.
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.Select(
label="Select your favorite library",
placeholder="Select one",
id="framework-select",
value="pd",
data=[
{"value": "pd", "label": "Pandas"},
{"value": "np", "label": "NumPy"},
{"value": "tf", "label": "TensorFlow"},
{"value": "torch", "label": "PyTorch"},
],
w=200,
mb=10,
),
dmc.Text(id="selected-value"),
]
)
@callback(Output("selected-value", "children"), Input("framework-select", "value"))
def select_value(value):
return f" You selected {value}"
```
### Data Format
The data can be provided as either:
* a list of primitive values (strings, numbers, booleans): - use when label and value are same.
* a list of dicts with `label` and `value` properties.
* a list of dict with `group` and `items` as keys where items are one of the previous two types.
```python
data = ["Pandas", "NumPy", "TensorFlow", "PyTorch"]
# or
data = [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
]
# or
data = [
{"group": "Data Analysis", "items": ["Pandas", "NumPy"]},
{"group": "Deep Learning", "items": ["TensorFlow", "Pytorch"]}
]
# or
data = [
{
"group": "Data Analysis",
"items": [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
],
},
{
"group": "Deep Learning",
"items": [
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
],
},
]
```
### autoSelectOnBlur
Set `autoSelectOnBlur=True` to automatically select the highlighted option when the input loses focus. To see this
feature in action: select an option with up/down arrows, then click outside the input:
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
autoSelectOnBlur=True,
w=400,
)
```
### Searchable
Set `searchable=True` to allow filtering options by user input.
```python
import dash_mantine_components as dmc
component = dmc.Select(
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
searchable=True,
w=200,
)
```
### clearSearchOnFocus
When `clearSearchOnFocus=True` and the `Select` is in searchable mode, the search input will be cleared each time the
field gains focus. This is useful when you want the user to start with an empty search box each time, without having
to manually delete the existing text.
```python
import dash_mantine_components as dmc
component = dmc.Select(
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
value="Pandas",
searchable=True,
clearSearchOnFocus=True,
)
```
### Nothing Found
Set the `nothingFoundMessage` prop to display a given message when no options match the search query or there is
no data available. If the `nothingFoundMessage` prop is not set, the `MultiSelect` dropdown will be hidden.
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Pick your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
searchable=True,
nothingFoundMessage="Nothing found...",
w=400,
)
```
### Checked option icon
Set `checkIconPosition` prop to left or right to control position of check icon in active option. To remove the
check icon, set `withCheckIcon=False`.
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Control check icon",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
value="NumPy",
checkIconPosition="right",
dropdownOpened=True,
comboboxProps={"withinPortal":False},
w=200,
pb=150,
id="select-check-icon",
)
```
### Clearable
Set `clearable` prop to enable clearing selected values.
```python
import dash_mantine_components as dmc
component = dmc.Select(
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
value="Pandas",
clearable=True,
w=200,
)
```
### Clear section mode
The `clearSectionMode` prop determines how the `clear` button and `rightSection` are rendered:
- 'both' (default) – render both the `clear` button and `rightSection`
- 'rightSection' – render only the user-supplied `rightSection`, ignore `clear` button
- 'clear' – render only the `clear` button, ignore `rightSection`
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
data = ["Mercury", "Venus", "Earth", "Mars"]
component = dmc.Stack([
dmc.Select(
label="clearSectionMode='both' (default)",
placeholder="Pick a planet",
data=data,
value="Earth",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="both",
),
dmc.Select(
label="clearSectionMode='rightSection'",
placeholder="Pick a planet",
data=data,
value="Earth",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="rightSection",
),
dmc.Select(
label="clearSectionMode='clear'",
placeholder="Pick a planet",
data=data,
value="Earth",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="clear",
),
])
```
### Allow deselect
`allowDeselect` prop determines whether the value should be deselected when user clicks on the selected option. By
default, `allowDeselect` is True:
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.Select(
label="Option cannot be deselected",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
value="Pandas",
allowDeselect=False,
w=400,
),
dmc.Select(
label="Option can be deselected",
description="This is the default behavior, click 'Pandas' in the dropdown",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
value="Pandas",
allowDeselect=True,
w=400,
mt="md",
),
]
)
```
### Large Data Sets
The best strategy for large data sets is to limit the number of options that are rendered at the same time. You can
do it with limit prop.
Note that if you use a custom `filter` function, you need to implement your own logic to limit the number of options in filter
Example of `Select` with 100 000 options, 10 options are rendered at the same time:
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="100,000 options",
data=[f"Option {i}" for i in range(100000)],
placeholder="use limit to optimize performance",
limit=10,
searchable=True,
w=400,
)
```
### renderOption
`renderOption` function allows you to customize option rendering.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = ([
dmc.Select(
label="Select with renderOption",
placeholder="Select text align",
data=[
{ "value": 'left', "label": 'Left' },
{ "value": 'center', "label": 'Center' },
{ "value": 'right', "label": 'Right' },
{ "value": 'justify', "label": 'Justify' },
],
renderOption={"function": "renderOptionSelect"}
)
])
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
var iconify = window.dash_iconify;
dmcfuncs.renderOptionSelect = function ({ option, checked }) {
const icons = {
left: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-left", width: 24 }),
center: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-center", width: 24 }),
right: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-right", width: 24 }),
justify: React.createElement(iconify.DashIconify, { icon: "mdi:format-align-justify", width: 24 }),
};
const checkedIcon = React.createElement(iconify.DashIconify, {
icon: "mdi:check",
width: 24,
});
return React.createElement(
dmc.Group,
{ flex: "1", gap: "xs" },
icons[option.value],
option.label,
checked ? checkedIcon : null
);
};
```
### Options filtering
By default, `Select` filters options by checking if the option label contains input value. You can change this behavior
with `filter`. The filter function receives an object with the following properties as a single argument:
- `options` – array of options or options groups, all options are in `{ value: string; label: string; disabled?: boolean }` format
- `search` – current search query
- `limit` – value of limit prop passed to `Select`
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
Example of a custom filter function that matches options by words instead of letters sequence:
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your country",
placeholder="Pick value",
searchable=True,
data=[
"Great Britain",
"Canada",
"United States",
],
filter={"function": "filterCountries"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterCountries = function ({ options, search }) {
const queryWords = search.toLowerCase().trim().split(" ");
return options.filter((option) => {
const words = option.label.toLowerCase().trim().split(" ");
return queryWords.every((word) =>
words.some((labelWord) => labelWord.includes(word))
);
});
};
```
### Sort options
By default, options are sorted by their position in the data array. You can change this behavior with `filter` function:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite Python library",
placeholder="Pick value",
searchable=True,
nothingFoundMessage="Nothing found...",
data=[
"4 – NumPy",
"1 – Pandas",
"3 – Scikit-learn",
"2 – Plotly",
],
filter={"function": "filterPythonLibs"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterPythonLibs = function ({ options, search }) {
const query = search.toLowerCase().trim();
const result = options.filter((option) =>
option.label.toLowerCase().trim().includes(query)
);
result.sort((a, b) => a.label.localeCompare(b.label));
return result;
};
```
### Scrollable dropdown
By default, the options list is wrapped with `ScrollArea.Autosize`. You can control dropdown max-height with
`maxDropdownHeight` prop if you do not change the default settings.
If you want to use native scrollbars, set `withScrollArea=False`. Note that in this case, you will need to change
dropdown styles with `Styles API`.
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.Select(
label="Scrollable dropdown",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value",
maxDropdownHeight=300,
w=400,
),
dmc.Select(
label="With native scroll",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value",
withScrollArea=False,
styles={"dropdown": {"maxHeight": 200, "overflowY": "auto"}},
w=400,
mt="md",
),
]
)
```
### Fit dropdown to viewport height
Set `floatingHeight="viewport"` to make the dropdown grow to fill the available vertical space in the viewport. The
flip middleware is disabled in this mode – the dropdown always opens in the configured direction and is constrained
to the viewport edges instead of flipping to the other side. Useful when working with large option lists:
```python
import dash_mantine_components as dmc
data = [f"Option {i}" for i in range(100)]
component = dmc.Select(
label="Fits viewport height",
placeholder="Pick value",
data=data,
floatingHeight="viewport",
)
```
### Grouping Items
```python
import dash_mantine_components as dmc
component = dmc.Select(
data=[
{
"group": "Data Analysis",
"items": [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
],
},
{
"group": "Deep Learning",
"items": [
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
],
},
],
w=400,
)
```
### Combobox props
You can override `Combobox` props with `comboboxProps`. It is useful when you need to change some of the props that are
not exposed by `Select`, for example `withinPortal`:
```python
dmc.Select(comboboxProps={"withinPortal": False})
```
### Change dropdown z-index
```python
dmc.Select(comboboxProps={"zIndex": 1000})
```
### Inside Popover
To use `Select` inside popover, you need to set `withinPortal=False`:
```python
import dash_mantine_components as dmc
component = dmc.Popover(
width=300,
position="bottom",
withArrow=True,
shadow="md",
children=[
dmc.PopoverTarget(dmc.Button("Toggle Popover")),
dmc.PopoverDropdown(
dmc.Select(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"withinPortal": False},
)
),
],
)
```
### Dropdown open in a callback
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.Button("Toggle dropdown", id="btn-select-opened", n_clicks=0),
dmc.Select(
label="Select your favorite library",
placeholder="Select value",
id="select-opened",
value="pd",
data=[
{"value": "pd", "label": "Pandas"},
{"value": "np", "label": "NumPy"},
{"value": "tf", "label": "TensorFlow"},
{"value": "torch", "label": "PyTorch"},
],
comboboxProps={"position": "bottom", "middlewares": {"flip": False, "shift": False}},
w=400,
mb=10,
),
]
)
@callback(
Output("select-opened", "dropdownOpened"), Input("btn-select-opened", "n_clicks")
)
def select_value(n):
if n % 2 == 0:
return False
return True
```
### Dropdown position
By default, the dropdown is displayed below the input if there is enough space; otherwise it is displayed above the
input. You can change this behavior by setting `position` and `middlewares` props, which are passed down to the
underlying `Popover` component.
Example of dropdown that is always displayed above the input:
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "top", "middlewares": {"flip": False, "shift": False}},
)
```
### Dropdown width
To change dropdown width, set `width` prop in `comboboxProps`. By default, dropdown width is equal to the input width.
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "bottom-start", "width": 200},
)
```
### Dropdown offset
To change dropdown offset, set `offset` prop in `comboboxProps`:
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={
"position": "bottom",
"middlewares": {"flip": False, "shift": False},
"offset": 0,
},
)
```
### Dropdown animation
By default, dropdown animations are disabled. To enable them, you can set `transitionProps`, which will be passed
down to the underlying `Transition` component.
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"transitionProps": {"transition": "pop", "duration": 200}},
)
```
### Dropdown padding
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.Select(
label="Zero padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
comboboxProps={"dropdownPadding": 0},
w=400,
),
dmc.Select(
label="10px padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
comboboxProps={"dropdownPadding": 10},
w=400,
mt="md",
),
]
)
```
### Dropdown shadow
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"shadow": "md"},
)
```
### Left and right sections
`Select` supports `leftSection` and `rightSection` props. These sections are rendered with absolute position
inside the input wrapper. You can use them to display icons, input controls or any other elements.
You can use the following props to control sections styles and content:
- `rightSection`/`leftSection` – component to render on the corresponding side of input
- `rightSectionWidth`/`leftSectionWidth` – controls width of the right section and padding on the corresponding side of the input. By default, it is controlled by component size prop.
- `rightSectionPointerEvents`/`leftSectionPointerEvents` – controls pointer-events property of the section. If you want to render a non-interactive element, set it to none to pass clicks through to the input.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Paper(
[
dmc.Select(
label="Your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
leftSectionPointerEvents="none",
leftSection=DashIconify(icon="bi-book"),
w=400,
),
dmc.Select(
label="Your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
rightSectionPointerEvents="none",
rightSection=DashIconify(icon="bi-book"),
w=400,
mt="md",
),
]
)
```
### Input Props
`Select` component supports `Input` and Input Wrapper components features and all input element props.
`Select` documentation does not include all features supported by the component – see Input documentation to learn about all available features.
### Error State
Note: Dash adds some css by default which can lead you to see a red box when setting the `required` or `error`
prop to True. Use the below css snippet to counteract it.
```css
input:invalid {
outline: none !important;
}
```
You can let the user know if the selected value is invalid. In the example below, you will get an error message if you
select less than 2 currency pairs.
```python
import dash_mantine_components as dmc
from dash import Output, Input, callback
component = dmc.Select(
data=["USDINR", "EURUSD", "USDTWD", "USDJPY"],
id="select-error",
value="USDJPY",
w=200,
)
@callback(Output("select-error", "error"), Input("select-error", "value"))
def select_value(value):
return "JPY is not allowed!" if value == "USDJPY" else ""
```
### Success State
```python
import dash_mantine_components as dmc
component = dmc.Select(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
success="Looks good"
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:------------|:----------------------------|:-------------------------------------------------|
| wrapper | .mantine-Select-wrapper | Root element of the Input |
| input | .mantine-Select-input | Input element |
| section | .mantine-Select-section | Left and right sections |
| root | .mantine-Select-root | Root element |
| label | .mantine-Select-label | Label element |
| required | .mantine-Select-required | Required asterisk element, rendered inside label |
| description | .mantine-Select-description | Description element |
| error | .mantine-Select-error | Error element |
| dropdown | .mantine-Select-dropdown | Dropdown root element |
| options | .mantine-Select-options | Options wrapper |
| option | .mantine-Select-option | Option |
| empty | .mantine-Select-empty | Nothing found message |
| group | .mantine-Select-group | Options group wrapper |
| groupLabel | .mantine-Select-groupLabel | Options group label |
### Keyword Arguments
#### Select
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- allowDeselect (boolean; optional):
Determines whether it should be possible to deselect value by
clicking on the selected option, `True` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoSelectOnBlur (boolean; optional):
If set, the highlighted option is selected when the input loses
focus. default `False`.
- checkIconPosition (a value equal to: 'left', 'right'; optional):
Position of the check icon relative to the option label, `'left'`
by default.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clearButtonProps (dict; optional):
Props passed down to the clear button.
`clearButtonProps` is a dict with keys:
- clearSearchOnFocus (boolean; default False):
Clears search value when dropdown is opened. Ignored if
searchable=False.
- clearSectionMode (a value equal to: 'rightSection', 'both', 'clear'; optional):
Determines how the clear button and rightSection are rendered
default 'both'.
- clearable (boolean; optional):
Determines whether the clear button should be displayed in the
right section when the component has value, `False` by default.
- comboboxProps (dict; optional):
Props passed down to `Combobox` component.
`comboboxProps` is a dict with keys:
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of strings; optional):
Data used to generate options.
- data-* (string; optional):
Wild card data attributes.
- debounce (number | boolean; default False):
(boolean | number; default False): If True, changes to input will
be sent back to the Dash server only on enter or when losing
focus. If it's False, it will send the value back on every change.
If a number, it will not send anything back to the Dash server
until the user has stopped typing for that number of milliseconds.
- description (a list of or a singular dash component, string or number; optional):
Contents of `Input.Description` component. If not set, description
is not rendered.
- descriptionProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Description` component.
- disabled (boolean; optional):
Sets `disabled` attribute on the `input` element.
- dropdownOpened (boolean; optional):
Controlled dropdown opened state.
- error (a list of or a singular dash component, string or number; optional):
Contents of `Input.Error` component. If not set, error is not
rendered.
- errorProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Error` component.
- filter (boolean | number | string | dict | list; optional):
A Function based on which items are filtered and sorted. See
https://www.dash-mantine-components.com/functions-as-props.
- floatingHeight (string; optional):
If set to `'viewport'`, the dropdown grows to fill the available
vertical space in the viewport. Disables the `flip` middleware.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hiddenInputProps (dict; optional):
Props passed down to the hidden input.
- inputProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input` component.
- inputWrapperOrder (list of a value equal to: 'label', 'description', 'error', 'input's; optional):
Controls order of the elements, `['label', 'description', 'input',
'error']` by default.
- label (a list of or a singular dash component, string or number; optional):
Contents of `Input.Label` component. If not set, label is not
rendered.
- labelProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Label` component.
- leftSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the left side of the input.
- leftSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `leftSection` element,
`'none'` by default.
- leftSectionProps (dict; optional):
Props passed down to the `leftSection` element.
- leftSectionWidth (string | number; optional):
Left section width, used to set `width` of the section and input
`padding-left`, by default equals to the input height.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- limit (number; optional):
Maximum number of options displayed at a time, `Infinity` by
default.
- loading (boolean; optional):
Displays loading indicator in the left or right section default
False.
- loadingPosition (a value equal to: 'left', 'right'; optional):
Position of the loading indicator default 'right'.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxDropdownHeight (string | number; optional):
`max-height` of the dropdown, only applicable when
`withScrollArea` prop is `True`, `250` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- n_blur (number; default 0):
An integer that represents the number of times that this element
has lost focus.
- n_submit (number; default 0):
An integer that represents the number of times that this element
has been submitted.
- name (string; optional):
Name prop.
- nothingFoundMessage (a list of or a singular dash component, string or number; optional):
Message displayed when no option matched current search query,
only applicable when `searchable` prop is set.
- openOnFocus (boolean; optional):
If set, the dropdown opens when the input receives focus default
`True`.
- persisted_props (list of strings; optional):
Properties whose user interactions will persist after refreshing
the component or the page. Since only `value` is allowed this prop
can normally be ignored.
- persistence (string | number | boolean; optional):
Used to allow user interactions in this component to be persisted
when the component - or the page - is refreshed. If `persisted` is
truthy and hasn't changed from its previous value, a `value` that
the user has changed while using the app will keep that change, as
long as the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`. Note: The component
must have an `id` for persistence to work.
- persistence_type (a value equal to: 'local', 'session', 'memory'; optional):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data
is cleared once the browser quit.
- placeholder (string; optional):
Placeholder.
- pointer (boolean; optional):
Determines whether the input should have `cursor: pointer` style,
`False` by default.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem,
`theme.defaultRadius` by default.
- readOnly (boolean; optional):
Readonly.
- renderOption (boolean | number | string | dict | list; optional):
A function to render content of the option, replaces the default
content of the option. See
https://www.dash-mantine-components.com/functions-as-props.
- required (boolean; optional):
Adds required attribute to the input and a red asterisk on the
right side of label, `False` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the right side of the input.
- rightSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `rightSection` element,
`'none'` by default.
- rightSectionProps (dict; optional):
Props passed down to the `rightSection` element.
- rightSectionWidth (string | number; optional):
Right section width, used to set `width` of the section and input
`padding-right`, by default equals to the input height.
- scrollAreaProps (dict; optional):
Props passed down to the underlying `ScrollArea` component in the
dropdown.
`scrollAreaProps` is a dict with keys:
- searchValue (string; optional):
Controlled search value.
- searchable (boolean; optional):
Determines whether the select should be searchable, `False` by
default.
- selectFirstOptionOnChange (boolean; optional):
Determines whether the first option should be selected when value
changes, `False` by default.
- selectFirstOptionOnDropdownOpen (boolean; optional):
If set, the first option is selected when dropdown opens, `False`
by default.
- size (optional):
Controls input `height` and horizontal `padding`, `'sm'` by
default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- success (a list of or a singular dash component, string or number; optional):
Determines whether the input should have success styles.
- successProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Success` component.
- tabIndex (number; optional):
tab-index.
- value (string | number | boolean; optional):
Controlled component value.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withAlignedLabels (boolean; optional):
If set, unchecked labels are aligned with the checked one
@,default,`False`.
- withAsterisk (boolean; optional):
Determines whether the required asterisk should be displayed.
Overrides `required` prop. Does not add required attribute to the
input. `False` by default.
- withCheckIcon (boolean; optional):
Determines whether check icon should be displayed near the
selected option label, `True` by default.
- withErrorStyles (boolean; optional):
Determines whether the input should have red border and red text
color when the `error` prop is set, `True` by default.
- withScrollArea (boolean; optional):
Determines whether the options should be wrapped with
`ScrollArea.AutoSize`, `True` by default.
- withSuccessStyles (boolean; optional):
Determines whether the input should have green border when the
`success` prop is set @,default,True.
- wrapperProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the root element.
## TagsInput
Capture a list of values from user with free input and suggestions
Category: Combobox
### Made with Combobox
`TagsInput` is built on top of [Combobox](https://mantine.dev/core/combobox/) and covers common use cases. If you need more advanced behavior or want to extend
its functionality, you can create your own custom `TagsInput` component. See this [GitHub repository](https://github.com/AnnMarieW/dmc_custom_components) for custom DMC component examples.
### Simple Example
`TagsInput` provides a way to enter multiple values. It can be used with suggestions or without them.
`TagsInput` is similar to MultiSelect, but it allows entering custom values.
By default, `enter key` and `,` will select the typed value.
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.TagsInput(
label="Select frameworks",
placeholder="Select all you like!",
id="framework-tags-input",
value=["ng", "vue"],
w=400,
mb=10,
),
dmc.Text(id="tags-input-value"),
]
)
@callback(
Output("tags-input-value", "children"), Input("framework-tags-input", "value")
)
def select_value(value):
return ", ".join(value)
```
### Data Format
Note that the `data` format is different than components like `Select` and `Multi Select`. See [Why can I not use value/label data structure with TagsInput?](https://help.mantine.dev/q/autocomplete-value-label)
`TagsInput` `data` prop accepts data in one of the following formats:
```python
data = ["React", "Angular", "Svelte", "Vue"]
# or
data = [
{"group": "Frontend", "items": ["React", "Angular"]},
{"group": "Backend", "items": ["Express", "Django"]}
]
```
### Loading state
Set `loading` prop to display a loading indicator. By default, the loader is displayed on the right side of the input.
You can change the position with the `loadingPosition` prop to 'left' or 'right'.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
placeholder="Enter tag",
loading=True,
w=400,
)
```
### Clearable
Set `clearable` prop to display the clear button in the right section. The button is not displayed when:
* The component does not have a value
* The component is disabled
* The component is read only
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Press Enter to submit a tag",
value=["React"],
w=400,
clearable=True,
)
```
### Clear section mode
The `clearSectionMode` prop determines how the `clear` button and `rightSection` are rendered:
- 'both' (default) – render both the `clear` button and `rightSection`
- 'rightSection' – render only the user-supplied `rightSection`, ignore `clear` button
- 'clear' – render only the `clear` button, ignore `rightSection`
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
data = [f"Option-{i}" for i in range(6)]
component = dmc.Stack([
dmc.TagsInput(
label="clearSectionMode='both' (default)",
placeholder="Select options",
data=data,
value=["Option-1", "Option-2"],
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="both",
),
dmc.TagsInput(
label="clearSectionMode='rightSection'",
placeholder="Select options",
data=data,
value=["Option-1", "Option-2"],
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="rightSection",
),
dmc.TagsInput(
label="clearSectionMode='clear'",
placeholder="Select options",
data=data,
value=["Option-1", "Option-2"],
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="clear",
),
])
```
### Max selected values
You can limit the number of selected values with `maxTags` prop. This will not allow adding more values once the limit is reached.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Select frameworks",
description="You can select a maximum of 3 frameworks.",
maxTags=3,
w=400,
)
```
### Accept value on blur
By default, if the user types a value and blurs the input, the value is added to the list. You can change this behavior
by setting `acceptValueOnBlur` to `False`. In this case, the value is added only when the user presses `Enter` or clicks
on a suggestion.
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.TagsInput(
label="Value is accepted on blur",
placeholder="Select all you like!",
id="framework-tags-input1",
value=["Pandas", "NumPy"],
w=400,
mb=10,
),
dmc.Text(id="tags-input-value1", mb="xl"),
dmc.TagsInput(
label="Value IS NOT accepted on blur",
placeholder="Select all you like!",
id="framework-tags-input2",
value=["Pandas", "NumPy"],
acceptValueOnBlur=False,
w=400,
mb=10,
),
dmc.Text(id="tags-input-value2"),
]
)
@callback(
Output("tags-input-value1", "children"), Input("framework-tags-input1", "value")
)
def select_value(value):
return f"You selected {value}"
@callback(
Output("tags-input-value2", "children"), Input("framework-tags-input2", "value")
)
def select_value(value):
return f"You selected {value}"
```
### Allow duplicates
By default, `TagsInput` does not allow adding duplicate values, but you can change this behavior by setting `allowDuplicates` prop.
Value is considered duplicate if it is already present in the `value` array, regardless of the case and trailing whitespace.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Press Enter to submit a tag",
placeholder="Duplicates are allowed",
allowDuplicates=True,
w=400,
)
```
### Split chars
By default, `TagsInput` splits values by comma (`,`), but you can change this behavior by setting `splitChars` prop to an array of strings.
All values from `splitChars` cannot be included in the final value. Values are also split on paste.
Example of splitting by `,`, `|` and `space`:
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Press Enter to submit a tag",
placeholder="Enter tag",
splitChars=[",", " ", "|"],
w=400,
)
```
### With suggestions
`TagsInput` can be used with suggestions, it will render suggestions list under input and allow selecting suggestions
with keyboard or mouse. Note that user is not limited to suggestions, it is still possible to enter custom values.
If you want to allow values only from suggestions, use [MultiSelect](/components/multiselect) component instead.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
w=400,
label="Press Enter to submit a tag",
placeholder="Pick tag from list",
data=["React", "Angular", "Svelte"],
)
```
### Grouping
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
data=[
{
"group": "Data Analysis",
"items": [
{"value": "Pandas", "label": "Pandas"},
{"value": "NumPy", "label": "NumPy"},
],
},
{
"group": "Deep Learning",
"items": [
{"value": "TensorFlow", "label": "TensorFlow"},
{"value": "PyTorch", "label": "PyTorch"},
],
},
],
w=400,
)
```
### Large data sets
The best strategy for large data sets is to limit the number of options that are rendered at the same time. You can do
it with `limit` prop.
Example of `TagsInput` with 100 000 options, 5 options are rendered at the same time:
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="100,000 options",
data=[f"Option {i}" for i in range(100000)],
placeholder="use limit to optimize performance",
limit=5,
w=400,
)
```
### renderOption
`renderOption` function allows you to customize option rendering.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
groceries = {
"Apples": {
"emoji": "🍎",
"description": "Crisp and juicy snacking delight",
},
"Bread": {
"emoji": "🍞",
"description": "Freshly baked daily essential",
},
"Bananas": {
"emoji": "🍌",
"description": "Perfect for a healthy breakfast",
},
"Eggs": {
"emoji": "🥚",
"description": "Versatile protein source for cooking",
},
"Broccoli": {
"emoji": "🥦",
"description": "Nutrient-rich green vegetable",
},
}
component = dmc.TagsInput(
label="Groceries",
placeholder="Pick tag from list or type to add new",
data=list(groceries.keys()),
maxDropdownHeight=300,
renderOption={
"function": "renderGroceryOption",
"options": {"data": groceries},
},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.renderGroceryOption = function ({ option }, { data }) {
const item = data[option.value];
return React.createElement(
dmc.Group,
null,
React.createElement(
dmc.Text,
{ span: true, fz: 24 },
item.emoji
),
React.createElement(
"div",
null,
React.createElement(dmc.Text, { key: "label"}, option.value, ),
React.createElement(
dmc.Text,
{ size: "xs", opacity: 0.5, key: "description" },
item.description
)
)
);
};
```
### renderPill
The `renderPill` function allows you to customize pill rendering. The function receives the `option` (that was passed to data),
`value`, `onRemove` and `disabled` props. It must return a React node. Note that since `TagsInput` allows adding custom values,
`option` property might be generated on the fly.
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Custom pills",
description="Tags are rendered with a star prefix",
placeholder="Enter tag",
value=["React", "Angular"],
renderPill={"function": "renderTagPill"}
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.renderTagPill = function ({ value, onRemove }) {
return React.createElement(
dmc.Pill,
{
withRemoveButton: true,
onRemove: onRemove,
},
`★ ${value}`
);
};
```
### Reorder pills
Set the `withPillsReorder` prop to allow reordering pills. Dropping a pill before or after another pill updates the
component `value` accordingly. Reordering is automatically disabled when `disabled` or `readOnly` is set.
You can reorder pills with a mouse (drag-and-drop) or keyboard:
- Pills are not part of the `Tab` order. With focus on the input, press `ArrowLeft` (when the caret is at the start of the input) to move focus to the last pill.
- `ArrowLeft` and `ArrowRight` move focus between pills (RTL-aware). Pressing `ArrowRight` on the last pill returns focus to the input.
- `Alt + ArrowLeft` and `Alt + ArrowRight` reorder the focused pill (RTL-aware).
-
Focus follows the moved pill so multiple moves can be chained without re-focusing.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Drag pills to reorder",
description="Tags can be reordered by dragging pills",
placeholder="Enter tag",
value=["first", "second", "third"],
w=400,
withPillsReorder=True
)
```
### Options filtering
By default, `TagsInput` filters options by checking if the option label contains input value. You can change this behavior
with `filter`. The filter function receives an object with the following properties as a single argument:
- `options` – array of options or options groups, all options are in `{ value: string; label: string; disabled?: boolean }` format
- `search` – current search query
- `limit` – value of limit prop passed to `Select`
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
Example of a custom filter function that matches options by words instead of letters sequence:
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="What countries have you visited?",
placeholder="Pick value or enter anything",
data=[
"Great Britain",
"Canada",
"United States",
],
filter={"function": "filterCountries"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterCountries = function ({ options, search }) {
const queryWords = search.toLowerCase().trim().split(" ");
return options.filter((option) => {
const words = option.label.toLowerCase().trim().split(" ");
return queryWords.every((word) =>
words.some((labelWord) => labelWord.includes(word))
);
});
};
```
### Sort options
By default, options are sorted by their position in the data array. You can change this behavior with `filter` function:
Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite Python library",
placeholder="Pick value or enter anything",
data=[
"4 – NumPy",
"1 – Pandas",
"3 – Scikit-learn",
"2 – Plotly",
],
filter={"function": "filterPythonLibs"},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.filterPythonLibs = function ({ options, search }) {
const query = search.toLowerCase().trim();
const result = options.filter((option) =>
option.label.toLowerCase().trim().includes(query)
);
result.sort((a, b) => a.label.localeCompare(b.label));
return result;
};
```
### Scrollable dropdown
By default, the options list is wrapped with `ScrollArea.Autosize`. You can control dropdown max-height with
`maxDropdownHeight` prop if you do not change the default settings.
If you want to use native scrollbars, set `withScrollArea=False`. Note that in this case, you will need to change
dropdown styles with `Styles API`.
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.TagsInput(
label="Scrollable dropdown",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value",
maxDropdownHeight=300,
w=400,
),
dmc.TagsInput(
label="With native scroll",
data=[f"Option {i}" for i in range(100)],
placeholder="Pick value",
withScrollArea=False,
styles={"dropdown": {"maxHeight": 200, "overflowY": "auto"}},
w=400,
mt="md",
),
]
)
```
### Fit dropdown to viewport height
Set `floatingHeight="viewport"` to make the dropdown grow to fill the available vertical space in the viewport. The
flip middleware is disabled in this mode – the dropdown always opens in the configured direction and is constrained
to the viewport edges instead of flipping to the other side. Useful when working with large option lists:
```python
import dash_mantine_components as dmc
data = [f"Option {i}" for i in range(100)]
component = dmc.TagsInput(
label="Fits viewport height",
placeholder="Pick value",
data=data,
floatingHeight="viewport",
)
```
### Disabled options
When an option is disabled, it cannot be selected and is ignored in keyboard navigation. Note that user can still enter
disabled option as a value. If you want to prohibit certain values, use a callback to filter them out.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Enter tags",
placeholder="Some tags are disabled",
data = [
{"value": "Pandas"},
{"value": "NumPy"},
{"value": "TensorFlow", "disabled": True},
{"value": "PyTorch", "disabled": True},
],
w=400,
)
```
### Combobox props
You can override `Combobox` props with `comboboxProps`. It is useful when you need to change some of the props that are
not exposed by `TagsInput`, for example `withinPortal`:
```python
dmc.TagsInput(comboboxProps={"withinPortal": False})
```
### Change dropdown z-index
```python
dmc.TagsInput(comboboxProps={"zIndex": 1000})
```
### Inside Popover
To use `TagsInput` inside popover, you need to set `withinPortal=False`:
```python
import dash_mantine_components as dmc
component = dmc.Popover(
width=300,
position="bottom",
withArrow=True,
shadow="md",
children=[
dmc.PopoverTarget(dmc.Button("Toggle Popover")),
dmc.PopoverDropdown(
dmc.TagsInput(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"withinPortal": False},
)
),
],
)
```
### Dropdown open in a callback
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
[
dmc.Button("Toggle dropdown", id="btn-tags-opened", n_clicks=0),
dmc.TagsInput(
label="Select your favorite library",
placeholder="Select value",
id="tags-opened",
value=["pd"],
data=[
{"value": "pd", "label": "Pandas"},
{"value": "np", "label": "NumPy"},
{"value": "tf", "label": "TensorFlow"},
{"value": "torch", "label": "PyTorch"},
],
w=400,
mb=10,
),
]
)
@callback(
Output("tags-opened", "dropdownOpened"), Input("btn-tags-opened", "n_clicks")
)
def select_value(n):
if n % 2 == 0:
return False
return True
```
### Dropdown position
By default, the dropdown is displayed below the input if there is enough space; otherwise it is displayed above the
input. You can change this behavior by setting `position` and `middlewares` props, which are passed down to the
underlying `Popover` component.
Example of dropdown that is always displayed above the input:
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "top", "middlewares": {"flip": False, "shift": False}},
)
```
### Dropdown width
To change dropdown width, set `width` prop in `comboboxProps`. By default, dropdown width is equal to the input width.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"position": "bottom-start", "width": 200},
)
```
### Dropdown offset
To change dropdown offset, set `offset` prop in `comboboxProps`:
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={
"position": "bottom",
"middlewares": {"flip": False, "shift": False},
"offset": 0,
},
)
```
### Dropdown animation
By default, dropdown animations are disabled. To enable them, you can set `transitionProps`, which will be passed
down to the underlying `Transition` component.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite library",
placeholder="Pick values",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"transitionProps": {"transition": "pop", "duration": 200}},
)
```
### Dropdown padding
```python
import dash_mantine_components as dmc
component = dmc.Paper(
[
dmc.TagsInput(
label="Zero padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
comboboxProps={"dropdownPadding": 0},
w=400,
),
dmc.TagsInput(
label="10px padding",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick value",
comboboxProps={"dropdownPadding": 10},
w=400,
mt="md",
),
]
)
```
### Dropdown shadow
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite library",
placeholder="Pick value",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
comboboxProps={"shadow": "md"},
)
```
### Left and right sections
`MultiSelect` supports `leftSection` and `rightSection` props. These sections are rendered with absolute position
inside the input wrapper. You can use them to display icons, input controls or any other elements.
You can use the following props to control sections styles and content:
- `rightSection`/`leftSection` – component to render on the corresponding side of input
- `rightSectionWidth`/`leftSectionWidth` – controls width of the right section and padding on the corresponding side of the input. By default, it is controlled by component size prop.
- `rightSectionPointerEvents`/`leftSectionPointerEvents` – controls pointer-events property of the section. If you want to render a non-interactive element, set it to none to pass clicks through to the input.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Paper(
[
dmc.TagsInput(
label="Your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
leftSectionPointerEvents="none",
leftSection=DashIconify(icon="bi-book"),
w=400,
),
dmc.TagsInput(
label="Your favorite library",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
placeholder="Pick values",
rightSectionPointerEvents="none",
rightSection=DashIconify(icon="bi-book"),
w=400,
mt="md",
),
]
)
```
### Input Props
`TagsInput` component supports `Input` and Input Wrapper components features and all input element props.
`TagsInput` documentation does not include all features supported by the component – see Input documentation to learn about all available features.
### Read only
Set `readOnly` to make the input read only. When `readOnly` is set, `TagsInput` will not show suggestions and value
cannot be updated by the user entering data in the input.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Read only",
placeholder="Enter tag",
readOnly=True,
value=["First", "Second"],
w=400,
)
```
### Disabled
Set `disabled` to disable the input. When `disabled` is set, user cannot interact with the input and `TagsInput` will not show suggestions.
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Disabled",
disabled=True,
value=["First", "Second"],
w=400,
)
```
### Error state
```python
import dash_mantine_components as dmc
component = dmc.Stack(
[
dmc.TagsInput(
label="Boolean error",
placeholder="Boolean error",
error=True,
value=["React", "Angular"],
),
dmc.TagsInput(
label="With error message",
placeholder="With error message",
error="Invalid name",
value=["React", "Angular"],
),
]
)
```
### Success state
```python
import dash_mantine_components as dmc
component = dmc.TagsInput(
label="Your favorite library:",
data=["Pandas", "NumPy", "TensorFlow", "PyTorch"],
success="Looks good"
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
Refer to the Mantine TagsInput Style API [interactive demo](https://mantine.dev/core/tags-input/#styles-api) for help in identifying each selector.
| Name | Static selector | Description |
|:------------|:-------------------------------|:-------------------------------------------------|
| wrapper | .mantine-TagsInput-wrapper | Root element of the Input |
| input | .mantine-TagsInput-input | Input element |
| section | .mantine-TagsInput-section | Left and right sections |
| root | .mantine-TagsInput-root | Root element |
| label | .mantine-TagsInput-label | Label element |
| required | .mantine-TagsInput-required | Required asterisk element, rendered inside label |
| description | .mantine-TagsInput-description | Description element |
| error | .mantine-TagsInput-error | Error element |
| dropdown | .mantine-TagsInput-dropdown | Dropdown root element |
| options | .mantine-TagsInput-options | Options wrapper |
| option | .mantine-TagsInput-option | Option |
| empty | .mantine-TagsInput-empty | Nothing found message |
| group | .mantine-TagsInput-group | Options group wrapper |
| groupLabel | .mantine-TagsInput-groupLabel | Options group label |
| pill | .mantine-TagsInput-pill | Value pill |
| inputField | .mantine-TagsInput-inputField | Input field |
| pillsList | .mantine-TagsInput-pillsList | List of pills, also contains input field |
### Keyword Arguments
#### TagsInput
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- acceptValueOnBlur (boolean; optional):
Determines whether the value typed in by the user but not
submitted should be accepted when the input is blurred, True by
default.
- allowDuplicates (boolean; optional):
Determines whether duplicate tags are allowed, `False` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clearButtonProps (dict; optional):
Props passed down to the clear button.
`clearButtonProps` is a dict with keys:
- clearSectionMode (a value equal to: 'rightSection', 'both', 'clear'; optional):
Determines how the clear button and rightSection are rendered
default 'both'.
- clearable (boolean; optional):
Determines whether the clear button should be displayed in the
right section when the component has value, `False` by default.
- comboboxProps (dict; optional):
Props passed down to `Combobox` component.
`comboboxProps` is a dict with keys:
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data (list of strings; optional):
Data displayed in the dropdown.
- data-* (string; optional):
Wild card data attributes.
- description (a list of or a singular dash component, string or number; optional):
Contents of `Input.Description` component. If not set, description
is not rendered.
- descriptionProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Description` component.
- disabled (boolean; optional):
Sets `disabled` attribute on the `input` element.
- dropdownOpened (boolean; optional):
Controlled dropdown opened state.
- error (a list of or a singular dash component, string or number; optional):
Contents of `Input.Error` component. If not set, error is not
rendered.
- errorProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Error` component.
- filter (boolean | number | string | dict | list; optional):
A Function based on which items are filtered and sorted. See
https://www.dash-mantine-components.com/functions-as-props.
- floatingHeight (string; optional):
If set to `'viewport'`, the dropdown grows to fill the available
vertical space in the viewport. Disables the `flip` middleware.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hiddenInputProps (dict; optional):
Props passed down to the hidden input.
- hiddenInputValuesDivider (string; optional):
Divider used to separate values in the hidden input `value`
attribute, `','` by default.
- inputProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input` component.
- inputWrapperOrder (list of a value equal to: 'label', 'description', 'error', 'input's; optional):
Controls order of the elements, `['label', 'description', 'input',
'error']` by default.
- label (a list of or a singular dash component, string or number; optional):
Contents of `Input.Label` component. If not set, label is not
rendered.
- labelProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Label` component.
- leftSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the left side of the input.
- leftSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `leftSection` element,
`'none'` by default.
- leftSectionProps (dict; optional):
Props passed down to the `leftSection` element.
- leftSectionWidth (string | number; optional):
Left section width, used to set `width` of the section and input
`padding-left`, by default equals to the input height.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- limit (number; optional):
Maximum number of options displayed at a time, `Infinity` by
default.
- loading (boolean; optional):
Displays loading indicator in the left or right section default
False.
- loadingPosition (a value equal to: 'left', 'right'; optional):
Position of the loading indicator default 'right'.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxDropdownHeight (string | number; optional):
`max-height` of the dropdown, only applicable when
`withScrollArea` prop is `True`, `250` by default.
- maxTags (number; optional):
Maximum number of tags, `Infinity` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- name (string; optional):
Name prop.
- openOnFocus (boolean; optional):
If set, the dropdown opens when the input receives focus default
`True`.
- persisted_props (list of strings; optional):
Properties whose user interactions will persist after refreshing
the component or the page. Since only `value` is allowed this prop
can normally be ignored.
- persistence (string | number | boolean; optional):
Used to allow user interactions in this component to be persisted
when the component - or the page - is refreshed. If `persisted` is
truthy and hasn't changed from its previous value, a `value` that
the user has changed while using the app will keep that change, as
long as the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`. Note: The component
must have an `id` for persistence to work.
- persistence_type (a value equal to: 'local', 'session', 'memory'; optional):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data
is cleared once the browser quit.
- placeholder (string; optional):
Placeholder.
- pointer (boolean; optional):
Determines whether the input should have `cursor: pointer` style,
`False` by default.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem,
`theme.defaultRadius` by default.
- readOnly (boolean; optional):
Readonly.
- renderOption (boolean | number | string | dict | list; optional):
A function to render content of the option, replaces the default
content of the option. See
https://www.dash-mantine-components.com/functions-as-props.
- renderPill (boolean | number | string | dict | list; optional):
A function to render content of the pill. See
https://www.dash-mantine-components.com/functions-as-props.
- required (boolean; optional):
Adds required attribute to the input and a red asterisk on the
right side of label, `False` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the right side of the input.
- rightSectionPointerEvents (a value equal to: 'auto', '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `rightSection` element,
`'none'` by default.
- rightSectionProps (dict; optional):
Props passed down to the `rightSection` element.
- rightSectionWidth (string | number; optional):
Right section width, used to set `width` of the section and input
`padding-right`, by default equals to the input height.
- scrollAreaProps (dict; optional):
Props passed down to the underlying `ScrollArea` component in the
dropdown.
`scrollAreaProps` is a dict with keys:
- searchValue (string; optional):
Controlled search value.
- selectFirstOptionOnChange (boolean; optional):
Determines whether the first option should be selected when value
changes, `False` by default.
- selectFirstOptionOnDropdownOpen (boolean; optional):
If set, the first option is selected when dropdown opens, `False`
by default.
- size (optional):
Controls input `height` and horizontal `padding`, `'sm'` by
default.
- splitChars (list of strings; optional):
Characters that should trigger tags split, `[',']` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- success (a list of or a singular dash component, string or number; optional):
Determines whether the input should have success styles.
- successProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Success` component.
- tabIndex (number; optional):
tab-index.
- value (list of strings; optional):
Controlled component value.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withAsterisk (boolean; optional):
Determines whether the required asterisk should be displayed.
Overrides `required` prop. Does not add required attribute to the
input. `False` by default.
- withErrorStyles (boolean; optional):
Determines whether the input should have red border and red text
color when the `error` prop is set, `True` by default.
- withPillsReorder (boolean; optional):
If set, selected values can be reordered by dragging pills.
Disabled when `disabled` or `readOnly` is set. @,default,False.
- withScrollArea (boolean; optional):
Determines whether the options should be wrapped with
`ScrollArea.AutoSize`, `True` by default.
- withSuccessStyles (boolean; optional):
Determines whether the input should have green border when the
`success` prop is set @,default,True.
- wrapperProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the root element.
## Custom DMC Components
Create advanced custom Dash components with MantineHooks and MantineCore
Category: Dash
*New in dash-mantine-components 2.5.0*
You can now build custom Dash components that use Mantine the same way Dash Mantine Components does.
Previously, custom components built with the standard Dash component template had to bundle their own copy of Mantine.
Because of this, they could not access the `MantineProvider` used by DMC, which meant themes, styles, and context did
not work as expected.
DMC now exports `MantineHooks` and `MantineCore`, allowing custom components to use the same Mantine hooks, utilities,
and context as the built-in components. This enables a wide range of custom components, such as building advanced `Select`
or `MultiSelect` on top of Mantine’s [Combobox](https://mantine.dev/core/combobox/), while keeping theme and behavior consistent inside a Dash app.
For examples and step-by-step instructions, see the custom DMC components in this [GitHub repository](https://github.com/AnnMarieW/dmc_custom_components).
## Dash 4 Components
How to style Dash 4 Core Components with a Mantine theme
Category: Dash
Dash 4 completely redesigned its core components for a consistent look and feel and added many new features. For a full
overview of what changed, see the [Dash 4 release post](https://community.plotly.com/t/dash-core-components-gets-a-design-driven-refresh-with-dash-4/96322).
It's usually best to stick with DMC components for a consistent design and UI. But some new DCC components such as `dcc.Dropdown`
and the `dcc.Slider` include features you won’t find in DMC so you might want to mix them in.
This section shows how to style Dash 4 components to match a Mantine theme in light and dark mode.
### Dash 4 Accent Color
The accent for Dash 4 components is controlled by a CSS variable so it's easy to change. The value can be any valid CSS color.
This example changes the default purple color to your Mantine primary color:
```python
style={
"--Dash-Fill-Interactive-Strong": "var(--mantine-primary-color-filled)"
}
```
### Dark Mode Support
Dash 4 components do not include built-in dark mode support. You can enable light and dark mode by mapping Dash CSS
variables to Mantine theme variables. The following is the CSS used in these docs.
Add the following CSS to `assets/`:
```css
.dmc {
--Dash-Stroke-Strong: var(--mantine-color-default-border);
--Dash-Stroke-Weak: var(--mantine-color-disabled);
--Dash-Fill-Interactive-Strong: var(--mantine-primary-color-filled);
--Dash-Fill-Inverse-Strong: var(--mantine-color-body);
--Dash-Text-Primary: var(--mantine-color-text);
--Dash-Text-Strong: var(--mantine-color-text);
--Dash-Text-Disabled: var(--mantine-color-dimmed);
--Dash-Text-Weak: var(--mantine-color-dimmed);
}
:root[data-mantine-color-scheme="dark"] .dmc {
--Dash-Fill-Inverse-Strong: var(--mantine-color-dark-6);
--Dash-Fill-Weak: rgba(255, 255, 255, 0.06);
--Dash-Fill-Primary-Hover: rgba(255, 255, 255, 0.08);
--Dash-Fill-Primary-Active: rgba(255, 255, 255, 0.12);
--Dash-Fill-Disabled: rgba(255, 255, 255, 0.15);
}
```
Wrap your app layout with `dmc` class:
```python
app.layout = dmc.MantineProvider(
dmc.Container(
[...],
className="dmc"
)
)
```
Dash 4 components inside this container will follow the Mantine color scheme and update automatically when the theme changes.
> Toggle the theme switch in the header to see the examples below update between light and dark mode.
### Example 1: dcc.Dropdown
This example shows how a [dcc.Dropdown](https://dash.plotly.com/dash-core-components/dropdown) works well with other DMC inputs in grids or forms.
For MultiSelect (set `multi=True`) the menu also includes Select all and Deselect all buttons. When multiple
items are selected, it displays a count of selected items, preventing the input from resizing as selections grow.
The `dmc.InputWrapper` is used to add elements like `label`, `description`, and `error` to the `dcc.Dropdown`,
making it consistent with the other DMC inputs. The `htmlFor` prop links the label to the component for focus and accessibility.
```python
import dash_mantine_components as dmc
from dash import dcc
component = dmc.Card([
dmc.SimpleGrid(
[
dmc.InputWrapper(
dcc.Dropdown([f"option {i}" for i in range(100)], value=["option 1", "option 2", "option 3"], multi=True, id="dcc-dropdown"),
label="dcc.Dropdown",
htmlFor="dcc-dropdown"
),
dmc.NumberInput(
label="dmc.NumberInput",
value=30712,
thousandSeparator=True,
prefix="$ ",
),
dmc.DatePickerInput(label="dmc.DatePickerInput", value="2025-12-05"),
],
cols={"base": 1, "md": 3},
),
],
withBorder=True,
shadow="sm",
radius="md",
className="dmc" # applies Mantine styles
)
```
### Example 2: dcc.Slider
The [dcc.Slider](https://dash.plotly.com/dash-core-components/slider) and `dcc.RangeSlider` includes optional numeric
input fields and automatic mark generation based on range and width. There is also an option for a vertical slider.
This example shows the `dcc.RandeSlider` styled with a Mantine theme.
```python
import dash_mantine_components as dmc
from dash import dcc
component = dcc.RangeSlider(0, 200, value=[50, 150], className="dmc")
```
### Migrating to Dash v4
All component props remain unchanged, so upgrading should not introduce errors. You may notice layout and style differences due to the redesign.
Custom CSS written for Dash 3 components will not apply to Dash 4. The components were fully rewritten, so selectors have changed. Start with the styling approach shown here and customize as needed for your app.
## Dash Ag Grid
Build high-performance, interactive data tables with Dash AG Grid and Dash Mantine Components. Learn how to apply light and dark grid themes and use DMC components as custom cell renderers and editors.
Category: Dash
### Dash AG Grid quickstart
If you're new to Dash AG Grid, check out the [official Dash AG Grid documentation](https://dash.plotly.com/dash-ag-grid) for detailed information.
Here are just some of the features enabled by default in the quickstart example below:
* Built-in theme pairs well with the Mantine default theme
* Columns are resizable (drag the column header edges)
* Rows are sortable (click header; shift-click for multi-sort)
* Smooth row animations during filtering and sorting
* Boolean values are rendered as checkboxes
* Columns can be reordered by dragging
* Columns can be pinned to either side of the grid
### Quickstart Demo
```bash
pip install dash-ag-grid
```
---
```python
import dash_mantine_components as dmc
import dash_ag_grid as dag
import pandas as pd
from dash import Dash
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/space-mission-data.csv")
app = Dash()
component = dag.AgGrid(
rowData=df.to_dict("records"),
columnDefs=[{"field": i} for i in df.columns],
)
app.layout=dmc.MantineProvider(component)
app.run(debug=True)
```
### Explore More Grid Features
Be sure to check out the [Dash AG Grid documentation](https://dash.plotly.com/dash-ag-grid) for even more features, such as:
- Column: resizing, reordering, pinning, spanning, and grouping.
- Row: sorting, selection (including with checkboxes), reordering, dragging, spanning, pinned rows, and full width rows.
- Data Manipulation and Display: pagination, cell data types with automatic inference, custom filtering, and cell editing, value getters and formatters, conditional formatting, and CSV data export.
- Layout and Styling: themes (Alpine, Material, Quartz) with light/dark options, customizable themes, and conditional styling for various elements. Custom icons and more.
- Other Features: tooltips in cells and headers, keyboard navigation, accessibility support, and localization.
- Enterprise Features: All the above features are free in AG Grid Community. Additional advanced features are available with an AG Grid Enterprise licence.
The next sections show how to apply AG Grid themes that match your Mantine light or dark theme, and how to use DMC
components as custom cell renderers and editors.
### Theming: Light and Dark Mode
#### Dash AG Grid ≥ v33
Dash AG Grid v33+ introduced a new theming API that makes it much easier to style the grid.
More details and examples are available in the [dash-ag-grid documentation](https://dash.plotly.com/dash-ag-grid/styling-themes).
If you are upgrading from an earlier version, see the [migration guide](https://dash.plotly.com/dash-ag-grid/migration-guide).
In earlier versions of dash-ag-grid, the grid theme was set using the `className` prop. Switching between light and
dark mode typically required updating `className` in a callback, which caused the grid to re-render and often resulted
in visible lag.
With v33+, the same built-in themes are still available, but they are applied through the new `theme` API instead
of `className`. Theme values can be customized using any valid CSS values, and using CSS variables works well for light and
dark mode support. See also the [Ag Grid documentation](https://www.ag-grid.com/react-data-grid/theming-colors/) for more information.
Below are two simple examples.
Example 1: No callback
This example uses a built-in light theme and applies Mantine CSS variables for background and text colors. When the app
theme changes, the grid updates automatically. No callback is required.
```python
# dash-ag-grid >= 33.3.3
import dash_ag_grid as dag
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv")
theme = {
"function": (
"themeQuartz.withParams({"
"backgroundColor: 'var(--mantine-color-body)', "
"foregroundColor: 'var(--mantine-color-text)', "
"})"
)
}
component = dag.AgGrid(
rowData=df.to_dict("records"),
columnDefs=[{"field": i} for i in ["athlete", "country", "sport", "year"]],
defaultColDef={"flex": 1, "filter": True},
dashGridOptions={
"theme": theme,
"rowSelection": {"mode": "multiRow"}
},
)
```
Example 2: Callback to switch built-in theme
Because the first example is based on a light theme, some elements such as scrollbars may not appear correctly in dark mode.
This example switches between the light and dark variants of the built-in Quartz theme. It also demonstrates additional
customization using the `theme` prop to set fonts and accent colors.
```python
# dash-ag-grid >= 33.3.3
import dash_ag_grid as dag
from dash import clientside_callback, Input, Output, html
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv")
theme = {
"function": (
"themeQuartz.withParams({"
"accentColor: 'var(--mantine-primary-color-filled)', "
"fontFamily: 'var(--mantine-font-family)', "
"headerFontWeight: 'bold'"
"})"
)
}
# Theme switch in the dmc-docs header:
# dmc.ColorSchemeToggle(
# lightIcon=DashIconify(icon="radix-icons:sun", width=20),
# darkIcon=DashIconify(icon="radix-icons:moon", width=20),
# variant="light",
# color="gray",
# id="docs-color-scheme-switch",
# )
component = html.Div([
dag.AgGrid(
id="theme-color-scheme33",
rowData=df.to_dict("records"),
columnDefs=[{"field": i} for i in ["athlete", "country", "sport", "year"]],
defaultColDef={"flex": 1, "filter": True},
dashGridOptions={
"theme": theme,
"rowSelection": {"mode": "multiRow"}
},
),
])
clientside_callback(
"""
(colorScheme) => {
document.documentElement.setAttribute(
'data-ag-theme-mode',
colorScheme
);
return window.dash_clientside.no_update;
}
""",
Input("docs-color-scheme-switch", "computedColorScheme"),
)
```
#### Dash AG Grid < v33
Before dash-ag-grid v33, the grid theme was set using the `className` prop. Four built-in themes were available, each with light and dark variants.
For example, to apply the Alpine theme:
* Light mode: `className="ag-theme-alpine"` (default)
* Dark mode: `className="ag-theme-alpine-dark"`
Switching between light and dark mode required updating the `className` prop in a callback.
For more details on available themes and customization options, see the [Dash AG Grid styling guide](https://dash.plotly.com/dash-ag-grid/styling-themes) or the [AG Grid v31.3 theme documentation](https://www.ag-grid.com/archive/31.3.0/react-data-grid/themes/).
Here is an example of the callback:
```python
# Example for dash-ag-grid<=33.0.0
import dash_ag_grid as dag
import pandas as pd
from dash import callback, Input, Output
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/space-mission-data.csv")
component = dag.AgGrid(
rowData=df.to_dict("records"),
columnDefs=[{"field": i} for i in df.columns],
id="theme-switch-dag31"
)
@callback(
Output("theme-switch-dag31", "className"),
Input("docs-color-scheme-switch", "checked")
)
def update_theme(switch_on):
return "ag-theme-alpine-dark" if switch_on else "ag-theme-alpine"
```
### Custom Cell Renderers with DMC
For an introduction to [dash-ag-grid Cell Renderers](https://dash.plotly.com/dash-ag-grid/cell-renderer-components) refer to the dash documentation.
A cell renderer is a JavaScript function that returns a component to customize the cell content, rather
than displaying simple text. You can use DMC components as custom cell renderers.
Key concepts:
* Define the cell renderer function in a `.js` file in `/assets/` under `window.dashAgGridComponentFunctions` namespace. Dash registers these components with the grid.
* Set `cellRenderer` to the function name.
* Pass extra props to the function with `cellRendererParams`.
```js
var dagcomponentfuncs = window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {};
dagcomponentfuncs.MyFunction = function (props) {
// define your cell renderer here
}
```
Want help writing these custom cell render functions? See [Using AI to Generate Functions](/functions-as-props#using-ai-to-generate-javascript-functions) for how to describe the logic in plain English or Python and convert it to JavaScript.
#### Example 1: Card
This example displays grid data in a DMC `Card` in cells. The card layout is defined in a `.js` file in the `/assets` folder, with
the function named `DMC_Card`.
```python
from dash import callback, Input, Output
import dash_ag_grid as dag
import pandas as pd
data = {
"stats": ["Revenue", "EBITDA", "Net Income"],
"results": ['$13,120,000','$1,117,000', '$788,000'],
"change": [10.1, -22.1, 18.6],
'comments': ['Enter your comments here...', '', '']
}
df = pd.DataFrame(data)
columnDefs = [
{
"headerName": "",
"cellRenderer": "DMC_Card",
},
{
"field": "comments",
"editable": True,
"cellEditorPopup": True,
"cellEditor": "agLargeTextCellEditor",
"flex": 1
},
]
component = dag.AgGrid(
columnDefs=columnDefs,
rowData=df.to_dict("records"),
dashGridOptions={"rowHeight": 120},
id="dag-dmc-card-grid",
)
@callback(
Output("dag-dmc-card-grid", "className"),
Input("docs-color-scheme-switch", "computedColorScheme")
)
def update_theme(color):
return "ag-theme-alpine-dark" if color=="dark" else "ag-theme-alpine"
```
```javascript
var dagcomponentfuncs = window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {};
dagcomponentfuncs.DMC_Card = function (props) {
return React.createElement(
window.dash_mantine_components.Card,
{
withBorder: true,
m: 4,
},
React.createElement(
window.dash_mantine_components.Text,
{c:"dimmed", tt: "uppercase", fw:700},
props.data.stats
),
React.createElement(
window.dash_mantine_components.Text,
{size: "lg"},
props.data.results
),
React.createElement(
window.dash_mantine_components.Text,
{size: "sm", c: (props.data.change > 0) ? "green" : "red"},
props.data.change + "%"
)
);
};
```
#### Example 2: Buttons
This example shows how to place interactive buttons inside grid cells. The `DMC_Button` is defined in a `.js` file in
`/assets` is used in the `cellRenderer` prop. You can pass `Button` props (color, icon, variant, etc.) using
`cellRendererParams` per column.
Here’s an example for the `"buy"` column:
```python
columnDefs = [
{
"field": "buy",
"cellRenderer": "DMC_Button",
"cellRendererParams": {
"variant": "outline",
"leftIcon": "ic:baseline-shopping-cart",
"color": "green",
"radius": "xl"
},
},
# other columns...
]
```
```python
import json
import dash_ag_grid as dag
from dash import html, dcc, Input, Output, callback
import pandas as pd
import dash_mantine_components as dmc
import dash_iconify
data = {
"ticker": ["AAPL", "MSFT", "AMZN", "GOOGL"],
"company": ["Apple", "Microsoft", "Amazon", "Alphabet"],
"price": [154.99, 268.65, 100.47, 96.75],
"buy": ["Buy" for _ in range(4)],
"sell": ["Sell" for _ in range(4)],
"watch": ["Watch" for _ in range(4)],
}
df = pd.DataFrame(data)
columnDefs = [
{
"headerName": "Stock Ticker",
"field": "ticker",
"minWidth": 100
},
{"headerName": "Company", "field": "company", "filter": True, "minWidth": 50},
{
"headerName": "Last Close Price",
"type": "rightAligned",
"field": "price",
"valueFormatter": {"function": """d3.format("($,.2f")(params.value)"""},
"minWidth": 100
},
{
"field": "buy",
"cellRenderer": "DMC_Button",
"cellRendererParams": {
"variant": "outline",
"leftIcon": "ic:baseline-shopping-cart",
"color": "green",
"radius": "xl"
},
"minWidth": 100
},
{
"field": "sell",
"cellRenderer": "DMC_Button",
"cellRendererParams": {
"variant": "outline",
"leftIcon": "ic:baseline-shopping-cart",
"color": "red",
"radius": "xl"
},
"minWidth": 100
},
{
"field": "watch",
"cellRenderer": "DMC_Button",
"cellRendererParams": {
"rightIcon": "ph:eye",
},
"minWidth": 100
},
]
component = html.Div(
[
dag.AgGrid(
id="dag-dmc-btn-grid",
columnDefs=columnDefs,
rowData=df.to_dict("records"),
columnSize="autoSize",
),
dmc.Text(id="dag-dmc-btn-value-changed"),
],
)
@callback(
Output("dag-dmc-btn-value-changed", "children"),
Input("dag-dmc-btn-grid", "cellRendererData"),
)
def showChange(n):
return json.dumps(n)
@callback(
Output("dag-dmc-btn-grid", "className"),
Input("docs-color-scheme-switch", "computedColorScheme")
)
def update_theme(color):
return "ag-theme-alpine-dark" if color=="dark" else "ag-theme-alpine"
```
```javascript
var dagcomponentfuncs = window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {};
dagcomponentfuncs.DMC_Button = function (props) {
const {setData, data} = props;
function onClick() {
setData();
}
let leftIcon, rightIcon;
if (props.leftIcon) {
leftIcon = React.createElement(window.dash_iconify.DashIconify, {
icon: props.leftIcon,
});
}
if (props.rightIcon) {
rightIcon = React.createElement(window.dash_iconify.DashIconify, {
icon: props.rightIcon,
});
}
return React.createElement(
window.dash_mantine_components.Button,
{
onClick,
variant: props.variant,
color: props.color,
leftSection: leftIcon,
rightSection: rightIcon,
radius: props.radius,
style: {
margin: props.margin,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
},
},
props.value
);
};
```
### Custom Cell editors with DMC
Dash AG Grid includes several [built-in cell editors](https://dash.plotly.com/dash-ag-grid/provided-cell-editors), such as:
- Text Cell Editor
- Large Text Cell Editor
- Select Cell Editor
- Rich Select Cell Editor (AG Grid Enterprise)
- Number Cell Editor
- Date Cell Editor
- Checkbox Cell Editor
These editors are easy to use and require no extra JavaScript. But if you need more control or want to use DMC components
as cell editors, you can create a custom cell editor.
The example below uses a generic editor function that works with any DMC component. Just copy the `.js` file into your app’s `/assets` folder to use it.
(Thanks to Dash community member [@BSd3v](https://github.com/BSd3v) for creating this!)
Then in your dash app you can pass a component written in Python to the function using the `cellEditorParams` prop:
```python
columnDefs = [
{
'cellEditor': {'function': 'AllFunctionalComponentEditors'},
"cellEditorParams": {
"component": dmc.Select(data=["A", "B", "C"])
}
},
]
```
#### Example: DatePickerInput, TagsInput, Select
This example shows how to use the following DMC components as custom cell editors:
* `dmc.DatePickerInput`
* `dmc.TagsInput`
* `dmc.Select`
Note: Set `cellEditorPopup=True` for any editor that displays dropdowns, popovers, or calendars. This prevents clipping inside the grid.
```python
from dash import callback, Input, Output
import dash_mantine_components as dmc
import dash_ag_grid as dag
import pandas as pd
now = "2025-12-30"
df = pd.DataFrame({
'Column 1': [1, 2, 3, 4, 5, 6],
'DatePickerInput': [now, now, now, now, now, now],
'TagsInput': [['A']] * 6, # Note TagsInput values must be a list
'Select': ['A', 'B', 'C', 'A', 'B', 'C']
})
columnDefs = [
{ "field": "Column 1", "headerName": "id", "maxWidth": 50},
{
"field": "DatePickerInput",
'cellEditor': {'function': 'AllFunctionalComponentEditors'},
'cellEditorParams': {'component': dmc.DatePickerInput(valueFormat="YYYY-MM-DD")},
'cellEditorPopup': True,
},
{
"field": "TagsInput",
'cellEditor': {'function': 'AllFunctionalComponentEditors'},
'cellEditorParams': {'component': dmc.TagsInput(data=["A", "B", "C"])},
'cellEditorPopup': True,
"flex": 1
},
{
"field": "Select",
'cellEditor': {'function': 'AllFunctionalComponentEditors'},
'cellEditorParams': {'component': dmc.Select(data=["A", "B", "C"])},
'cellEditorPopup': True,
"flex": 1
},
]
component = dag.AgGrid(
id='dag-dmc-cell-editor',
columnDefs=columnDefs,
rowData=df.to_dict('records'),
defaultColDef={'editable': True, "minWidth": 150},
dashGridOptions={'singleClickEdit': True}
)
@callback(
Output("dag-dmc-cell-editor", "className"),
Input("docs-color-scheme-switch", "computedColorScheme")
)
def update_theme(color):
return "ag-theme-alpine-dark" if color=="dark" else "ag-theme-alpine"
```
```javascript
var dagfuncs = (window.dashAgGridFunctions = window.dashAgGridFunctions || {});
const {useRef, createElement, useEffect, useCallback, forwardRef, useMemo} = React
// Use this with DMC components
dagfuncs.AllFunctionalComponentEditors = forwardRef(({ value, ...params }, ref) => {
const comp = params.colDef.cellEditorParams.component;
const node = useRef(params.api.getRowNode(params.node.id));
const newValue = useRef(value);
const escaped = useRef(null);
const editorRef = useRef(null);
const handleStop = ({ event, ...params }) => {
setTimeout(() => {
if (!escaped.current) {
node.current.setDataValue(params.column.colId, newValue.current);
}
}, 1);
};
if (params.colDef.cellEditorPopup) {
comp['props']['style'] = { ...comp.props?.style, width: params.column.actualWidth - 2 };
}
const setProps = (propsToSet) => {
if ('value' in propsToSet) {
newValue.current = propsToSet.value;
}
};
const handleKeyDown = ({ key, ...event }) => {
if (key == "Escape") {
escaped.current = true;
}
};
useEffect(() => {
params.api.addEventListener('cellEditingStopped', handleStop);
document.addEventListener('keydown', handleKeyDown);
params.colDef.suppressKeyboardEvent = (params) => params.editing && params.event.key != 'Tab';
return () => {
document.removeEventListener('keydown', handleKeyDown);
delete params.colDef.suppressKeyboardEvent;
params.api.removeEventListener('cellEditingStopped', handleStop);
};
}, []);
useEffect(() => {
if (editorRef.current) {
if (editorRef.current.querySelector('input')) {
editorRef.current.querySelector('input').focus();
} else {
editorRef.current.focus()
}
}
}, [editorRef.current]);
const el = useMemo(() =>
createElement(
'div',
{ ref: editorRef, tabIndex: 0 },
createElement(window[comp['namespace']][comp['type']], { ...comp.props, setProps, value })
),
[]);
return el;
});
```
## Dash Iconify
Add icons to your dash apps the simplest and the most efficient way.
Category: Dash
### Why Use This?
DashIconify fetches only the icons you need. You can use icons from over 100 icon sets without loading all of them.
Search [here](https://icon-sets.iconify.design/) for the desired icon and use DashIconify to use that in your dash app.
[Source Code](https://github.com/snehilvj/dash-iconify)
### Installation
```bash
pip install dash-iconify
```
```bash
poetry add dash-iconify
```
### Simple Usage
DashIconify component can be customized with `width`, `height`, `rotate` and `flip` props.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
[
DashIconify(icon="ion:logo-github", width=30, rotate=1, flip="horizontal"),
DashIconify(icon="flat-ui:settings", width=30),
DashIconify(
icon="feather:info",
color=dmc.DEFAULT_THEME["colors"]["yellow"][5],
width=30,
),
]
)
```
### Usage With DMC
Although dash-iconify can be used with any dash components library, be it, dash-mantine-components, dash-core-components
or dash-bootstrap-components, DMC provides direct hooks for adding icons to enhance the look and feel of your apps.
```python
from datetime import date
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
[
dmc.DatePickerInput(
value=date.today(), leftSection=DashIconify(icon="clarity:date-line")
),
dmc.Alert(
icon=DashIconify(icon="radix-icons:cross-circled"),
children="There seems to be an error!",
color="red",
),
dmc.Button(
"Open Settings",
leftSection=DashIconify(icon="carbon:settings-check", width=20),
),
]
)
```
## Dash Loading States
Learn how to show loading states in Dash apps using DMC components like Loader, Skeleton, and LoadingOverlay. Includes integration with dcc.Loading and examples of custom CSS-based spinners.
Category: Dash
### DMC Loading components
DMC has several components that are often used to indicate a component's loading state:
- [Loader](/components/loader): A basic visual spinner (oval, bars, or dots) for simple loading states. Can be customized with size, color, and type.
- [LoadingOverlay](/components/loadingoverlay): Overlays a parent element with a loader, disabling user interaction to indicate a loading state, commonly used for forms.
- [Progress](/components/progress): A progress bar that shows task status and completion percentage. Customizable with value, color, label, and sections.
- [Button](/components/button) and [ActionIcon](/components/actionicon) (`loading` prop): Integrates a `Loader` into buttons and icons. Disables Button while `loading=True`.
- [Skeleton](/components/skeleton): Creates placeholders resembling content layout to give users a preview while loading, reducing perceived wait time.
### With dcc.Loading
For greater control over when the DMC loading components are displayed and for how long, use the `dcc.Loading` component from
`dash-core-components`. DMC components such as `Skeleton`, `Loader`, `LoadingOverlay` can be displayed in the `custom_spinner` prop.
You can configure options such as:
- `delay_show`: Specifies the wait time before displaying the loading component. This helps prevent flickering for fast-loading content.
- `delay_hide`: Defines how long the loading component remains visible after loading completes, creating a smoother transition between the placeholder and final content.
- `target_components`: Determines which components trigger the loader to display. This makes the loading effect triggered only by specific components rather than being triggered by any of the children.
Refer to the [Dash Documentation](https://dash.plotly.com/dash-core-components/loading) for more details.
Here is an example of `delay_hide` prop in `dcc.Loading` to prevent the `Skeleton` from showing for a very short time.
```python
import time
import dash_mantine_components as dmc
from dash import Input, Output, html, callback, dcc
component = html.Div(
[
dcc.Loading(
children=html.Div([
dmc.Text("Initial data", id="dccloading-div"),
dmc.Text("The data only takes 200ms to update, but `delay_hide` is set to 1000ms to prevent flashing.")
]),
delay_hide=1000,
custom_spinner = dmc.Skeleton(
visible=True,
h="100%"
),
),
dmc.Button("Update!", id="dccloading-button"),
]
)
@callback(
Output("dccloading-div", "children"),
Input("dccloading-button", "n_clicks"),
prevent_initial_call=True
)
def update_graph(n):
time.sleep(.2)
return f"Data updated {n} times"
```
### Custom CSS Loaders Using data-dash-is-loading
Dash automatically adds the attribute `data-dash-is-loading="true"` to components that are being updated in a callback.
You can use this attribute to apply custom loading indicators using CSS — no extra Python code or spinner components needed!
#### Basic Example
You can hide a component’s content and display a custom loader using just CSS:
```css
/* Hide the content while it's loading */
[data-dash-is-loading="true"] {
visibility: hidden;
position: relative;
}
/* Show a loader */
[data-dash-is-loading="true"]::before {
content: "Loading...";
visibility: visible;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
```
In your Dash layout:
```python
dmc.Text(id="output-id", className="my-output")
```
In your `assets/style.css`:
```css
.my-output[data-dash-is-loading="true"]::before {
/* Custom loader styles */
}
```
Now, whenever `output-id` is being updated by a callback, your custom loader will appear in place of the original content.
### Example with 3 custom spinners
This example has 3 custom spinner defined in the `.css` file in `/assets`. The different loaders are applied to the
component based on the `className`.
```python
from dash import Input, Output, callback
import dash_mantine_components as dmc
import time
component = dmc.Stack([
dmc.Title(" Dash Spinner Loader Showcase", order=2),
dmc.Card([
dmc.Select(
label="Pulse Loader",
placeholder="Choose an option...",
data=["A", "B", "C"],
id="dash-is-loading-input-1"
),
dmc.Text(id="dash-is-loading-output-1", className="output-example-loading", py="lg")
],
className="pulse-loader",
withBorder=True
),
dmc.Card([
dmc.Select(
label="Ring Loader",
placeholder="Choose an option...",
data=["A", "B", "C"],
id="dash-is-loading-input-2"
),
dmc.Text(id="dash-is-loading-output-2", className="output-example-loading", py="lg")
], className="ring-loader", withBorder=True),
dmc.Card([
dmc.Select(
label="Bounce Loader",
placeholder="Choose an option...",
data=["A", "B", "C"],
id="dash-is-loading-input-3"
),
dmc.Text(id="dash-is-loading-output-3", className="output-example-loading", py="xl")
], className="bounce-loader"),
])
@callback(Output("dash-is-loading-output-1", "children"), Input("dash-is-loading-input-1", "value"))
def update_output1(value):
time.sleep(2)
return f"You selected: {value}"
@callback(Output("dash-is-loading-output-2", "children"), Input("dash-is-loading-input-2", "value"))
def update_output2(value):
time.sleep(2)
return f"You selected: {value}"
@callback(Output("dash-is-loading-output-3", "children"), Input("dash-is-loading-input-3", "value"))
def update_output3(value):
time.sleep(2)
return f"You selected: {value}"
```
```css
/* Output Base Hidden + Loader Target */
.output-example-loading[data-dash-is-loading="true"] {
visibility: hidden;
position: relative;
}
.output-example-loading[data-dash-is-loading="true"]::before {
visibility: visible;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%); /* centers the spinner */
content: "";
}
/* pulse loader */
.pulse-loader .output-example-loading[data-dash-is-loading="true"]::before {
content: "";
width: 20px;
height: 20px;
border-radius: 50%;
background-color: var(--mantine-color-blue-filled);
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) scale(0.95);
animation: pulseAnim 1s infinite ease-in-out;
visibility: visible;
}
@keyframes pulseAnim {
0% { transform: translate(-50%, -50%) scale(0.95); opacity: 1; }
50% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.6; }
100% { transform: translate(-50%, -50%) scale(0.95); opacity: 1; }
}
/* Loader: Ring */
.ring-loader .output-example-loading[data-dash-is-loading="true"]::before {
content: "";
width: 40px;
height: 40px;
border: 4px solid #f3f3f3;
border-top: 4px solid var(--mantine-color-green-filled);
border-radius: 50%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(0deg);
animation: ringSpin 1s linear infinite;
visibility: visible;
}
@keyframes ringSpin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
/* Loader: Bounce Dots */
.bounce-loader .output-example-loading[data-dash-is-loading="true"]::before {
content: "";
display: inline-block;
width: 60px;
height: 16px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.bounce-loader .output-example-loading[data-dash-is-loading="true"]::before {
background: transparent;
}
.bounce-loader .output-example-loading[data-dash-is-loading="true"]::before {
content: "● ● ●";
color: var(--mantine-color-orange-filled);
font-size: 22px;
letter-spacing: 6px;
animation: dotBounce 1.2s infinite ease-in-out;
}
/* Animation for Dots */
@keyframes dotBounce {
0%, 80%, 100% {
opacity: 0.2;
transform: translate(-50%, -50%) scale(0.8);
}
40% {
opacity: 1;
transform: translate(-50%, -50%) scale(1.2);
}
}
```
## Functions as Props
Introduction to using JavaScript functions with Dash Mantine Components
Category: Dash
### How Function Props Work
In JavaScript libraries like [Mantine](https://mantine.dev), some component props accept functions — for example, to
dynamically format a value, render custom content, or control behavior. Here is an example of formating the label of the `Slider`
**In Mantine**
```js
`${value} °C`} />
```
However, in a Dash app, you can’t pass a function to the component because functions don't serialize over the network.
To support this safely, Dash Mantine Components allows you to pass named references to JavaScript functions instead.
You write your function in a `.js` file in the `/assets` folder, and refer to it by name in Python:
**app.py**
```python
dmc.Slider(label={"function": "celsiusLabel"}, value=40)
```
**assets/formatCelsius.js**
```js
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.celsiusLabel = function(value) {
return `${value} °C`;
};
```
DMC knows how to call this function in the browser for props like `label`.
### Example: Formatting a Slider label
See more examples in the [Slider section](/components/slider) section.
```python
import dash_mantine_components as dmc
component = dmc.Slider(label={"function": "celsiusLabel"}, value=40, labelAlwaysOn=True)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.celsiusLabel = (value) => `${value} °C`;
```
### Function Props in Mantine Components
Not all Mantine props accept functions — only specific ones are designed to.
Here are some examples:
* `Slider`: `label`
* `Select`: `renderOption`
* `BarChart`: `getBarColor`
* `ScatterChart`: `valueFormat`
For a full list of supported function props in Dash Mantine Components, see the table at the bottom of this page.
Each function must match the structure expected by Mantine. To learn what arguments each one receives — and how they’re
used — refer to the [Mantine documentation](https://mantine.dev). You’ll also find complete working examples in the relevant sections of the DMC docs.
### Passing Extra Options
You can pass extra options from Python to customize how the JavaScript function behaves.
In this example, the same function can be used to format the label using either Celsius or Fahrenheit.
.py
```python
dmc.Slider(
label={
"function": "formatTemperature",
"options": {"unit": "F"}
},
# other props
)
```
.js
```js
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatTemperature = function (value, { unit }) {
if (unit === "F") {
return `${(value * 9 / 5 + 32).toFixed(1)} °F`;
}
return `${value.toFixed(1)} °C`;
};
```
### Returning a Component
Its also possible to return React components. To do this:
- Use `React.createElement()` (no JSX).
- access DMC components by using `window.dash_mantine_components`.
- If you've imported other component libraries in your Dash app, you can use them too. For example `window.dash_iconify`, `window.dash_core_components`, etc.
See examples of including icons in the dropdown data in the `Select` section of the docs.
### Example: Components and passing extra options
This example shows
- Returning a component. Note the dropdown data is formated as a `Badge`.
- Passing extra options to the JavaScript function. The colors for each badge are passed to the function from the dash app.
```python
import dash_mantine_components as dmc
colors = {
"Pandas": "grape",
"NumPy": "blue",
"Matplotlib": "teal",
"Plotly": "violet",
}
component = dmc.Select(
label="Choose a library",
placeholder="Pick one",
data=list(colors.keys()),
renderOption={
"function": "renderBadge",
"options": {"colors": colors},
},
)
```
```javascript
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.renderBadge = function ({option}, {colors}) {
return React.createElement(
dmc.Badge,
{
color: colors[option.value] || "gray",
variant: "light",
radius: "sm",
},
option.value
);
};
```
### Using Other JavaScript Libraries
You can use third-party JavaScript libraries inside your Dash functions — as long as you include them correctly in your app.
Here is an example of including the `dayjs` library as an external script:
```python
app = Dash(exteral_scripts=["https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.8/dayjs.min.js"])
```
.js
```json
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.excludeDate = function(dateStr) {
const date = dayjs(dateStr, "YYYY-MM-DD");
return date.isValid() && date.day() !== 5;
}
```
### Use AI to Help Write JavaScript
Most Dash users are more comfortable writing Python than JavaScript. You can use AI tools like ChatGPT to generate the
JavaScript functions needed for Dash Mantine Components.
While it's possible to describe the logic in plain English, in practice, writing the function in Python and asking the
AI to translate it tends to produce more accurate and usable results. It gives the model a clear structure and avoids
ambiguity, especially for functions with conditions, formatting rules, or custom output.
#### Prompt Template
When asking AI to generate a function:
1. State the function name.
2. Mention it’s for Dash Mantine Components.
3. Ask it to assign the function to dmcfuncs.functionName.
4. Provide the Python logic (or natural language)
5. Always include this global header:
```
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
```
6. If the function returns a component, mention:
- Use `React.createElement`
- Don’t use JSX
- Use `window.dash_mantine_components`
#### Example 1: Simple function
AI Prompt:
> Write a JavaScript function for Dash Mantine Components named `formatUsd`. Assign it to `dmcfuncs.formatUsd`. In Python, the function would be:
>
> ```python
> def formatUsd(value):
return f"${value:,.2f}"
> ```
AI Output:
```js
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatUsd = function (value) {
return `$${new Intl.NumberFormat("en-US", { minimumFractionDigits: 2 }).format(value)}`;
};
```
#### Example 2 Function with options
AI Prompt:
> Write a JavaScript function for Dash Mantine Components named `formatTemp`. Assign it to `dmcfuncs.formatTemp`. In Python, the function would be:
> ```python
> def formatTemp(value, unit="C"):
> if unit == "F":
> return f"{value * 9 / 5 + 32:.1f} °F"
> return f"{value:.1f} °C"
>```
AI Output:
```js
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
dmcfuncs.formatTemp = function (value, { unit }) {
if (unit === "F") {
return `${(value * 9 / 5 + 32).toFixed(1)} °F`;
}
return `${value.toFixed(1)} °C`;
};
```
---
#### Example 3: Return a Component
AI Prompt
> Write a JavaScript function for Dash Mantine Components named `renderBadge`. Assign it to `dmcfuncs.renderBadge`.
> This function returns a React component. Use `React.createElement`. Do not use JSX. Use `dmc = window.dash_mantine_components`.
> In Python, the function would be:
> ```python
> def renderBadge(option):
> return dmc.Badge(
> option["value"],
> color= "red" if option["value"] == "A" else "blue",
> variant="light",
> radius="sm"
> )
> ```
AI Output
```js
var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {};
var dmc = window.dash_mantine_components;
dmcfuncs.renderBadge = function ({ option }) {
return React.createElement(
dmc.Badge,
{
color: option.value === "A" ? "red" : "blue",
variant: "light",
radius: "sm"
},
option.value
);
};
```
Supported props in V2
The following props support JavaScript functions in Dash Mantine Components version >=2.0.0.
If there’s a Mantine prop you’d like to see added, feel free to [open an issue on GitHub.](https://github.com/snehilvj/dash-mantine-components/issues)
| Component | Props |
|------------------|-------------------------------------------|
| Slider | label, scale |
| RangeSlider | label, scale |
| Select | renderOption, filter |
| MultiSelect | renderOption, filter |
| TagsInput | renderOption, filter |
| DatePickerInput | disabledDates |
| DateInput | disabledDates |
| DateTimePicker | disabledDates |
| MonthPickerInput | disabledDates |
| YearPickerInput | disabledDates |
| BarChart | getBarColor, valueFormatter, tooltipProps |
| AreaChart | valueFormatter, tooltipProps |
| LineChart | valueFormatter, tooltipProps |
| CompositeChart | valueFormatter, tooltipProps |
| BubbleChart | valueFormatter, tooltipProps |
| ScatterChart | valueFormatter, tooltipProps |
Additional Supported props in V2.1.0
| Component | Props |
|------------------|-------------------------------------------------------------------|
| AutoComplete | renderOption, filter |
| DatePickerInput | getYearControlProps, getMonthControlProps, getDayProps, renderDay |
| DateInput | getYearControlProps, getMonthControlProps, getDayProps, renderDay |
| DateTimePicker | getYearControlProps, getMonthControlProps, getDayProps, renderDay |
| MonthPickerInput | getYearControlProps, getMonthControlProps |
| YearPickerInput | getYearControlProps |
| Tree | renderNode |
Additional Supported props in V2.4.0
| Component | Props |
| ------------------------------------------------------------------------- | -------------------------------------------------- |
| AreaChart, BarChart, BubbleChart, CompositeChart, LineChart, ScatterChart | xAxisProps, yAxisProps, gridProps, rightYAxisProps |
| BubbleChart | zAxisProps |
## debounce prop
Learn how to use the debounce prop in Dash Mantine Components to control when input values update. Reduce callback load and improve performance in text inputs, dropdowns, pickers, and more.
Category: Dash
### About the debounce prop
The `debounce` prop delays the update of a component's value until the user stops interacting, reducing callback
frequency for inputs.
To control how often the input's value is updated while the user is typing, use the `debounce` prop:
- `debounce=False` Is the default and it will update as the user interacts with the input.
- Set `debounce=True` to update the value only when the user finishes typing and moves focus away (i.e. on blur).
- Set `debounce=` to update the value after a specified delay from the user's last keystroke. For example,
`debounce=300` will wait 300 milliseconds after the user stops typing before updating the value.
#### debounce=False
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Group(
gap=50,
children=[
dmc.TimePicker(label="Enter a time", id="timepicker-usage"),
dmc.Text(id="out-timepicker")
],
)
@callback(
Output("out-timepicker", "children"),
Input("timepicker-usage", "value")
)
def update(value):
return f"You entered: {value}"
```
#### debounce=True
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Group(
gap=50,
children=[
dmc.TimePicker(
label="Enter a time",
debounce=True,
id="timepicker-debounce"
),
dmc.Text(id="out-timepicker-debounce")
],
)
@callback(
Output("out-timepicker-debounce", "children"),
Input("timepicker-debounce", "value")
)
def update(value):
return f"You entered: {value}"
```
#### debounce=1000
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Group(
gap=50,
children=[
dmc.TimePicker(
label="Enter a time",
debounce=1000,
id="timepicker-debounce-ms"
),
dmc.Text(id="out-timepicker-debounce-ms")
],
)
@callback(
Output("out-timepicker-debounce-ms", "children"),
Input("timepicker-debounce-ms", "value")
)
def update(value):
return f"You entered: {value}"
```
### Example with TextInput
This example uses `debounce=True`. Note that the comments are updated only after the user has
finished entering data.
```python
import dash_mantine_components as dmc
from dash import callback, Input, Output
component = dmc.Stack(
[
dmc.TextInput(
id="debounce-text",
label="Enter your comments",
debounce=True
),
dmc.Text(id="debounce-text-output"),
],
)
@callback(
Output("debounce-text-output", "children"),
Input("debounce-text", "value"),
)
def update_output(comments):
if not comments:
return ""
return f"Thank you for your feedback: {comments}"
```
### Supported Components
The `debounce` prop is supported by many DMC input components, including:
- TextInput
- Textarea
- NumberInput
- PasswordInput
- JsonInput
- Select, MultiSelect, Autocomplete
- DateInput, DateTimePicker, DatePickerInput
- MonthPickerInput, YearPickerInput, TimeInput, TimePicker
- RichTextEditor
For the `Slider` and `RangeSlider` use [updatemode](/components/slider#update-mode)
### Usage Tips
- Use `debounce=True` for forms where you only care about the final value after the user finishes typing, for example, email fields, names, comments.
- Use `debounce=300` or higher for search boxes or filters that trigger live updates (for example, querying a table or filtering a plot). This prevents the app from firing a callback on every keystroke and keeps things responsive.
- Combine with `n_submit` or `n_blur` if you want finer control over when inputs send updates.
## persistence props
Dash Mantine Components support Dash’s built-in persistence system, allowing component values to be retained across page reloads, tabs, or user sessions — without writing extra callbacks.
Category: Dash
### Overview: Persistence in Dash
When a user interacts with a component (like typing in a `TextInput` or selecting a `Date`), its value is
stored in local memory (or optionally, in localStorage or sessionStorage). If the user refreshes the page, navigates
away and returns, or reopens the tab, that value can be restored automatically.
This helps maintain app state with minimal effort.
### How to Enable Persistence
You can enable persistence on any supported component by setting these props:
```python
persistence=True
persisted_props=["value"] # or other prop(s) to persist. Typically use the default.
persistence_type="local" # "local", "session", or "memory" (default is "local")
id="component-id" # required for persistence to work
```
### Example: Persistent TextInput
Try typing something in each box, then refresh the browser to see which one remembers your input.
```python
import dash_mantine_components as dmc
component = dmc.Stack(
[
dmc.TextInput(
id="persisted-input", # id required- persistence only works on components with an id
label="With persistence",
placeholder="This will stick",
persistence=True,
),
dmc.TextInput(
id="non-persisted-input",
label="Without persistence",
placeholder="This will reset",
),
],
)
```
### Important Notes
* In DMC, the `persisted_prop` is already set with an appropriate default for each component, so you don’t need to specify it.
* An `id` is required — persistence will not work without one.
* Due to [an open issue in Dash](https://github.com/plotly/dash/issues/3147), persistence does not work if your layout is simply a list of components. The layout must be a single component (or a function returning one).
This **does work**:
```python
app.layout = dmc.MantineProvider(
dmc.Container([
dmc.Select(id="select", data=["A", "B", "C"], persistence=True)
])
)
```
This **will not work**:
```python
app.layout = dmc.MantineProvider(
[
dmc.Select(id="select", data=["A", "B", "C"], persistence=True)
]
)
```
### Supported DMC Components
Persistence is available for all stateful inputs in DMC — including:
* `TextInput`, `Textarea`, `PasswordInput`, `NumberInput`
* `Select`, `MultiSelect`, `TagsInput`
* `Checkbox`, `RadioGroup`, `Switch`
* `DateInput`, `DateTimePicker`, `TimeInput`, etc.
To check if a specific component supports persistence, look for the `persistence`, `persisted_props`, and
`persistence_type` props in the Keyword Arguments section of its documentation.
### Reference
For more details see the [Persistence section in the Dash documentation.](https://dash.plotly.com/persistence)
- `persistence` (boolean | string | number; optional): Any truthy value will enable persistence for this component. Persistence is keyed to the combination of component id and this persistence value, so if this value changes you will see different persisted settings. For example, perhaps you have dropdowns for country and city, and you know that your users want to see the same country pre-filled as the last time they used your app - you can just set persistence=True on the country dropdown. But for the city they would like to see the same one as the last time they chose that country - just set persistence=country_name (where country_name is the value of the chosen country) on the city dropdown and we'll save one preferred city for each country.
- `persistence_type` ('local', 'session', or 'memory'; default 'local'): Where persisted user changes will be stored:
- `memory`: only kept in memory, reset on page refresh. This is useful for example if you have a tabbed app, that deletes the component when a different tab is active, and you want changes persisted as you switch tabs but not after reloading the app.
- `local`: uses window.localStorage. This is the default, and keeps the data indefinitely within that browser on that computer.
- `session`: uses window.sessionStorage. Like 'local' the data is kept when you reload the page, but cleared when you close the browser or open the app in a new browser tab.
- `persistence_props` (list of strings; optional): These are the props whose values will persist. Typically this defaults to all user-editable props, which in many cases is just one (ie 'value'). dash-table has many props users can edit, and all of them except 'data' are included here by default. Sometimes only a part of a prop is saved; this happens with table headers, which are only part of the columns prop. The corresponding persistence_props value is 'columns.name'.
## Accordion
Use the Accordion and AccordionX components to toggle between hiding and showing large amount of content.
Category: Data Display
### Introduction
### Multiple Items
Set `multiple=True` to enable opening multiple items.
```python
import dash_mantine_components as dmc
dmc.Accordion(
children=[...],
multiple=True
)
```
### Custom Accordion Label
```python
import dash_mantine_components as dmc
from dash import html
characters_list = [
{
"id": "bender",
"image": "https://img.icons8.com/clouds/256/000000/futurama-bender.png",
"label": "Bender Bending Rodríguez",
"description": "Fascinated with cooking, though has no sense of taste",
"content": "Bender Bending Rodríguez, (born September 4, 2996), designated Bending Unit 22, and commonly "
"known as Bender, is a bending unit created by a division of MomCorp in Tijuana, Mexico, "
"and his serial number is 2716057. His mugshot id number is 01473. He is Fry's best friend.",
},
{
"id": "carol",
"image": "https://img.icons8.com/clouds/256/000000/futurama-mom.png",
"label": "Carol Miller",
"description": "One of the richest people on Earth",
"content": "Carol Miller (born January 30, 2880), better known as Mom, is the evil chief executive officer "
"and shareholder of 99.7% of Momcorp, one of the largest industrial conglomerates in the universe "
"and the source of most of Earth's robots. She is also one of the main antagonists of the Futurama "
"series.",
},
{
"id": "homer",
"image": "https://img.icons8.com/clouds/256/000000/homer-simpson.png",
"label": "Homer Simpson",
"description": "Overweight, lazy, and often ignorant",
"content": "Homer Jay Simpson (born May 12) is the main protagonist and one of the five main characters of "
"The Simpsons series(or show). He is the spouse of Marge Simpson and father of Bart, "
"Lisa and Maggie Simpson.",
},
]
def create_accordion_label(label, image, description):
return dmc.AccordionControl(
dmc.Group(
[
dmc.Avatar(src=image, radius="xl", size="lg"),
html.Div(
[
dmc.Text(label),
dmc.Text(description, size="sm", fw=400, c="dimmed"),
]
),
]
)
)
def create_accordion_content(content):
return dmc.AccordionPanel(dmc.Text(content, size="sm"))
component = dmc.Accordion(
chevronPosition="right",
variant="contained",
children=[
dmc.AccordionItem(
[
create_accordion_label(
character["label"], character["image"], character["description"]
),
create_accordion_content(character["content"]),
],
value=character["id"],
)
for character in characters_list
],
)
```
### Customizing chevron
You can use [dash-iconify](/dash-iconify) to change the chevron icon.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
dmc.Accordion(
chevron=DashIconify(icon="ant-design:plus-outlined"),
disableChevronRotation=True,
children=[...]
)
```
### With icons
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Accordion(
disableChevronRotation=True,
children=[
dmc.AccordionItem(
[
dmc.AccordionControl(
"Personal Information",
icon=DashIconify(
icon="tabler:user",
color="var(--mantine-color-blue-6)",
width=20,
),
),
dmc.AccordionPanel("some content"),
],
value="info",
),
dmc.AccordionItem(
[
dmc.AccordionControl(
"Shipping Address",
icon=DashIconify(
icon="tabler:map-pin",
color= "var(--mantine-color-red-6)",
width=20,
),
),
dmc.AccordionPanel("some content"),
],
value="addr",
),
dmc.AccordionItem(
[
dmc.AccordionControl(
"Confirmation",
icon=DashIconify(
icon="tabler:circle-check",
color= "var(--mantine-color-green-6)",
width=20,
),
),
dmc.AccordionPanel("some content"),
],
value="focus",
),
],
)
```
### Change transition
```python
import dash_mantine_components as dmc
dmc.Accordion(
children=[...],
transitionDuration=1000
)
```
### Default opened items
Provide a default value using the `value` prop.
```python
import dash_mantine_components as dmc
dmc.Accordion(
children=[...],
value="flexibility"
)
```
If `multiple` is `True`, then value will be a list:
```python
import dash_mantine_components as dmc
dmc.Accordion(
children=[...],
value=["flexibility", ]
)
```
```python
import dash_mantine_components as dmc
component = dmc.Accordion(
value=["flexibility"],
multiple=True,
children=[
dmc.AccordionItem(
[
dmc.AccordionControl("Customization"),
dmc.AccordionPanel(
"Colors, fonts, shadows and many other parts are customizable to fit your design needs"
),
],
value="customization",
),
dmc.AccordionItem(
[
dmc.AccordionControl("Flexibility"),
dmc.AccordionPanel(
"Configure temp appearance and behavior with vast amount of settings or overwrite any part of "
"component styles "
),
],
value="flexibility",
),
],
)
```
### Callbacks and State Management
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback
component = html.Div(
children=[
dmc.Accordion(
id="accordion-simple",
value="customization",
children=[
dmc.AccordionItem(
[
dmc.AccordionControl("Customization"),
dmc.AccordionPanel(
"Colors, fonts, shadows and many other parts are customizable to fit your design needs"
),
],
value="customization",
),
dmc.AccordionItem(
[
dmc.AccordionControl("Flexibility"),
dmc.AccordionPanel(
"Configure temp appearance and behavior with vast amount of settings or overwrite any "
"part of component styles "
),
],
value="flexibility",
),
],
),
dmc.Text(id="accordion-state", mt=10),
]
)
@callback(Output("accordion-state", "children"), Input("accordion-simple", "value"))
def show_state(value):
return value
```
### Compose control
You can add any additional elements that will be displayed next to `AccordionControl`, for example, you can add `ActionIcon` or `Menu`.
This enables interaction with the element without affecting the opening or closing of the accordion item. In this
example, try clicking the heart icon.
```python
import dash_mantine_components as dmc
from dash import Output, Input, html, callback, MATCH
from dash_iconify import DashIconify
def make_control(text, action_id):
return dmc.Flex(
[
dmc.AccordionControl(text),
dmc.ActionIcon(
children=DashIconify(icon="tabler:heart"),
color="yellow",
variant="default",
n_clicks=0,
id={"index": action_id},
),
],
justify="space-between",
)
component = dmc.Accordion(
id="accordion-compose-controls",
chevronPosition="left",
children=[
dmc.AccordionItem(
[
make_control(f"Item {i}", f"action-{i}"),
dmc.AccordionPanel(f"Content for AccordionItem {i}"),
],
value=f"item-{i}",
)
for i in range(5)
],
)
@callback(Output({"index": MATCH}, "variant"), Input({"index": MATCH}, "n_clicks"))
def update_heart(n):
if n % 2 == 0:
return "default"
return "filled"
```
### Disable collapse
By default, in single mode (`multiple=False`) the open item can always be toggled closed, which leaves the `Accordion`
fully collapsed. Set the `disableCollapse` prop to prevent this: once an item is open, clicking its control again is
a no-op, and the only way to change state is to open a different item. This is useful for settings panels, stepper-style
flows and FAQ pages where one section should always stay visible.
`disableCollapse` only prevents collapsing an already-open item – it does not force an item open on mount. To guarantee
that one item is open from the start, set the `value` prop.
The prop has no effect when multiple is set, as multiple mode already allows any combination of opened and closed items.
```python
import dash_mantine_components as dmc
data = [
{
"emoji": "🍎",
"value": "Apples",
"description": "Crisp and refreshing fruit. Apples are known for their versatility and nutritional benefits. They come in a variety of flavors and are great for snacking, baking, or adding to salads.",
},
{
"emoji": "🍌",
"value": "Bananas",
"description": "Naturally sweet and potassium-rich fruit. Bananas are a popular choice for their energy-boosting properties and can be enjoyed as a quick snack, added to smoothies, or used in baking.",
},
{
"emoji": "🥦",
"value": "Broccoli",
"description": "Nutrient-packed green vegetable. Broccoli is packed with vitamins, minerals, and fiber. It has a distinct flavor and can be enjoyed steamed, roasted, or added to stir-fries.",
},
]
component = dmc.Accordion(
[
dmc.AccordionItem(
[
dmc.AccordionControl(item["value"], icon=item["emoji"]),
dmc.AccordionPanel(item["description"]),
],
value=item["value"],
)
for item in data
],
value="Apples",
disableCollapse=True,
order=3,
)
```
### Disabled Item
Set `disabled=True` in dmc.AccordionControl to disable it.
```python
import dash_mantine_components as dmc
dmc.AccordionControl(children=[...], disabled=True)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Accordion selectors
| Selector | Static selector | Description |
|------------|---------------------------------|------------------------------------------------|
| root | .mantine-Accordion-root | Root element |
| item | .mantine-Accordion-item | Accordion.Item root element |
| control | .mantine-Accordion-control | Accordion.Control root element |
| chevron | .mantine-Accordion-chevron | Accordion.Control chevron container element |
| label | .mantine-Accordion-label | Accordion.Control label |
| icon | .mantine-Accordion-icon | Accordion.Control icon |
| itemTitle | .mantine-Accordion-itemTitle | Accordion.Control title (h2-h6) tag |
| panel | .mantine-Accordion-panel | Accordion.Panel root element |
| content | .mantine-Accordion-content | Wrapper element of Accordion.Panel children |
#### Accordion CSS variables
| Selector | Variable | Description |
|----------|----------------------------------|----------------------------------------------------------------|
| root | --accordion-chevron-size | Controls chevron container element width and min-width |
| | --accordion-radius | Controls border-radius in various elements, depending on variant |
| | --accordion-transition-duration | Controls all animations' transition-duration |
#### Accordion data attributes
| Selector | Attribute | Condition | Value |
|---------------|-------------------------|-------------------------|-----------------------------------------|
| item, control | data-active | Item is active (opened) | – |
| control | data-chevron-position | – | Value of `chevronPosition` prop on Accordion |
### Keyword Arguments
#### Accordion
- children (a list of or a singular dash component, string or number; required):
Accordion content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- chevron (a list of or a singular dash component, string or number; optional):
Custom chevron icon that will be used in all items.
- chevronIconSize (string | number; optional):
Size of the default chevron icon. Ignored when `chevron` prop is
set. default `16`.
- chevronPosition (a value equal to: 'left', 'right'; optional):
Position of the chevron relative to the item label, `right` by
default.
- chevronSize (string | number; optional):
Size of the chevron icon container, `24` by default.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- disableChevronRotation (boolean; optional):
Determines whether chevron rotation should be disabled, `False` by
default.
- disableCollapse (boolean; optional):
If set, the open item cannot be collapsed by clicking it again, so
one item always stays open. Only applies when `multiple` is
`False`. default False.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- keepMounted (boolean; optional):
If set to `False`, panels are unmounted when collapsed. By
default, panels stay mounted when collapsed. default True.
- keepMountedMode (a value equal to: 'activity', 'display-none'; optional):
Controls how inactive panels content is hidden when `keepMounted`
is `True`, `'activity'` – hidden with `Activity` component,
`'display-none'` – hidden with `display: none` styles default
'activity'.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- loop (boolean; optional):
Determines whether arrow key presses should loop though items
(first to last and last to first), `True` by default.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- multiple (boolean; optional):
Determines whether multiple items can be opened at a time, `False`
by default.
- order (a value equal to: 2, 3, 4, 5, 6; optional):
Heading order, has no effect on visuals.
- persisted_props (list of strings; optional):
Properties whose user interactions will persist after refreshing
the component or the page. Since only `value` is allowed this prop
can normally be ignored.
- persistence (string | number | boolean; optional):
Used to allow user interactions in this component to be persisted
when the component - or the page - is refreshed. If `persisted` is
truthy and hasn't changed from its previous value, a `value` that
the user has changed while using the app will keep that change, as
long as the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`. Note: The component
must have an `id` for persistence to work.
- persistence_type (a value equal to: 'local', 'session', 'memory'; optional):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data
is cleared once the browser quit.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius.
Numbers are converted to rem. `theme.defaultRadius` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- transitionDuration (number; optional):
Transition duration in ms, `200` by default.
- value (string | list of strings; optional):
Value for controlled component.
- variant (a value equal to: 'default', 'contained', 'filled', 'separated'; optional):
Controls visuals.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### AccordionControl
- children (a list of or a singular dash component, string or number; optional):
Control label.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- chevron (a list of or a singular dash component, string or number; optional):
Custom chevron icon.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- disabled (boolean; optional):
Disables control button.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- icon (a list of or a singular dash component, string or number; optional):
Icon displayed next to the label.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### AccordionItem
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- value (string; required):
Value that is used to manage accordion state.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### AccordionPanel
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- keepMounted (boolean; optional):
If set, overrides the Accordion-level `keepMounted` value. When
undefined (default), uses Accordion's `keepMounted` setting.
- keepMountedMode (a value equal to: 'activity', 'display-none'; optional):
If set, overrides the Accordion-level `keepMountedMode` value.
When undefined (default), uses Accordion's `keepMountedMode`
setting.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Avatar
Use Avatar to display user profile pictures. It supports images, icons, or letters. Use AvatarGroup to display stack Avatar components.
Category: Data Display
### Simple Usage
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
children=[
dmc.Avatar(
src="https://avatars.githubusercontent.com/u/91216500?v=4", radius="xl"
),
# default placeholder
dmc.Avatar(radius="xl"),
# initials
dmc.Avatar("MK", color="cyan", radius="xl"),
# icon
dmc.Avatar(DashIconify(icon="radix-icons:star"), color="blue", radius="xl"),
],
)
```
### Initials
To display initials instead of the default placeholder, set name prop to the name of the person, for example,
`name='John Doe'`. If the name is set, you can use `color='initials'` to generate color based on the name:
```python
import dash_mantine_components as dmc
names = [
"John Doe",
"Jane Mol",
"Alex Lump",
"Sarah Condor",
"Mike Johnson",
"Kate Kok",
"Tom Smith",
]
avatars = [dmc.Avatar(name=name, color="initials") for name in names]
component = dmc.Group(avatars)
```
### Allowed initials colors
By default, all colors from the default theme are allowed for initials, you can restrict them by providing
`allowedInitialsColors` prop with an array of colors. Note that the default colors array does not include custom
colors defined in the theme, you need to provide them manually if needed.
```python
import dash_mantine_components as dmc
names = [
"John Doe",
"Jane Mol",
"Alex Lump",
"Sarah Condor",
"Mike Johnson",
"Kate Kok",
"Tom Smith",
]
component = dmc.Group(
[
dmc.Avatar(name=n, color="initials", allowedInitialsColors=["blue", "red"])
for n in names
]
)
```
### Size, Radius and Variant
Control Avatar's height and width with `size` prop and border-radius with `radius` prop. Both props have
predefined values: xs, sm, md, lg, xl. Alternatively, a number can be used to set radius or size in px.
You can also use `variant` to style the Avatar.
```python
import dash_mantine_components as dmc
dmc.Avatar(src="/assets/avatar.jpeg", size="sm"),
dmc.Avatar(src="/assets/avatar.jpeg"),
dmc.Avatar(src="/assets/avatar.jpeg", size=50, radius="xl"),
dmc.Avatar(src="/assets/avatar.jpeg", size="xl", radius=20),
dmc.Avatar(src="/assets/avatar.jpeg", size="xl", variant="outline"),
```
### Avatar Group
Use AvatarGroup to stack Avatar components.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.AvatarGroup(
children=[
dmc.Avatar(
src="https://avatars.githubusercontent.com/u/91216500?v=4", radius="xl"
),
dmc.Avatar(
src="https://avatars.githubusercontent.com/u/24227892?v=4", radius="xl"
),
dmc.Avatar(radius="xl"),
dmc.Avatar("MK", color="cyan", radius="xl"),
dmc.Avatar(DashIconify(icon="radix-icons:star"), color="blue", radius="xl"),
],
)
```
### Avatar link with tooltip
```python
import dash_mantine_components as dmc
from dash import html
component = html.A(
dmc.Tooltip(
dmc.Avatar(
src="https://e7.pngegg.com/pngimages/799/987/png-clipart-computer-icons-avatar-icon-design-avatar-heroes"
"-computer-wallpaper-thumbnail.png",
size="lg",
radius="xl",
),
label="Snehil Vijay",
position="bottom",
),
href="https://www.linkedin.com/in/snehilvj/",
target="_blank",
)
```
### Dynamically created AvatarGroup
Here's an example of a dynamically created AvatarGroup from GitHub contributors to DMC library.
```python
from os import environ
import dash_mantine_components as dmc
import requests
def create_contributors_list():
resp = requests.get(
"https://api.github.com/repos/snehilvj/dash-mantine-components/contributors",
headers={"authorization": f"token {environ['CONTRIB_TOKEN']}"},
)
contributors = resp.json()
children = []
for user in contributors:
avatar = dmc.Avatar(src=user["avatar_url"], radius="xl")
children.append(avatar)
return dmc.AvatarGroup(children, id="avatar-group")
component = create_contributors_list() if "CONTRIB_TOKEN" in environ else None
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:----------------|:--------------------------------|:----------------------------------------------------------|
| root | .mantine-Avatar-root | Root element |
| image | .mantine-Avatar-image | `img` element |
| placeholder | .mantine-Avatar-placeholder | Placeholder element, rendered when image cannot be loaded |
### Keyword Arguments
#### Avatar
- children (a list of or a singular dash component, string or number; optional):
Avatar placeholder, displayed when `src={None}` or when the image
cannot be loaded.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- allowedInitialsColors (list; optional):
An array of colors that can be used for autogenerated initials. By
default, all default Mantine colors can be used except gray and
dark.
- alt (string; optional):
Image `alt` attribute, also used as `title` attribute for
placeholder.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether text color with filled variant should depend on
`background-color`. If luminosity of the `color` prop is less than
`theme.luminosityThreshold`, then `theme.white` will be used for
text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color, default value is
`theme.primaryColor`. Set to "initials" to auto generate color
based on `name`.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- gradient (dict; optional):
Gradient configuration used when `variant="gradient"`, default
value is `theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- imageProps (dict; optional):
`img` tag attributes.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- name (string; optional):
Name of the user. When src is not set, used to display initials
and to generate color when color="initials" is set.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius,
`'100%'` by default.
- size (number; optional):
Width and height of the avatar, numbers are converted to rem,
`'md'` by default.
- src (string; optional):
Image url, if the image cannot be loaded or `src={None}`, then
placeholder is displayed instead.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### AvatarGroup
- children (a list of or a singular dash component, string or number; optional):
components.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- spacing (number; optional):
Negative space between Avatar components, `'sm'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Badge
Use Badges to show indicators, numerical or otherwise.
Category: Data Display
### Introduction
### Variants
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Badge("Default light badge"),
dmc.Badge("Dot badge", variant="dot"),
dmc.Badge("Outline badge", variant="outline"),
dmc.Badge("Filled badge", variant="filled"),
]
)
```
### Colors
```python
import dash_mantine_components as dmc
dmc.Badge("Orange", color="orange")
```
### Gradient variant
```python
import dash_mantine_components as dmc
component = dmc.Group(
children=[
dmc.Badge(
"Indigo cyan",
variant="gradient",
gradient={"from": "indigo", "to": "cyan"},
),
dmc.Badge(
"Lime green",
variant="gradient",
gradient={"from": "teal", "to": "lime", "deg": 105},
),
dmc.Badge(
"Teal blue",
variant="gradient",
gradient={"from": "teal", "to": "blue", "deg": 60},
),
dmc.Badge(
"Orange red",
variant="gradient",
gradient={"from": "orange", "to": "red"},
),
dmc.Badge(
"Grape pink",
variant="gradient",
gradient={"from": "grape", "to": "pink", "deg": 35},
),
]
)
```
### Size
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Badge("Sale", size="xs"),
dmc.Badge("Sale", size="sm"),
dmc.Badge("Sale", size="md"),
dmc.Badge("Sale", size="lg"),
dmc.Badge("Sale", size="xl"),
]
)
```
### Radius
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Badge("Sale", radius="xs"),
dmc.Badge("Sale", radius="sm"),
dmc.Badge("Sale", radius="md"),
dmc.Badge("Sale", radius="lg"),
dmc.Badge("Sale", radius="xl"),
]
)
```
### Rounded
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Badge(1, size="xs", circle=True),
dmc.Badge(7, size="sm", circle=True),
dmc.Badge(9, size="md", circle=True),
dmc.Badge(3, size="lg", circle=True),
dmc.Badge(8, size="xl", circle=True),
]
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:-------------|:----------------------------|:------------------------|
| root | .mantine-Badge-root | Root element |
| label | .mantine-Badge-label | Badge children |
| section | .mantine-Badge-section | Left and right sections |
### Keyword Arguments
#### Badge
- children (a list of or a singular dash component, string or number; optional):
Main badge content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether text color with filled variant should depend on
`background-color`. If luminosity of the `color` prop is less than
`theme.luminosityThreshold`, then `theme.white` will be used for
text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- circle (boolean; optional):
If set, badge `min-width` becomes equal to its `height` and
horizontal padding is removed.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color, `theme.primaryColor`
by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- fullWidth (boolean; optional):
Determines whether Badge should take 100% of its parent width,
`False` by default.
- gradient (dict; optional):
Gradient configuration used when `variant="gradient"`, default
value is `theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- leftSection (a list of or a singular dash component, string or number; optional):
Content displayed on the left side of the badge label.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, `'xl'` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content displayed on the right side of the badge label.
- size (optional):
Controls `font-size`, `height` and horizontal `padding`, `'md'` by
default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Card
Use Card component to hold anything from images to headlines, supporting text, buttons, lists, etc. in a contained unit.
Category: Data Display
### Simple Example
Card component is a wrapper around Paper component with styles for CardSection component.
```python
import dash_mantine_components as dmc
component = dmc.Card(
children=[
dmc.CardSection(
dmc.Image(
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-8.png",
h=160,
alt="Norway",
)
),
dmc.Group(
[
dmc.Text("Norway Fjord Adventures", fw=500),
dmc.Badge("On Sale", color="pink"),
],
justify="space-between",
mt="md",
mb="xs",
),
dmc.Text(
"With Fjord Tours you can explore more of the magical fjord landscapes with tours and activities on and "
"around the fjords of Norway",
size="sm",
c="dimmed",
),
dmc.Button(
"Book classic tour now",
color="blue",
fullWidth=True,
mt="md",
radius="md",
),
],
withBorder=True,
shadow="sm",
radius="md",
w=350,
)
```
### Horizontal Orientation
```python
import dash_mantine_components as dmc
completed = 1887
total = 2334
stats = [
{"value": 447, "label": "Remaining"},
{"value": 76, "label": "In progress"},
]
items = [
dmc.Box([
dmc.Text(stat["value"]),
dmc.Text(stat["label"], size="xs", c="dimmed"),
])
for stat in stats
]
component = dmc.Card(
[
dmc.CardSection(
dmc.RingProgress(
roundCaps=True,
thickness=6,
size=150,
sections=[
{
"value": (completed / total) * 100,
"color": "blue",
}
],
label=dmc.Box([
dmc.Text(
f"{((completed / total) * 100):.0f}%",
ta="center",
fz="lg",
),
dmc.Text(
"Completed",
ta="center",
fz="xs",
c="dimmed",
),
]),
),
inheritPadding=True,
px="xs",
withBorder=True,
),
dmc.CardSection(
[
dmc.Text("Project tasks", fz="xl"),
dmc.Box(
[
dmc.Text("1887"),
dmc.Text("Completed", fz="xs", c="dimmed"),
],
mt="xs",
),
dmc.Group(items, mt="sm"),
],
inheritPadding=True,
px="md",
withBorder=True,
ml="lg"
),
],
padding="sm",
withBorder=True,
orientation="horizontal",
w=400
)
```
### Card Section
CardSection is a special component that is used to remove Card padding from its children while other elements still have horizontal spacing. CardSection works the following way:
1. If component is a first child in Card then it has negative top, left and right margins.
2. If it is a last child in Card then it has negative bottom, left and right margins.
3. If it is in the middle then only left and right margins will be negative.
##### Border and Padding in CardSection
`withBorder` property will add top and bottom border to CardSection depending on its position relative to other content and sections.
`inheritPadding` property will add the same left and right padding to CardSection as set in Card component.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
urls = [
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-1.png",
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-2.png",
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-3.png",
]
images = [dmc.Image(radius="sm", src=url) for url in urls]
component = dmc.Card(
children=[
dmc.CardSection(
dmc.Group(
children=[
dmc.Text("Review Pictures", fw=500),
dmc.ActionIcon(
DashIconify(icon="carbon:overflow-menu-horizontal"),
color="gray",
variant="transparent",
),
],
justify="space-between",
),
withBorder=True,
inheritPadding=True,
py="xs",
),
dmc.Box(
children=[
dmc.Text(
"200+ images uploaded",
c="blue",
style={"display": "inline"},
),
" since last visit, review them to select which one should be added to your gallery",
],
mt="sm",
c="dimmed",
),
dmc.CardSection(
dmc.Image(
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-4.png",
mt="sm",
),
),
dmc.CardSection(
children=[
dmc.SimpleGrid(cols=3, children=[i for i in images]),
],
inheritPadding=True,
mt="sm",
pb="md",
),
],
withBorder=True,
shadow="sm",
radius="md",
w=350,
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:--------|:----------------------|:----------------------------|
| root | .mantine-Card-root | Root element |
| section | .mantine-Card-section | `Card.Section` root element |
### Keyword Arguments
#### Card
- children (a list of or a singular dash component, string or number; optional):
Card content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Card orientation @,default,'vertical'.
- padding (number; optional):
Controls `padding`, key of `theme.spacing` or any valid CSS value,
`'md'` by default.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius,
numbers are converted to rem, `theme.defaultRadius` by default.
- shadow (optional):
Key of `theme.shadows` or any valid CSS value to set `box-shadow`,
`none` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBorder (boolean; optional):
Determines whether the card should have border, border color
depends on color scheme, `False` by default.
#### CardSection
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- inheritPadding (boolean; optional):
Determines whether the section should inherit padding from the
parent `Card`, `False` by default.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBorder (boolean; optional):
Determines whether the section should have a border, `False` by
default.
## Carousel
Use the Carousel component to cycle through elements like a slideshow.
Category: Data Display
### CSS Extensions
As of DMC 1.2.0, `Carousel` component styles are bundled automatically, so you no longer need to include a separate CSS file.
If you're using an older version of DMC, refer to the [migration guide](/migration) for instructions on including optional stylesheets.
### Simple Example
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center("Slide-1", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-2", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-3", bg="blue", c="white", p=60)),
],
id="carousel-simple",
)
```
### Options
### Size and Gap
Set `slideSize` and `slideGap` on `Carousel` component to control size and gap of every slide:
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center(f"Slide {i}", bg="blue", c="white", h="100%"))
for i in range(1, 7)
],
id="carousel-size",
withIndicators=True,
height=200,
slideSize="33.3333%",
slideGap="md",
emblaOptions = {"loop": True, "align": "start", "slidesToScroll": 3},
)
```
### Responsive styles
`slideSize` and `slideGap` props work the same way as `style` props, you can pass an object with values for different breakpoints:
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(
dmc.Center(f"Slide {i}", ta="center", bg="blue", c="white", h="100%")
)
for i in range(1, 7)
],
id="carousel-responsive",
withIndicators=True,
height=200,
slideSize={"base": "100%", "sm": "50%", "md": "33.333333%"},
slideGap={"base": 0, "sm": "md"},
emblaOptions = {"loop": True, "align": "start"},
)
```
### Drag free
`dragFree` will disable slides snap points – user will be able to stop dragging at any position:
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(
dmc.Center(f"Slide {i}", ta="center", bg="blue", c="white", h="100%")
)
for i in range(1, 7)
],
id="carousel-drag-free",
withIndicators=True,
height=200,
slideGap="md",
emblaOptions = {"loop": True, "align": "start", "dragFree": True},
)
```
### Vertical orientation
Carousel with `orientation="vertical"` requires `height` prop to be set:
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(
dmc.Center(f"Slide {i}", ta="center", bg="blue", c="white", h="100%")
)
for i in range(1, 7)
],
id="carousel-vertical",
orientation="vertical",
withIndicators=True,
height=200,
emblaOptions={"loop": True},
)
```
### Controls icons
You can replace default next/previous controls icons with any component:
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Carousel(
[
dmc.CarouselSlide(
dmc.Center(f"Slide {i}", ta="center", bg="blue", c="white", h="100%")
)
for i in range(1, 7)
],
id="carousel-controls_icons",
withIndicators=True,
height=180,
nextControlIcon=DashIconify(icon="bi:arrow-right-circle-fill", width=30),
previousControlIcon=DashIconify(icon="bi:arrow-left-circle-fill", width=30),
emblaOptions = {"loop": True},
)
```
### Autoscroll
Enable autoscroll by setting `autoScroll=True` or by passing in a `dict` with options. Refer to [Embla Carousel Auto Scroll Options](https://www.embla-carousel.com/plugins/auto-scroll/#options) to learn more.
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center("Slide-1", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-2", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-3", bg="blue", c="white", p=60)),
],
id="carousel-autoscroll",
emblaOptions={"loop": True},
autoScroll=True,
)
```
### Autoplay
Enable autoplay by setting `autoplay=True` or by passing in a `dict` with options. Refer to [Embla Carousel Autoplay Options](https://www.embla-carousel.com/plugins/autoplay/#options) to learn more.
```python
import dash
import dash_mantine_components as dmc
from dash import html, callback, Input, Output
component = html.Div([
dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center("Slide-1", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-2", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-3", bg="blue", c="white", p=60)),
],
id="carousel-autoplay",
mt="sm",
emblaOptions={"loop": True},
autoplay=True, # Default delay is 4000ms
)
])
```
Here’s an example of passing props to the Embla component. In this example, the `delay` is set to 2000ms, and autoplay pauses when hovering over a slide:
```python
autoplay={"delay": 2000, "stopOnMouseEnter": True, "stopOnInteraction":False}
```
### Carousel Styles API
Carousel supports Styles API, you can add styles to any inner element of the component with `classNames` prop. Refer to the [Styles API documentation](/styles-api) to learn more.
### Carousel Indicator styles
This example styles the indicators to emphasize the active slide.
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center(f"Slide {i}", bg="blue", c="white", h="100%"))
for i in range(1, 4)
],
id="carousel-indicator-styles",
withIndicators=True,
height=200,
emblaOptions = {"loop": True},
classNames={"indicator": "dmc-indicator"},
)
```
Put the following in a .css file in the `assets` folder:
```css
.dmc-indicator {
width: 12px;
height: 4px;
transition: width 250ms ease;
&[data-active] {
width: 40px;
}
}
```
### Hide inactive controls
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center(f"Slide {i}", bg="blue", c="white", h="100%"))
for i in range(1, 4)
],
id="carousel-hide-inactive-controls",
height=200,
classNames={"control": "dmc-control"},
)
```
Put the following in a .css file in the `assets` folder:
```css
.dmc-control {
&[data-inactive] {
opacity: 0;
cursor: default;
}
}
```
### Show controls on hover
```python
import dash_mantine_components as dmc
component = dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center(f"Slide {i}", bg="blue", c="white", h="100%"))
for i in range(1, 4)
],
id="carousel-show-controls-on-hover",
height=200,
classNames={"controls": "dmc-controls", "root": "dmc-root"},
)
```
Put the following in a .css file in the `assets` folder:
```css
.dmc-controls {
transition: opacity 150ms ease;
opacity: 0;
}
.dmc-root {
&:hover {
.dmc-controls {
opacity: 1;
}
}
}
```
### Set initial slide
To set the initial slide to display, use the index number of the slide.
```python
import dash_mantine_components as dmc
from dash import Input, Output, callback, no_update
component = dmc.Paper(
[
dmc.Select(
label="Set initial slide",
data=[str(i) for i in range(6)],
value="0",
id="carousel-input",
mb=10,
),
dmc.Carousel(
[
dmc.CarouselSlide(
dmc.Center(
f"Slide {i}", ta="center", bg="blue", c="white", h="100%"
)
)
for i in range(6)
],
id="carousel-initial",
height=200,
emblaOptions = {"loop": True, "align": "start"},
),
]
)
@callback(
Output("carousel-initial", "initialSlide"),
Input("carousel-input", "value"),
)
def go_to_slide(value):
return int(value)
```
### Container queries
To use container queries instead of media queries, set `type="container"`. With container queries, slides size and gap
will be adjusted based on the container width, not the viewport width.
Note that, when using container queries, `slideSize` and `slideGap` props cannot reference `theme.breakpoints` values
in keys. It is required to use exact `px` or `em` values.
To see how the slides size and gap changes, resize the root element of the demo with the resize handle located at the
bottom right corner of the demo:
```python
import dash_mantine_components as dmc
from dash import html
component = html.Div(
# Wrapper div is added for demonstration purposes only,
# It is not required in real projects
dmc.Carousel(
[
dmc.CarouselSlide(dmc.Center("Slide-1", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-2", bg="blue", c="white", p=60)),
dmc.CarouselSlide(dmc.Center("Slide-3", bg="blue", c="white", p=60)),
],
id="carousel-container",
type="container",
slideSize = {"base": '100%', '300px': '50%', '500px': '33.333333%'},
slideGap = {"base": 0, '300px': 'md', '500px': 'lg'},
emblaOptions = {"loop": True, "align": "start"},
),
style={
"resize": 'horizontal',
"overflow": 'hidden',
"maxWidth": '100%',
"minWidth": 250,
"padding": 10,
}
)
```
### Active prop for callbacks
The `active` prop represents the index of the currently displayed slide and can be used to trigger Dash callbacks. Note
that this prop is read-only. To set the initially displayed slide, use the `initialSlide` prop instead.
### Example Image Carousel
```python
import dash_mantine_components as dmc
images = [
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-1.png",
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-2.png",
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-3.png",
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-4.png",
"https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-5.png",
]
component = dmc.Carousel(
[dmc.CarouselSlide(dmc.Image("Slide 1", src=image)) for image in images],
id="carousel-images",
withIndicators=True,
w=400,
)
```
### Example Card Carousel
```python
import dash_mantine_components as dmc
from dash import html
data = [
{
"image": "https://images.unsplash.com/photo-1508193638397-1c4234db14d8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=400&q=80",
"title": "Best forests to visit in North America",
"category": "NATURE",
},
{
"image": "https://images.unsplash.com/photo-1559494007-9f5847c49d94?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=400&q=80",
"title": "Hawaii beaches review: better than you think",
"category": "BEACH",
},
{
"image": "https://images.unsplash.com/photo-1608481337062-4093bf3ed404?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=400&q=80",
"title": "Mountains at night: 12 best locations to enjoy the view",
"category": "NATURE",
},
{
"image": "https://images.unsplash.com/photo-1510798831971-661eb04b3739?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=400&q=80",
"title": "Best places to visit this winter",
"category": "TOURISM",
},
{
"image": "https://images.unsplash.com/photo-1582721478779-0ae163c05a60?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=400&q=80",
"title": "Active volcanos reviews: travel at your own risk",
"category": "NATURE",
},
]
def make_card(image, title, category):
return dmc.Paper(
[
html.Div(
[
dmc.Text(category, c="white", opacity=0.7, fw=700),
dmc.Title(title, lh=1.2, order=3, mt="xs", fw=900, c="white"),
]
),
dmc.Button("Read Article", variant="white", color="dark"),
],
shadow="md",
p="xl",
radius="md",
style={
"backgroundImage": f"url({image})",
"height": 440,
"display": "flex",
"flexDirection": "column",
"justifyContent": "space-between",
"alignItems": "flex-start",
"backgroundSize": "cover",
"backgroundPosition": "center",
},
)
component = dmc.Carousel(
[dmc.CarouselSlide(make_card(d["image"], d["title"], d["category"])) for d in data],
id="carousel-cards",
w=400,
emblaOptions={"loop": True, "align": "start"},
)
```
### Limitation: Carousel in Tabs
When a Carousel is placed inside a tab, it may not render correctly. For more details, refer to [GitHub Issue #299]((https://github.com/snehilvj/dash-mantine-components/issues/299).
As a workaround, you can update the carousel within the tabs using a callback.
Be sure to give a unique id to each carousel in the app.
```python
import dash_mantine_components as dmc
from dash import html, Input, Output, callback
def make_carousel(id):
return dmc.Carousel(
emblaOptions={"loop": True},
withIndicators=True,
children=[
dmc.CarouselSlide(
dmc.Center(
slide,
bg="blue",
c="white",
p=60,
)
)
for slide in ["Slide 1", "Slide 2", "Slide 3"]
],
id=id,
)
component = html.Div(
[
dmc.Tabs(
[
dmc.TabsList(
[
dmc.TabsTab("Tab one", value="1"),
dmc.TabsTab("Tab two", value="2"),
]
),
],
id="tabs-carousel-example",
value="1",
),
html.Div(id="tabs-carousel-content", style={"paddingTop": 10}),
]
)
@callback(
Output("tabs-carousel-content", "children"), Input("tabs-carousel-example", "value")
)
def render_content(active):
if active == "1":
return [dmc.Text("Tab One selected", my=10), make_carousel("carousel-tab1")]
else:
return [dmc.Text("Tab Two selected", my=10), make_carousel("carousel-tab2")]
```
### Limitation: draggable and speed Props
As of DMC v0.14.7, the `draggable` and `speed` props no longer work because Embla Carousel v8 has removed them. These props
will be removed in DMC v1.0.0
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Carousel selectors
| Selector | Static selector | Description |
|------------|------------------------------|----------------------------------------------------------|
| root | .mantine-Carousel-root | Root element |
| slide | .mantine-Carousel-slide | Carousel.Slide root element |
| container | .mantine-Carousel-container | Slides container |
| viewport | .mantine-Carousel-viewport | Main element, contains slides container and all controls |
| controls | .mantine-Carousel-controls | Next/previous controls container |
| control | .mantine-Carousel-control | Next/previous control |
| indicators | .mantine-Carousel-indicators | Indicators container |
| indicator | .mantine-Carousel-indicator | Indicator button |
#### Carousel CSS variables
| Selector | Variable | Description |
|----------|----------------------------|------------------------------------------------------------|
| root | --carousel-control-size | Controls `width` and `height` of the next/previous buttons |
| root | --carousel-controls-offset | Controls offsets of the next/previous buttons |
| root | --carousel-height | Controls height of the carousel |
#### Carousel data attributes
| Selector | Attribute | Condition | Value |
|------------|------------------------------|------------------------------------------|------------------------------|
| root | data-orientation | – | Value of `orientation` prop |
| root | data-include-gap-in-size | `includeGapInSize` prop is set | – |
| control | data-inactive | No previous/next slides are available | – |
| indicator | data-active | Associated slide is active | – |
### Keyword Arguments
#### Carousel
- children (a list of or a singular dash component, string or number; optional):
components.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- active (number; default 0):
The index of the current slide. Read only. Use initialSlide to
set the current slide.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoScroll (boolean; optional):
Enables autoScroll with optional configuration.
- autoplay (boolean; optional):
Enables autoplay with optional configuration.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- controlSize (string | number; optional):
Controls size of the next and previous controls, `26` by default.
- controlsOffset (number; optional):
Controls position of the next and previous controls, key of
`theme.spacing` or any valid CSS value, `'sm'` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- emblaOptions (dict; optional):
options to pass to the embla component.
- height (string | number; optional):
Slides container `height`, required for vertical orientation.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- includeGapInSize (boolean; optional):
Determines whether gap between slides should be treated as part of
the slide size, `True` by default.
- initialSlide (number; default 0):
Index of initial slide.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- nextControlIcon (a list of or a singular dash component, string or number; optional):
Icon of the next control.
- orientation (a value equal to: 'horizontal', 'vertical'; optional):
Carousel orientation, `'horizontal'` by default.
- previousControlIcon (a list of or a singular dash component, string or number; optional):
Icon of the previous control.
- slideGap (number; optional):
Key of theme.spacing or number to set gap between slides.
- slideSize (string | number; optional):
Controls slide width based on viewport width, `'100%'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- type (a value equal to: 'media', 'container'; optional):
Determines typeof of queries that are used for responsive styles,
'media' by default.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withControls (boolean; optional):
Determines whether next/previous controls should be displayed,
True by default.
- withIndicators (boolean; optional):
Determines whether indicators should be displayed, `False` by
default.
- withKeyboardEvents (boolean; optional):
Determines whether arrow key should switch slides, `True` by
default.
#### CarouselSlide
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Image
DMC alternative for html.Img with placeholder for loading and error states.
Category: Data Display
### Simple Example
`Image` is a wrapper for HTML `img` with minimal styles. By default, the image will take 100% of parent width. The
image size can be controlled with `w` and `h` style props.
```python
import dash_mantine_components as dmc
component = dmc.Image(
radius="md",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-7.png",
)
```
### Image height
In most case, you will need to set image height to prevent layout jumps when image is loading. You can do so with `h` [style](/style-props) props.
```python
import dash_mantine_components as dmc
component = dmc.Image(
radius="md",
h=200,
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-10.png",
)
```
### Image fit
By default the image has `object-fit: cover` style - it will resize to cover parent element. To change this behavior,
set `w="auto"` and `fit="contain"` props.
```python
import dash_mantine_components as dmc
component = dmc.Image(
radius="md",
h=200,
w="auto",
fit="contain",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/images/bg-9.png",
)
```
### Placeholder
Set `fallbackSrc` prop to display fallback image when image fails to load:
```python
import dash_mantine_components as dmc
component = dmc.Image(
radius="md",
src=None,
h=200,
fallbackSrc="https://placehold.co/600x400?text=Placeholder",
)
```
### Background Image
Use BackgroundImage component when you need to display image below any content. Component sets background-image to
given `src`, background-size to cover and background-position to center.
```python
import dash_mantine_components as dmc
from dash import html
component = html.Div(
style={"width": 300},
children=dmc.BackgroundImage(
src="https://images.unsplash.com/photo-1419242902214-272b3f66ee7a?ixlib=rb-1.2.1&ixid"
"=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=720&q=80",
children=[
dmc.Center(
p="md",
children=[
dmc.Text(
"BackgroundImage component can be used to add any content on image. It is used for cards, "
"hero headers and similar components",
c="yellow",
)
],
)
],
),
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Image Selectors
| Selector | Static selector | Description |
| -------- | --------------------- | ------------ |
| root | `.mantine-Image-root` | Root element |
#### Image CSS Variables
| Selector | Variable | Description |
| -------- | -------------------- | --------------------------------- |
| root | `--image-object-fit` | Controls `object-fit` property |
| root | `--image-radius` | Controls `border-radius` property |
#### Image Data Attributes
| Selector | Attribute | Condition |
| -------- | --------------- | -------------------- |
| root | `data-fallback` | Image failed to load |
### Keyword Arguments
#### Image
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- alt (string; optional):
Image alt text, used as title for placeholder if image was not
loaded.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- fallbackSrc (string; optional):
Image url that will be used as a fallback in case `src` prop is
not set or image cannot be loaded.
- fit (a value equal to: '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'contain', 'cover', 'fill', 'scale-down'; optional):
Controls `object-fit` style, `'cover'` by default.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, `0` by default.
- src (boolean | number | string | dict | list; optional):
Image url.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### BackgroundImage
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius,
numbers are converted to rem, `0` by default.
- src (string; required):
Image url.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Indicator
Use Indicator to display element at the corner of another element
Category: Data Display
### Introduction
Use Indicator to display element at the corner of another element.
### Inline
When the target element has a fixed width, set `inline` prop to add `display: inline-block;` styles to Indicator container.
Alternatively, you can set width and height with `style` prop if you still want the root element to keep `display: block`.
```python
import dash_mantine_components as dmc
component = dmc.Indicator(
dmc.Avatar(
size="lg",
radius="sm",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-2.png",
),
inline=True,
size=16,
label="New",
)
```
### Offset
Set `offset` to change the indicator position. It is useful when the `Indicator` component is used with children that
have `border-radius`. You can provide a number for uniform offset or a dictionary with `x` and `y` properties for
separate horizontal and vertical offsets
```python
import dash_mantine_components as dmc
component = dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-3.png",
),
inline=True,
offset=7,
position="bottom-end",
color="red",
withBorder=True,
size=16,
)
```
### Max value
Set `maxValue` prop to display `{maxValue}+` when the label exceeds the maximum value. This is useful for notification
counters that should not show exact large numbers:
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-1.png",
),
inline=True,
label=50,
maxValue=99,
),
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-2.png",
),
inline=True,
label=100,
maxValue=99,
),
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-3.png",
),
inline=True,
label=1000,
maxValue=999,
),
]
)
```
### Show zero
By default, the indicator is displayed when the label is 0. Set `showZero=False` to hide the indicator when the label is 0
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-1.png",
),
inline=True,
label=0,
),
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-2.png",
),
inline=True,
label=0,
showZero=False,
),
]
)
```
### Auto contrast
Set `autoContrast` prop to automatically adjust text color based on the background color to ensure readable contrast:
```python
import dash_mantine_components as dmc
component = dmc.Group(
[
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-1.png",
),
inline=True,
label="99",
color="lime.4",
),
dmc.Indicator(
dmc.Avatar(
size="lg",
radius="xl",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-2.png",
),
inline=True,
label="99",
color="lime.4",
autoContrast=True,
),
]
)
```
### Processing Animation
```python
import dash_mantine_components as dmc
component = dmc.Indicator(
dmc.Avatar(
size="lg",
radius="sm",
src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-4.png",
),
inline=True,
color="red",
size=12,
processing=True,
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:----------|:-----------------------------|:------------------|
| root | .mantine-Indicator-root | Root element |
| indicator | .mantine-Indicator-indicator | Indicator element |
### Keyword Arguments
#### Indicator
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether text color should depend on `background-color`.
If luminosity of the `color` prop is less than
`theme.luminosityThreshold`, then `theme.white` will be used for
text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color value,
`theme.primaryColor` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- disabled (boolean; optional):
When Indicator is disabled it renders children only.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- inline (boolean; optional):
Determines whether the indicator container should be an inline
element, `False` by default.
- label (a list of or a singular dash component, string or number; optional):
Label rendered inside the indicator, for example, notification
count.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxValue (number; optional):
Maximum value to display. If label is a number greater than this
value, it will be displayed as `{maxValue}+`.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- offset (dict; optional):
Distance in pixels to offset the indicator from its default
position, useful for elements with border-radius. Can be a number
for uniform offset or a dict with `x` and `y` properties for
separate horizontal and vertical offsets default 0.
`offset` is a number | dict with keys:
- position (a value equal to: 'top-center', 'top-end', 'top-start', 'bottom-center', 'bottom-end', 'bottom-start', 'middle-center', 'middle-end', 'middle-start'; optional):
Indicator position relative to the target element, `'top-end'` by
default.
- processing (boolean; optional):
Determines whether the indicator should have processing animation,
`False` by default.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, `100` by default.
- showZero (boolean; optional):
Determines whether indicator with label `0` should be displayed
default True.
- size (string | number; optional):
Indicator width and height, `10` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- withBorder (boolean; optional):
Determines whether the indicator should have a border (color of
the border is the same as the body element), `False` by default.
- zIndex (string | number; optional):
Indicator z-index, `200` by default.
## Kbd
Use Kbd to show keyboard shortcuts, etc.
Category: Data Display
### Simple Example
```python
import dash_mantine_components as dmc
from dash import html
component = html.Div([dmc.Kbd("⌘"), " + ", dmc.Kbd("shift"), " + ", dmc.Kbd("M")])
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:------------|:------------------|:-------------------------------------------------|
| root | .mantine-Kbd-root | Root element |
### Keyword Arguments
#### Kbd
- children (a list of or a singular dash component, string or number; optional):
Keyboard key.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- size (optional):
Controls font-size and padding, `'sm'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## NumberFormatter
Use the NumberFormatter component to format number with thousands/decimal separators and suffix/prefix
Category: Data Display
### Simple Example
Use `NumberFormatter` to format numbers. It supports the same formatting related props as `NumberInput` component.
```python
import dash_mantine_components as dmc
component = dmc.NumberFormatter(prefix="$ ", value=1000000, thousandSeparator=True)
```
### Prefix and suffix
Set `prefix` and `suffix` props to add given string to the start or end of the value:
```python
from dash import html
import dash_mantine_components as dmc
component = html.Div([
html.Div(["With prefix: ", dmc.NumberFormatter(value=100, prefix="$")]),
html.Div(["With suffix: ", dmc.NumberFormatter(value=100, suffix=" RUB")]),
])
```
### Keyword Arguments
#### NumberFormatter
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- allowNegative (boolean; optional):
Determines whether negative values are allowed, `True` by default.
- aria-* (string; optional):
Wild card aria attributes.
- data-* (string; optional):
Wild card data attributes.
- decimalScale (number; optional):
Limits the number of digits that are displayed after the decimal
point, by default there is no limit.
- decimalSeparator (string; optional):
Character used as a decimal separator, `'.'` by default.
- fixedDecimalScale (boolean; optional):
If set, 0s are added after `decimalSeparator` to match given
`decimalScale`. `False` by default.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- prefix (string; optional):
Prefix added before the value.
- suffix (string; optional):
Suffix added after the value.
- tabIndex (number; optional):
tab-index.
- thousandSeparator (string | boolean; optional):
A character used to separate thousands, `','` by default.
- thousandsGroupStyle (a value equal to: 'none', 'thousand', 'lakh', 'wan'; optional):
Defines the thousand grouping style.
- value (string | number; optional):
Value to format.
## Spoiler
Use the Spoiler component to hide long sections of content.
Category: Data Display
### Simple Example
Use Spoiler to hide long sections of content. Pass `maxHeight` prop to control the point at which content will be
hidden under the spoiler and control to show/hide extra appears. If content height is less than `maxHeight`, spoiler
will just render children.
Props `hideLabel` and `showLabel` are required - they are used as spoiler toggle button label in corresponding state.
```python
import dash_mantine_components as dmc
# very long string
text = ""
component = dmc.Spoiler(
showLabel="Show more",
hideLabel="Hide",
maxHeight=50,
children=[dmc.Text(text)],
)
```
### Accessibility
The Spoiler component includes ARIA attributes and keyboard support for screen reader users:
* The toggle button uses `aria-expanded` to indicate whether the content is expanded or collapsed.
* The content region uses `role="region"` and is associated with the toggle button through `aria-controls`.
* The spoiler can be toggled with Space or Enter when the button is focused.
### Best practices for label text
Use descriptive labels for `showLabel` and `hideLabel` that clearly describe the action:
```python
import dash_mantine_components as dmc
dmc.Spoiler(
showLabel="Show full article",
hideLabel="Hide article",
)
```
Other good examples include `"Expand details"` / `"Collapse details"`. Avoid vague labels such as `"More"` / `"Less"` or `"..."`.
### Custom accessibility labels
If the visible button labels do not clearly describe the action, use `showAriaLabel` and `hideAriaLabel` to provide descriptive labels for screen readers:
```python
import dash_mantine_components as dmc
component = dmc.Spoiler(
showLabel="👁️",
hideLabel="👁️",
showAriaLabel="Show discussion comments",
hideAriaLabel="Hide discussion comments",
children="Comments content",
)
```
The `showAriaLabel` and `hideAriaLabel` values are used as the accessible labels for the toggle button.
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:--------|:-------------------------|:-----------------------------------------------|
| root | .mantine-Spoiler-root | Root element |
| content | .mantine-Spoiler-content | Wraps content to set max-height and transition |
| control | .mantine-Spoiler-control | Show/hide content control |
### Keyword Arguments
#### Spoiler
- children (a list of or a singular dash component, string or number; optional):
Content.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- defaultExpanded (boolean; optional):
Initial expanded state in uncontrolled mode. If `True`, content
starts expanded. If `False`, content starts collapsed default
False.
- expanded (boolean; default False):
Controlled expanded state value.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hideAriaLabel (string; optional):
Accessible label for the toggle button when expanded. If not set,
`hideLabel` is used.
- hideLabel (a list of or a singular dash component, string or number; required):
Content displayed in the toggle button when content is expanded
(to collapse).
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxHeight (number; optional):
Maximum height of visible content in px. When content exceeds this
height, the toggle control appears default 100.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- showAriaLabel (string; optional):
Accessible label for the toggle button when collapsed. If not set,
`showLabel` is used.
- showLabel (a list of or a singular dash component, string or number; required):
Content displayed in the toggle button when content is collapsed
(to expand).
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- transitionDuration (number; optional):
Spoiler reveal transition duration in ms. Set to 0 to disable
animation default 200.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## ThemeIcon
Use ThemeIcon component to render icon inside element with theme colors.
Category: Data Display
### Usage
ThemeIcon can be customized by setting its variant, size, radius and color.
### Colors
ThemeIcon supports all colors from Mantine's theme colors.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
colors = [
"gray",
"red",
"pink",
"grape",
"violet",
"indigo",
"blue",
"lime",
"yellow",
"orange",
]
component = dmc.Stack(
gap="xs",
children=[
dmc.Group(
[
dmc.ThemeIcon(
DashIconify(icon="tabler:photo", width=20),
variant=variant,
color=color,
)
for color in colors
],
justify="center",
)
for variant in ["outline", "light", "filled"]
],
)
```
### Gradient Variant
To use gradient as ThemeIcon background:
* set `variant` prop to "gradient"
* set `gradient` prop to `{ "from": "color-from", "to": "color-to", "deg": 135}`, where
* `color-from` and `color-to` are colors from Mantine's theme colors.
* `deg` is linear gradient deg.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Group(
children=[
dmc.ThemeIcon(
DashIconify(icon="tabler:photo", width=20),
variant="gradient",
gradient={"from": "indigo", "to": "cyan"},
size="lg",
),
dmc.ThemeIcon(
DashIconify(icon="tabler:photo", width=20),
variant="gradient",
gradient={"from": "teal", "to": "lime", "deg": 105},
size="lg",
),
dmc.ThemeIcon(
DashIconify(icon="tabler:photo", width=20),
variant="gradient",
gradient={"from": "teal", "to": "blue", "deg": 60},
size="lg",
),
dmc.ThemeIcon(
DashIconify(icon="tabler:photo", width=20),
variant="gradient",
gradient={"from": "orange", "to": "red"},
size="lg",
),
dmc.ThemeIcon(
DashIconify(icon="tabler:photo", width=20),
variant="gradient",
gradient={"from": "grape", "to": "pink", "deg": 35},
size="lg",
),
]
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
| Name | Static selector | Description |
|:------------|:------------------------|:-------------------------------------------------|
| root | .mantine-ThemeIcon-root | Root element |
### Keyword Arguments
#### ThemeIcon
- children (a list of or a singular dash component, string or number; optional):
Icon displayed inside the component.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether button text color with filled variant should
depend on `background-color`. If luminosity of the `color` prop is
less than `theme.luminosityThreshold`, then `theme.white` will be
used for text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color. Default value is
`theme.primaryColor`.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- gradient (dict; optional):
Gradient data used when `variant="gradient"`, default value is
`theme.defaultGradient`.
`gradient` is a dict with keys:
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set border-radius.
Numbers are converted to rem. `theme.defaultRadius` by default.
- size (number; optional):
Controls width and height of the button. Numbers are converted to
rem. `'md'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Timeline
Use the Timeline and TimelineItem components to display a list of events in chronological order.
Category: Data Display
### Introduction
### Usage
Control timeline appearance with the following props:
- `active` - index of current active element, all elements before this index will be highlighted with color
- `color` - color from theme that should be used to highlight active items, defaults to theme.primaryColor
- `lineWidth` - controls line width and bullet border
- `bulletSize` - bullet width, height and border-radius
- `align` - defines line and bullets position relative to content, also sets textAlign
```python
import dash_mantine_components as dmc
component = dmc.Timeline(
active=1,
bulletSize=15,
lineWidth=2,
children=[
dmc.TimelineItem(
title="New Branch",
children=[
dmc.Text(
[
"You've created new branch ",
dmc.Anchor("fix-notification", href="#", size="sm"),
" from master",
],
c="dimmed",
size="sm",
),
],
),
dmc.TimelineItem(
title="Commits",
children=[
dmc.Text(
[
"You've pushed 23 commits to ",
dmc.Anchor("fix-notification", href="#", size="sm"),
],
c="dimmed",
size="sm",
),
],
),
dmc.TimelineItem(
title="Pull Request",
lineVariant="dashed",
children=[
dmc.Text(
[
"You've submitted a pull request ",
dmc.Anchor(
"Fix incorrect notification message (#178)",
href="#",
size="sm",
),
],
c="dimmed",
size="sm",
),
],
),
dmc.TimelineItem(
[
dmc.Text(
[
dmc.Anchor(
"AnnMarieW",
href="https://github.com/AnnMarieW",
size="sm",
),
" left a comment on your pull request",
],
c="dimmed",
size="sm",
),
],
title="Code Review",
),
],
)
```
### Components in Bullets
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Timeline(
children=[
dmc.TimelineItem(
title="Default bullet",
children=dmc.Text("Default bullet without anything", c="dimmed", size="sm")
),
dmc.TimelineItem(
title="Avatar",
bullet=dmc.Avatar(
size=22,
radius="xl",
src="https://avatars.githubusercontent.com/u/91216500?v=4"
),
children=dmc.Text("Timeline bullet as avatar image", c="dimmed", size="sm")
),
dmc.TimelineItem(
title="Icon",
bullet=DashIconify(icon="tabler:sun", width=13),
children=dmc.Text("Timeline bullet as icon", c="dimmed", size="sm")
),
dmc.TimelineItem(
title="ThemeIcon",
bullet=dmc.ThemeIcon(
size=22,
variant="gradient",
gradient={"from": "lime", "to": "cyan"},
radius="xl",
children=DashIconify(icon="tabler:video", width=13)
),
children=dmc.Text("Timeline bullet as ThemeIcon component", c="dimmed", size="sm")
)
],
bulletSize=24
)
```
### Opposite
Use the `opposite` prop on `TimelineItem` to render content on the opposite side of the timeline. When any `TimelineItem`
has the opposite prop, the timeline switches to a centered layout with content on both sides of the line.
```python
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Timeline(
[
dmc.TimelineItem(
title="New branch",
bullet=DashIconify(icon="tabler:git-branch", width=12),
opposite=dmc.Text("2 hours ago", size="sm", c="dimmed"),
children=dmc.Text(
[
"You've created new branch ",
dmc.Text("fix-notifications", variant="link", span=True, inherit=True),
" from master",
],
c="dimmed",
size="sm",
),
),
dmc.TimelineItem(
title="Commits",
bullet=DashIconify(icon="tabler:git-commit", width=12),
opposite=dmc.Text("52 minutes ago", size="sm", c="dimmed"),
children=dmc.Text(
[
"You've pushed 23 commits to ",
dmc.Text("fix-notifications branch", variant="link", span=True, inherit=True),
],
c="dimmed",
size="sm",
),
),
dmc.TimelineItem(
title="Pull request",
bullet=DashIconify(icon="tabler:git-pull-request", width=12),
lineVariant="dashed",
opposite=dmc.Text("34 minutes ago", size="sm", c="dimmed"),
children=dmc.Text(
[
"You've submitted a pull request ",
dmc.Text(
"Fix incorrect notification message (#187)",
variant="link",
span=True,
inherit=True,
),
],
c="dimmed",
size="sm",
),
),
dmc.TimelineItem(
title="Code review",
bullet=DashIconify(icon="tabler:message-circle", width=12),
children=dmc.Text(
[
dmc.Text("Claude", variant="link", span=True, inherit=True),
" left a code review on your pull request",
],
c="dimmed",
size="sm",
),
),
],
active=1,
bulletSize=24,
lineWidth=2,
)
```
### Alternate
Set the `alternate` prop on individual `TimelineItem` components to switch the position of content and opposite:
```python
import dash_mantine_components as dmc
component = dmc.Timeline(
[
dmc.TimelineItem(
title="Project started",
opposite=dmc.Text("Jan 2025", size="sm", c="dimmed"),
children="Initial planning and requirements gathering.",
),
dmc.TimelineItem(
title="Beta release",
opposite=dmc.Text("Apr 2025", size="sm", c="dimmed"),
alternate=True,
children="Released the first version to early adopters.",
),
dmc.TimelineItem(
title="General availability",
opposite=dmc.Text("Aug 2025", size="sm", c="dimmed"),
children="Launched publicly with full documentation.",
),
dmc.TimelineItem(
title="Version 2.0",
opposite=dmc.Text("Jan 2026", size="sm", c="dimmed"),
alternate=True,
children="Introduced a redesigned interface and new features.",
),
],
active=3,
bulletSize=16,
lineWidth=2,
)
```
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### Timeline Selectors
| Selector | Static selector | Description |
|-------------|-------------------------------|-------------------------------------------|
| root | .mantine-Timeline-root | Root element |
| item | .mantine-Timeline-item | Item root element |
| itemBody | .mantine-Timeline-itemBody | Item body, wraps title and content |
| itemTitle | .mantine-Timeline-itemTitle | Item title, controlled by `title` prop |
| itemContent | .mantine-Timeline-itemContent | Item content, controlled by `children` prop |
| itemBullet | .mantine-Timeline-itemBullet | Item bullet |
#### Timeline CSS Variables
| Selector | Variable | Description |
|----------|------------------|---------------------------------------------|
| root | --tl-bullet-size | Controls bullet width and height |
| | --tl-color | Controls active bullet and line colors |
| | --tl-icon-color | Controls icon color |
| | --tl-line-width | Controls width of the line between bullets |
| | --tl-radius | Controls bullet border-radius |
#### Timeline Data Attributes
| Selector | Attribute | Condition |
|----------------|----------------|----------------------------------------------|
| item, itemBullet | data-active | Item index is `<=` Timeline `active` prop |
| item | data-line-active | Item index is `<` Timeline `active` prop |
### Keyword Arguments
#### Timeline
- children (a list of or a singular dash component, string or number; optional):
`Timeline.Item` components.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- active (number; optional):
Index of active element.
- align (a value equal to: 'left', 'right'; optional):
Controls how the content is positioned relative to the bullet,
`'left'` by default.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- autoContrast (boolean; optional):
Determines whether icon color should depend on `background-color`.
If luminosity of the `color` prop is less than
`theme.luminosityThreshold`, then `theme.white` will be used for
text color, otherwise `theme.black`. Overrides
`theme.autoContrast`.
- bulletSize (string | number; optional):
Controls size of the bullet, `20` by default.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color to control active
item colors, `theme.primaryColor` by default.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- lineWidth (string | number; optional):
Control width of the line.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem, `'xl'` by default.
- reverseActive (boolean; optional):
Determines whether the active items direction should be reversed
without reversing items order, `False` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
#### TimelineItem
- children (a list of or a singular dash component, string or number; optional):
Content displayed below the title.
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- alternate (boolean; optional):
If set, switches the position of content and opposite
@,default,False.
- aria-* (string; optional):
Wild card aria attributes.
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- bullet (a list of or a singular dash component, string or number; optional):
React node that should be rendered inside the bullet – icon,
image, avatar, etc. By default, large white dot is displayed.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- color (optional):
Key of `theme.colors` or any valid CSS color to control active
item colors @,default,theme.primaryColor.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- lineVariant (a value equal to: 'dashed', 'dotted', 'solid'; optional):
Controls line border style, `'solid'` by default.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- opposite (a list of or a singular dash component, string or number; optional):
Content displayed on the opposite side of the timeline item.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem, `'xl'` by default.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- tabIndex (number; optional):
tab-index.
- title (a list of or a singular dash component, string or number; optional):
Item title, displayed next to the bullet.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
## Date Pickers Overview
This guide gives an overview of Date and Time components available in Dash Mantine components.
Category: Date Pickers
The Mantine date pickers let users quickly navigate by months or years to select dates in the past or future.
### DatePicker
[DatePicker](/components/datepicker) allows users to select a date, date range, or multiple dates from a calendar. It does not have an input field.
Note: Many `DatePicker` props (for example, `minDate`, `maxDate`, `excludeDates`, `allowLevelChange`, `firstDayOfWeek`,
`renderDay`) apply across other Mantine date and time picker components. Refer to the DatePicker section for details and example for these shared props.
### DatePickerInput
[DatePickerInput](/components/datepickerinput): Select single dates, multiple dates (`type="multiple"`), or date
ranges (`type="range"`). This option **does not** allow free text input.
### DateInput
[DateInput](/components/datepickerinput): Allows free form text input of dates, as well as selecting a date from a calendar.
### MonthPickerInput
[MonthPickerInput](/components/monthpickerinput): Use when only the month value is needed.
### YearPickerInput
[YearPickerInput](/components/yearpickerinput): Use when only the year value is needed.
### TimeInput
[TimeInput](/components/timeinput): is based on the native `input[type="time"]` element and does not support most of
advanced features like choosing time format or custom dropdown with time select. If you need more features, use
`TimePicker` component instead.
### TimePicker
[TimePicker](/components/timepicker): Advanced time selection with features like dropdowns for hours, minutes, seconds,
and 12-hour/24-hour formats, and time pre-sets.
### TimeGrid
[TimeGrid](/components/timegrid) captures time value from the user with a predefined set of options.
### DateTimePicker
[DateTimePicker](/components/): Selects both date and time from user.
### CSS Extensions
As of DMC 1.2.0, Date component styles are bundled automatically, so you no longer need to include a separate CSS file.
If you're using an older version of DMC, refer to the [migration guide](/migration) for instructions on including optional stylesheets.
## DateInput
Free form date input
Category: Date Pickers
### DateInput props
DateInput supports most of the [DatePicker](/components/datepicker) props, read through DatePicker
documentation to learn about all component features that are not listed on this page.
### Simple Example
This is a simple example of DateInput tied to a callback. You can type a date or select from the DatePicker
```python
import dash_mantine_components as dmc
from dash import Input, Output, html, callback
component = html.Div(
[
dmc.DateInput(
id="dateinput2",
label="Enter a date",
description="You can type a date or select from the calendar",
w=300,
),
dmc.Space(h=10),
dmc.Text(id="selected-dateinput2"),
]
)
@callback(Output("selected-dateinput2", "children"), Input("dateinput2", "value"))
def update_output(d):
prefix = "You entered: "
if d:
return prefix + d
else:
return ""
```
### Value format
Use `valueFormat` prop to change [dayjs format](https://day.js.org/docs/en/display/format) of value label displayed in the input field.
```python
from datetime import datetime
import dash_mantine_components as dmc
component = dmc.Group(
gap="xl",
children=[
dmc.DateInput(
value=datetime.now().date(),
valueFormat="ddd, MMM D YY",
label="ddd, MMM D YY",
w=250,
),
dmc.DateInput(
value=datetime.now().date(),
valueFormat="MMMM DD, YY",
label="MMMM DD, YY",
w=250,
),
dmc.DateInput(
value=datetime.now().date(),
valueFormat="DD-MM-YYYY",
label="DD-MM-YYYY",
w=250,
),
],
)
```
`valueFormat` also accepts a function that receives the value as a YYYY-MM-DD string and returns the formatted value. For
more details and examples, see [Mantine DateInput](https://mantine.dev/dates/date-input/#value-format) documentation, and the [Functions As Props](/functions-as-props) section.
### Clearable
Set clearable prop to allow removing value from the input. Input will be cleared if user selects the same date in dropdown or clears input value.
When `clearable=True`, a clear button in the right section is displayed. Note that if you set rightSection prop, clear button will not be displayed.
```python
import dash_mantine_components as dmc
component = dmc.DateInput(
clearable=True, label="Date input", placeholder="Date Input", w=250
)
```
### Clear section mode
The `clearSectionMode` prop determines how the `clear` button and `rightSection` are rendered:
- 'both' (default) – render both the `clear` button and `rightSection`
- 'rightSection' – render only the user-supplied `rightSection`, ignore `clear` button
- 'clear' – render only the `clear` button, ignore `rightSection`
```python
from datetime import date
import dash_mantine_components as dmc
from dash_iconify import DashIconify
component = dmc.Stack([
dmc.DateInput(
label="clearSectionMode='both' (default)",
placeholder="Pick date",
value="2027-01-01",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="both",
),
dmc.DateInput(
label="clearSectionMode='rightSection'",
placeholder="Pick date",
value="2027-01-01",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="rightSection",
),
dmc.DateInput(
label="clearSectionMode='clear'",
placeholder="Pick date",
value="2027-01-01",
clearable=True,
rightSection=DashIconify(icon="tabler:chevron-down", width=16),
clearSectionMode="clear",
),
])
```
### Min and max date
Set `minDate` and `maxDate` props to define min and max dates. If date that is after `maxDate` or before `minDate` is entered, then it will be considered invalid and input value will be reverted to last known valid date value.
```python
from datetime import datetime, timedelta
import dash_mantine_components as dmc
component = dmc.DateInput(
minDate=datetime.now(),
maxDate=datetime.now() + timedelta(days=7),
placeholder="Date input",
label="Select valid date",
w=250,
)
```
### Input props
### CSS Extensions
As of DMC 1.2.0, Date component styles are bundled automatically, so you no longer need to include a separate CSS file.
If you're using an older version of DMC, refer to the [migration guide](/migration) for instructions on including optional stylesheets.
### Styles API
This component supports Styles API. With Styles API, you can customize styles of any inner element. See the Styling and Theming sections of these docs for more information.
#### DateInput selectors
| Selector | Static selector | Description |
| ------------------------- | ---------------------------------------------- | ------------------------------------------------------------------ |
| wrapper | `.mantine-DateInput-wrapper` | Root element of the Input |
| input | `.mantine-DateInput-input` | Input element |
| section | `.mantine-DateInput-section` | Left and right sections |
| root | `.mantine-DateInput-root` | Root element |
| label | `.mantine-DateInput-label` | Label element |
| required | `.mantine-DateInput-required` | Required asterisk element, rendered inside label |
| description | `.mantine-DateInput-description` | Description element |
| error | `.mantine-DateInput-error` | Error element |
| calendarHeader | `.mantine-DateInput-calendarHeader` | Calendar header root element |
| calendarHeaderControl | `.mantine-DateInput-calendarHeaderControl` | Previous/next calendar header controls |
| calendarHeaderControlIcon | `.mantine-DateInput-calendarHeaderControlIcon` | Icon of previous/next calendar header controls |
| calendarHeaderLevel | `.mantine-DateInput-calendarHeaderLevel` | Level control (changes levels when clicked, month → year → decade) |
| levelsGroup | `.mantine-DateInput-levelsGroup` | Group of months levels |
| yearsList | `.mantine-DateInput-yearsList` | Years list table element |
| yearsListRow | `.mantine-DateInput-yearsListRow` | Years list row element |
| yearsListCell | `.mantine-DateInput-yearsListCell` | Years list cell element |
| yearsListControl | `.mantine-DateInput-yearsListControl` | Button used to pick months and years |
| monthsList | `.mantine-DateInput-monthsList` | Months list table element |
| monthsListRow | `.mantine-DateInput-monthsListRow` | Months list row element |
| monthsListCell | `.mantine-DateInput-monthsListCell` | Months list cell element |
| monthsListControl | `.mantine-DateInput-monthsListControl` | Button used to pick months and years |
| monthThead | `.mantine-DateInput-monthThead` | `thead` element of month table |
| monthRow | `.mantine-DateInput-monthRow` | `tr` element of month table |
| monthTbody | `.mantine-DateInput-monthTbody` | `tbody` element of month table |
| monthCell | `.mantine-DateInput-monthCell` | `td` element of month table |
| month | `.mantine-DateInput-month` | Month table element |
| weekdaysRow | `.mantine-DateInput-weekdaysRow` | Weekdays `tr` element |
| weekday | `.mantine-DateInput-weekday` | Weekday `th` element |
| day | `.mantine-DateInput-day` | Month day control |
| weekNumber | `.mantine-DateInput-weekNumber` | Week number `td` element |
| datePickerRoot | `.mantine-DateInput-datePickerRoot` | Date picker root element, contains calendar and presets |
| presetsList | `.mantine-DateInput-presetsList` | Presets wrapper element |
| presetButton | `.mantine-DateInput-presetButton` | Preset button |
#### DateInput data attributes
| Selector | Attribute | Condition | Value |
| --------------------- | --------------------- | --------------------------------------------------------------------- | ------------------------------------------------------ |
| calendarHeaderControl | `data-direction` | – | `"previous"` or `"next"` depending on the control type |
| calendarHeaderControl | `data-disabled` | Control is disabled for any reason | – |
| monthCell | `data-with-spacing` | `withCellSpacing` prop is set | – |
| day | `data-today` | Date is the same as `new Date()` | – |
| day | `data-hidden` | Day is outside of current month and `hideOutsideDates` is set | – |
| day | `data-disabled` | Day disabled by one of the props (`excludeDate`, `getDayProps`, etc.) | – |
| day | `data-weekend` | Day is weekend | – |
| day | `data-outside` | Day is outside of the current month | – |
| day | `data-selected` | Day is selected | – |
| day | `data-in-range` | Day is in range selection | – |
| day | `data-first-in-range` | Day is first in range selection | – |
| day | `data-last-in-range` | Day is last in range selection | – |
### Keyword Arguments
#### DateInput
- id (string; optional):
Unique ID to identify this component in Dash callbacks.
- allowDeselect (boolean; optional):
Determines whether value can be deselected when the user clicks on
the selected date in the calendar (only when clearable prop is
set), defaults to True if clearable prop is set, False otherwise.
- aria-* (string; optional):
Wild card aria attributes.
- ariaLabels (dict; optional):
aria-label attributes for controls on different levels.
`ariaLabels` is a dict with keys:
- attributes (boolean | number | string | dict | list; optional):
Passes attributes to inner elements of a component. See Styles
API docs.
- className (string; optional):
Class added to the root element, if applicable.
- classNames (dict; optional):
Adds custom CSS class names to inner elements of a component. See
Styles API docs.
- clearButtonProps (dict; optional):
Props added to clear button.
`clearButtonProps` is a dict with keys:
- clearSectionMode (a value equal to: 'rightSection', 'both', 'clear'; optional):
Determines how the clear button and rightSection are rendered
default 'both'.
- clearable (boolean; optional):
Determines whether input value can be cleared, adds clear button
to right section, False by default.
- columnsToScroll (number; optional):
Number of columns to scroll when user clicks next/prev buttons,
defaults to numberOfColumns.
- darkHidden (boolean; optional):
Determines whether component should be hidden in dark color scheme
with `display: none`.
- data-* (string; optional):
Wild card data attributes.
- dateParser (boolean | number | string | dict | list; optional):
A function to parse user input and convert it to date string
value.
- debounce (number | boolean; default False):
(boolean | number; default False): If True, changes to input will
be sent back to the Dash server only on enter or when losing
focus. If it's False, it will send the value back on every change.
If a number, it will not send anything back to the Dash server
until the user has stopped typing for that number of milliseconds.
- decadeLabelFormat (string; optional):
dayjs label format to display decade label or a function that
returns decade label based on date value, defaults to "YYYY".
- description (a list of or a singular dash component, string or number; optional):
Contents of `Input.Description` component. If not set, description
is not rendered.
- descriptionProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Description` component.
- disabled (boolean; optional):
Sets `disabled` attribute on the `input` element.
- disabledDates (boolean | number | string | dict | list; optional):
Specifies days that should be disabled. Either a list of dates or
a function. See
https://www.dash-mantine-components.com/functions-as-props.
- error (a list of or a singular dash component, string or number; optional):
Contents of `Input.Error` component. If not set, error is not
rendered.
- errorProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Error` component.
- firstDayOfWeek (a value equal to: 0, 1, 2, 3, 4, 5, 6; optional):
number 0-6, 0 – Sunday, 6 – Saturday, defaults to 1 – Monday.
- fixOnBlur (boolean; optional):
Determines whether input value should be reverted to last known
valid value on blur, True by default.
- fullWidth (boolean; optional):
Determines whether the calendar should take the full width of its
container default False.
- getDayProps (boolean | number | string | dict | list; optional):
A function that passes props down Day component based on date.
(See https://www.dash-mantine-components.com/functions-as-props).
- getMonthControlProps (boolean | number | string | dict | list; optional):
A function that passes props down month picker control based on
date. (See
https://www.dash-mantine-components.com/functions-as-props).
- getYearControlProps (boolean | number | string | dict | list; optional):
A function that passes props down to year picker control based on
date. (See
https://www.dash-mantine-components.com/functions-as-props).
- hasNextLevel (boolean; optional):
Determines whether next level button should be enabled, defaults
to True.
- headerControlsOrder (list of a value equal to: 'level', 'next', 'previous's; optional):
Controls order, `['previous', 'level', 'next']`` by default.
- hiddenFrom (string; optional):
Breakpoint above which the component is hidden with `display:
none`.
- hideOutsideDates (boolean; optional):
Determines whether outside dates should be hidden, defaults to
False.
- hideWeekdays (boolean; optional):
Determines whether weekdays row should be hidden, defaults to
False.
- highlightToday (boolean; optional):
Determines whether today should be highlighted with a border,
False by default.
- inputProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input` component.
- inputWrapperOrder (list of a value equal to: 'label', 'description', 'error', 'input's; optional):
Controls order of the elements, `['label', 'description', 'input',
'error']` by default.
- label (a list of or a singular dash component, string or number; optional):
Contents of `Input.Label` component. If not set, label is not
rendered.
- labelProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Label` component.
- leftSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the left side of the input.
- leftSectionPointerEvents (a value equal to: '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'auto', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `leftSection` element,
`'none'` by default.
- leftSectionProps (dict; optional):
Props passed down to the `leftSection` element.
- leftSectionWidth (string | number; optional):
Left section width, used to set `width` of the section and input
`padding-left`, by default equals to the input height.
- level (a value equal to: 'month', 'year', 'decade'; optional):
Current level displayed to the user (decade, year, month), used
for controlled component.
- lightHidden (boolean; optional):
Determines whether component should be hidden in light color
scheme with `display: none`.
- loading (boolean; optional):
Displays loading indicator in the left or right section default
False.
- loadingPosition (a value equal to: 'left', 'right'; optional):
Position of the loading indicator default 'right'.
- loading_state (dict; optional):
Object that holds the loading state object coming from
dash-renderer. For use with dash<3.
`loading_state` is a dict with keys:
- maxDate (string; optional):
Maximum possible date.
- maxLevel (a value equal to: 'month', 'year', 'decade'; optional):
Max level that user can go up to (decade, year, month), defaults
to decade.
- minDate (string; optional):
Minimum possible date.
- mod (string | dict | list of string | dicts; optional):
Element modifiers transformed into `data-` attributes. For
example: "xl" or {"data-size": "xl"}. Can also be a list of
strings or dicts for multiple modifiers. Falsy values are removed.
- monthLabelFormat (string; optional):
dayjs label format to display month label or a function that
returns month label based on month value, defaults to "MMMM
YYYY".
- monthsListFormat (string; optional):
dayjs format for months list.
- n_blur (number; default 0):
An integer that represents the number of times that this element
has lost focus.
- n_submit (number; default 0):
An integer that represents the number of times that this element
has been submitted.
- name (string; optional):
Name prop.
- nextDisabled (boolean; optional):
Determines whether next control should be disabled, defaults to
True.
- nextIcon (a list of or a singular dash component, string or number; optional):
Change next icon.
- nextLabel (string; optional):
aria-label for next button.
- numberOfColumns (number; optional):
Number of columns to render next to each other.
- persisted_props (list of strings; optional):
Properties whose user interactions will persist after refreshing
the component or the page. Since only `value` is allowed this prop
can normally be ignored.
- persistence (string | number | boolean; optional):
Used to allow user interactions in this component to be persisted
when the component - or the page - is refreshed. If `persisted` is
truthy and hasn't changed from its previous value, a `value` that
the user has changed while using the app will keep that change, as
long as the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`. Note: The component
must have an `id` for persistence to work.
- persistence_type (a value equal to: 'local', 'session', 'memory'; optional):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data
is cleared once the browser quit.
- placeholder (string; optional):
Placeholder.
- pointer (boolean; optional):
Determines whether the input should have `cursor: pointer` style,
`False` by default.
- popoverProps (dict; optional):
Props added to Popover component.
`popoverProps` is a dict with keys:
- previousDisabled (boolean; optional):
Determines whether previous control should be disabled, defaults
to True.
- previousIcon (a list of or a singular dash component, string or number; optional):
Change previous icon.
- previousLabel (string; optional):
aria-label for previous button.
- radius (number; optional):
Key of `theme.radius` or any valid CSS value to set
`border-radius`, numbers are converted to rem,
`theme.defaultRadius` by default.
- readOnly (boolean; optional):
Readonly.
- renderDay (boolean | number | string | dict | list; optional):
A function that controls day value rendering. (See
https://www.dash-mantine-components.com/functions-as-props).
- required (boolean; optional):
Adds required attribute to the input and a red asterisk on the
right side of label, `False` by default.
- rightSection (a list of or a singular dash component, string or number; optional):
Content section rendered on the right side of the input.
- rightSectionPointerEvents (a value equal to: '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'auto', 'none', 'all', 'fill', 'painted', 'stroke', 'visible', 'visibleFill', 'visiblePainted', 'visibleStroke'; optional):
Sets `pointer-events` styles on the `rightSection` element,
`'none'` by default.
- rightSectionProps (dict; optional):
Props passed down to the `rightSection` element.
- rightSectionWidth (string | number; optional):
Right section width, used to set `width` of the section and input
`padding-right`, by default equals to the input height.
- size (a value equal to: 'xs', 'sm', 'md', 'lg', 'xl'; optional):
Component size.
- styles (boolean | number | string | dict | list; optional):
Adds inline styles directly to inner elements of a component. See
Styles API docs.
- success (a list of or a singular dash component, string or number; optional):
Determines whether the input should have success styles.
- successProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional):
Props passed down to the `Input.Success` component.
- tabIndex (number; optional):
tab-index.
- value (string; optional):
Value for controlled component.
- valueFormat (string; optional):
Dayjs format to display input value, "MMMM D, YYYY" by default.
- variant (string; optional):
variant.
- visibleFrom (string; optional):
Breakpoint below which the component is hidden with `display:
none`.
- weekdayFormat (string; optional):
dayjs format for weekdays names, defaults to "dd".
- weekendDays (list of a value equal to: 0, 1, 2, 3, 4, 5, 6s; optional):
Indices of weekend days, 0-6, where 0 is Sunday and 6 is Saturday,
defaults to value defined in DatesProvider.
- withAsterisk (boolean; optional):
Determines whether the required asterisk should be displayed.
Overrides `required` prop. Does not add required attribute to the
input. `False` by default.
- withCellSpacing (boolean; optional):
Determines whether controls should be separated by spacing, True
by default.
- withErrorStyles (boolean; optional):
Determines whether the input should have red border and red text
color when the `error` prop is set, `True` by default.
- withNativeLevelSelect (boolean; optional):
Determines whether level select controls should be rendered as
native `