RichTextEditor
component focuses on usability and is designed to be as simple as possible to bring a familiar editing experience to regular users. RichTextEditor
is based on Tiptap.dev and supports all of its features:
Name | Description | ||
---|---|---|---|
Cyndi Lauper | Singer | Songwriter | Actress |
Bruce Springsteen | Singer | Songwriter | Actor |
This is a basic example of implementing images. Drag to re-order.
Source code control example
New line with bold text
New line with italic text
' component =dmc.RichTextEditor( html=content, toolbar={ "sticky": True, "controlsGroups": [ ["SourceCode"], [ "Blockquote", "Bold", "Italic", "Underline", "Strikethrough", "ClearFormatting", "Highlight", ], ], }, ) ``` ### Custom controls Use `CustomControl` in the `controlsGroups` to create create custom controls in the `toolbar`. Note that you will need to set `aria-label` attribute to make control visible for screen readers. Tiptap version note: - DMC 2.3.0 and later uses [Tiptap v3.3 commands](https://tiptap.dev/docs/editor/api/commands). - Older versions of DMC used [Tiptap v2.9 commands](https://v2.tiptap.dev/docs/editor/api/commands). Use the appropriate Tiptap documentation above to see the full list of editor commands available for your custom controls. Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. #### Example: Insert content ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.RichTextEditor( html= 'Change font size with the controls!
", toolbar={ "controlsGroups": [ ["H1", "H2", "H3", "H4"], [ { "CustomControl": { "aria-label": "Increase font size", "title": "Increase font size", "children": DashIconify(icon="mdi:format-font-size-increase", width=16), "onClick": {"function": "increaseFontSize"}, }, }, { "CustomControl": { "aria-label": "Decrease font size", "title": "Decrease font size", "children": DashIconify(icon="mdi:format-font-size-decrease", width=16), "onClick": {"function": "decreaseFontSize"}, }, }, ], ], }, ) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; function changeFontSize(editor, delta) { if (!editor) return; const { from, to } = editor.state.selection; let size = 16; // default editor.state.doc.nodesBetween(from, to, (node) => { if (node.isText) { const mark = node.marks.find(m => m.type.name === "textStyle"); if (mark?.attrs.fontSize) { size = parseInt(mark.attrs.fontSize, 10); } } }); const newSize = Math.min(Math.max(size + delta, 8), 72) + "px"; editor.chain().focus().setFontSize(newSize).run(); } dmcfuncs.increaseFontSize = ({ editor }) => changeFontSize(editor, 2); dmcfuncs.decreaseFontSize = ({ editor }) => changeFontSize(editor, -2); ``` ### Selected text The `selected` prop contains the currently selected text. Note that it is text only and does not include any formatting. ```python from dash import Input, Output, html, callback import dash_mantine_components as dmc component = html.Div( [ dmc.RichTextEditor( html="Welcome to the editor.
Select some text
", extensions=[ "StarterKit", ], toolbar={ "controlsGroups": [ [ "Bold", "Italic", "Underline", "Strikethrough", "Highlight", ], ] }, id="rte", ), dmc.Box(id="rte-selected", mt="lg"), ] ) @callback(Output("rte-selected", "children"), Input("rte", "selected")) def update_content(content: str): return f"Your selected text: {content}" ``` ### Debounce The `debounce` prop controls how updates to the `html`, `json`, and `selected` props are triggered in the `RichTextEditor`. Enabling debounce helps prevent excessive callbacks by delaying updates until the user stops interacting. If set to `True`, updates occur only when the editor loses focus. Alternatively, you can specify a delay in milliseconds to fine-tune when updates should be sent. ```python dmc.RichTextEditor( debounce=500 # # Delay updates by 500ms ) ``` ### Persistence Dash provides built-in persistence props that allow components to retain their values across page reloads or app sessions. In `RichTextEditor`, this means the editor content can be saved and restored automatically. The following persistence-related props are available: - `persistence` – Enables persistence (`True`, `"local"`, `"session"`, or `"memory"`). - `persisted_props` – Specifies which props should be persisted. By default it's `["html, json"]` - `persistence_type` – Defines where the data is stored (`"local"`, `"session"`, or `"memory"`). For more details on how Dash handles persistence, refer to the [Dash persistence documentation](https://dash.plotly.com/persistence). Notes: - The component must have an `id` for persistence to work. - If you want to set an initial value while also enabling persistence, set `persisted_props` to only the prop used for the initial value. For example `persisted_props=['html']`. ### Subtle Variant `variant="subtle"` removes borders from the controls groups, makes controls larger and reduces spacing of the toolbar: ```python import dash_mantine_components as dmc component = dmc.RichTextEditor( html="Subtle rich text editor variant", extensions=[ "StarterKit", "Underline", "Highlight", ], toolbar={ "sticky": True, "stickyOffset": 60, "variant": "subtle", "controlsGroups": [ [ "Bold", "Italic", "Underline", "Strikethrough", "ClearFormatting", "Highlight", "Code", ], ], }, ) ``` ### CSS Extensions As of DMC 1.2.0, RichTextEditor 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. #### RichTextEditor Selectors | Selector | Static Selector | Description | |----------------------------------|------------------------------------------------------|-------------| | `root` | `.mantine-RichTextEditor-root` | Root element | | `toolbar` | `.mantine-RichTextEditor-toolbar` | Toolbar element | | `content` | `.mantine-RichTextEditor-content` | Content area | | `typographyStylesProvider` | `.mantine-RichTextEditor-typographyStylesProvider` | TypographyStylesProvider component, wraps content | | `control` | `.mantine-RichTextEditor-control` | `RichTextEditor.Control` root element, used as a base for all controls | | `controlIcon` | `.mantine-RichTextEditor-controlIcon` | Control icon element | | `controlsGroup` | `.mantine-RichTextEditor-controlsGroup` | `RichTextEditor.ControlsGroup` component root | | `linkEditor` | `.mantine-RichTextEditor-linkEditor` | Link editor root element | | `linkEditorSave` | `.mantine-RichTextEditor-linkEditorSave` | Link editor save button | | `linkEditorInput` | `.mantine-RichTextEditor-linkEditorInput` | Link editor URL input | | `linkEditorExternalControl` | `.mantine-RichTextEditor-linkEditorExternalControl` | Link editor external button | | `linkEditorDropdown` | `.mantine-RichTextEditor-linkEditorDropdown` | Link editor popover dropdown element | #### RichTextEditor Data Attributes | Selector | Attribute | Condition | |-----------|--------------|---------------------------| | `control` | `data-active` | Control is active | ### Keyword Arguments #### RichTextEditor - 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. - debounce (number; optional): If True, changes will be sent back to Dash only when losing focus. If False, data will be sent on every change. If a number, data will be sent when the value has been stable for that number of milliseconds. - extensions (list; optional): List of extensions to be loaded by the editor. Each item can be either a string with the extension name (e.g. 'Color') or an object with the extension name as key and options as value (e.g. {'TextAlign': {'types': ['heading', 'paragraph']}}). ['StarterKit', 'Underline', 'Link', 'Superscript', 'Subscript', 'Highlight', 'Table', 'TableCell', 'TableHeader', 'TableRow', {'Placeholder': {'placeholder': 'Write or paste content here...'}}, {'TextAlign': {'types': ['heading', 'paragraph']}}, 'Color', 'TextStyle', 'Image'] by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - html (string; optional): HTML string representation of the editor content. Affected by debounce. If both json and html are provided, json takes precedence. - json (dict; optional): JSON object (ProseMirror) representation of the editor content. Affected by debounce. If both json and html are provide, json takes precedence. - labels (dict; optional): Labels that are used in controls. If not set, default labels are used. `labels` is a dict with keys: - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - n_blur (number; optional): An integer that represents the number of times that this element has lost focus. - 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; 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. - selected (string; optional): Currently selected text. Affected by debounce. - 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. - toolbar (dict; optional): Toolbar property definition. Empty by default. `toolbar` is a dict with keys: - variant (a value equal to: 'default', 'subtle'; optional): Variant of the editor. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. - withCodeHighlightStyles (boolean; optional): Determines whether code highlight styles should be added, True by default. - withTypographyStyles (boolean; optional): Determines whether typography styles should be added, True by default. ## SegmentedControl SegmentedControl is an alternative to RadioGroup and allows users to select an option from a small set of options. Category: Inputs ### Simple Example SegmentedControl is usually used as an alternative to Tabs (to switch views) and RadioGroup (to capture user feedback limited to certain options) ```python import dash_mantine_components as dmc from dash import Output, Input, html, callback component = html.Div( [ dmc.SegmentedControl( id="segmented", value="ng", data=[ {"value": "react", "label": "React"}, {"value": "ng", "label": "Angular"}, {"value": "svelte", "label": "Svelte"}, {"value": "vue", "label": "Vue"}, ], mb=10, ), dmc.Text(id="segmented-value"), ] ) @callback(Output("segmented-value", "children"), Input("segmented", "value")) def select_value(value): return value ``` ### Data Prop The data can be provided as either: * an array of strings - use when label and value are same. * an array of dicts with `label` and `value` properties (plus an optional `disabled` boolean). ```python data = ["React", "Angular", "Svelte", "Vue"] # or data = [ {"value": "React", "label": "React"}, {"value": "Angular", "label": "Angular"}, {"value": "Svelte", "label": "Svelte", "disabled": True}, {"value": "Vue", "label": "Vue"}, ] ``` ### Disabled To disable the entire component, use the `disabled` prop. To disable a SegmentedControl item, use the array of objects data format and set `disabled = True` on the item that you want to disable. ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Text("Disabled control"), dmc.SegmentedControl( disabled=True, data=[ {"value": "preview", "label": "Preview"}, {"value": "code", "label": "Code"}, {"value": "export", "label": "Export"}, ], ), dmc.Text("Disabled option"), dmc.SegmentedControl( data=[ {"value": "preview", "label": "Preview", "disabled": True}, {"value": "code", "label": "Code"}, {"value": "export", "label": "Export"}, ], ), ], align="flex-start", ) ``` ### Full Width and Orientation By default, SegmentedControl will take only the amount of space that is required to render elements. Set `fullWidth` prop to make it block and take 100% width of its container. The orientation can be set via `orientation` prop. ```python import dash_mantine_components as dmc dmc.SegmentedControl( orientation="horizontal", fullWidth=True, data=[] ) ``` ### Sizes SegmentedControl supports 5 sizes: xs, sm, md, lg, xl. Size controls font-size and padding properties. ```python import dash_mantine_components as dmc data = ["Dash", "Mantine", "Bootstrap", "Core"] component = dmc.Stack( [dmc.SegmentedControl(data=data, size=x) for x in ["xs", "sm", "md", "lg", "xl"]], align="flex-start", ) ``` ### Radius xs, sm, md, lg, xl radius values are defined in theme.radius. Alternatively, you can use a number to set radius in px. ```python import dash_mantine_components as dmc data = ["Dash", "Mantine", "Bootstrap", "Core"] component = dmc.Stack( [dmc.SegmentedControl(data=data, radius=x) for x in [0, "md", "lg", 20]], align="flex-start", ) ``` ### Color By default, SegmentedControl uses theme.white with shadow in light color scheme and theme.colors.dark[6] background color for active element. You can choose any color defined in theme.colors in case you need colored variant. ```python import dash_mantine_components as dmc dmc.SegmentedControl( color="red", data = [] ) ``` ### Transitions Change transition properties with: - `transitionDuration` – all transitions duration in ms (ignored if user prefers to reduce motion) - `transitionTimingFunction` – defaults to `theme.transitionTimingFunction` ```python import dash_mantine_components as dmc data = ["Dash", "Mantine", "Bootstrap", "Core"] component = dmc.Stack( [ dmc.Text("No transition"), dmc.SegmentedControl(data=data, transitionDuration=0), dmc.Text("500ms linear transition"), dmc.SegmentedControl( data=data, transitionDuration=500, transitionTimingFunction="linear" ), ], align="flex-start", ) ``` ### Components in label ```python import dash_mantine_components as dmc from dash import Output, Input, html, callback from dash_iconify import DashIconify data = [ ["Preview", "tabler:eye"], ["Code", "tabler:code"], ["Export", "tabler:external-link"], ] component = html.Div( [ dmc.SegmentedControl( id="segmented-with-react-nodes", value="Preview", data=[ { "value": v, "label": dmc.Center( [DashIconify(icon=icon, width=16), html.Span(v)], style={"gap": 10}, ), } for v, icon in data ], mb=10, ), dmc.Text(id="segmented--value-data"), ] ) @callback( Output("segmented--value-data", "children"), Input("segmented-with-react-nodes", "value"), ) def update_value(value): return value ``` ### 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-SegmentedControl-root | Root element | | control | .mantine-SegmentedControl-control | Wrapper element for input and label | | input | .mantine-SegmentedControl-input | Input element hidden by default | | label | .mantine-SegmentedControl-label | Label element associated with input | | indicator | .mantine-SegmentedControl-indicator | Floating indicator that moves between items | | innerLabel | .mantine-SegmentedControl-innerLabel | Wrapper of label element children | ### Keyword Arguments #### SegmentedControl - 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` of the indicator. If luminosity of the `color` prop is less than `theme.luminosityThreshold`, then `theme.white` will be used. - 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, changes color of indicator, by default color is based on current color scheme. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data (list of strings; required): Data based on which controls are rendered. - data-* (string; optional): Wild card data attributes. - disabled (boolean; optional): Determines whether the component is disabled. - fullWidth (boolean; optional): Determines whether the component should take 100% width of its parent, `False` by default. - hiddenFrom (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - name (string; optional): Name of the radio group, by default random name is generated. - orientation (a value equal to: 'horizontal', 'vertical'; optional): Determines in which orientation component id displayed, `'horizontal'` by default. - 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; 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. - readOnly (boolean; optional): Determines whether the value can be changed. - size (optional): Controls `font-size`, `padding` and `height` properties, `'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. - transitionDuration (number; optional): Indicator `transition-duration` in ms, set `0` to turn off transitions, `200` by default. - transitionTimingFunction (string; optional): Indicator `transition-timing-function` property, `ease` by default. - value (string; optional): Controlled component value. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. - withItemsBorders (boolean; optional): Determines whether there should be borders between items, `True` by default. ## Slider Use Slider component to capture user feedback from a range of values. Category: Inputs ### Introduction ### Simple Usage Use the `value` prop to get the value of the slider. ```python import dash_mantine_components as dmc from dash import callback, html, Output, Input component = html.Div( [ dmc.Slider( id="slider-callback", value=26, marks=[ {"value": 20, "label": "20%"}, {"value": 50, "label": "50%"}, {"value": 80, "label": "80%"}, ], mb=35, ), dmc.Text(id="slider-output"), ] ) @callback(Output("slider-output", "children"), Input("slider-callback", "value")) def update_value(value): return f"You have selected: {value}" ``` ### Range Slider Note: The `RangeSlider` has a `minRange` prop that defaults to 10. Make sure `minRange` is not greater than the slider's maximum value, or the slider won't work properly. ```python import dash_mantine_components as dmc from dash import callback, html, Output, Input component = html.Div( [ dmc.RangeSlider( id="range-slider-callback", value=[26, 50], marks=[ {"value": 20, "label": "20%"}, {"value": 50, "label": "50%"}, {"value": 80, "label": "80%"}, ], mb=35, ), dmc.Text(id="range-slider-output"), ] ) @callback( Output("range-slider-output", "children"), Input("range-slider-callback", "value") ) def update_value(value): return f"You have selected: [{value[0]}, {value[1]}]" ``` ### minRange Use `minRange` prop to control minimum range between from and to values in `RangeSlider`. The default value is 10. The example below shows how to use `minRange` prop to capture decimal values from the user: ```python import dash_mantine_components as dmc component = dmc.RangeSlider( minRange=0.2, min=0, max=1, step=0.0005, value=[0.1245, 0.5535] ) ``` ### Update Mode By default, slider value is updated once the user has stopped dragging the handle. But it can be changed by changing the `updatemode` to "drag" instead of "mouseup" (default). Below is a slider with `updatemode` set to "drag", observe how the output text changes as you drag the slider handle. ```python import dash_mantine_components as dmc from dash import callback, html, Output, Input component = html.Div( [ dmc.Slider( id="drag-slider", value=26, updatemode="drag", marks=[ {"value": 20, "label": "20%"}, {"value": 50, "label": "50%"}, {"value": 80, "label": "80%"}, ], ), dmc.Space(h=35), dmc.Text(id="drag-output"), ] ) @callback(Output("drag-output", "children"), Input("drag-slider", "value")) def update_value(value): return f"You have selected: {value}" ``` ### Control label To change label behavior and appearance, set the following props: - `label` – set to `None` to disable the label. You can also provide a formatter function (via `{"function": "..."}`) to customize the label text. The function receives the `value` as its argument. - `labelAlwaysOn` – if `True` – label will always be displayed, by default label is visible only when user is dragging - `labelTransitionProps` – props passed down to the `Transition` component, can be used to customize label animation 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.Stack([ dmc.Text("No label", size="sm"), dmc.Slider(value=40, label=None), dmc.Text("Label formatted with a function", size="sm", mt="xl"), dmc.Slider( value=40, label={"function": "celsiusLabel"} ), dmc.Text("Label always visible", size="sm", mt="xl"), dmc.Slider(value=40, labelAlwaysOn=True), dmc.Text("Custom label transition", size="sm", mt="xl"), dmc.Slider( value=40, labelTransitionProps={ "transition": "skew-down", "duration": 150, "timingFunction": "linear" } ), ]) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; dmcfuncs.celsiusLabel = (value) => `${value} °C`; ``` ### Min, Max, and Step You can set `min`, `max` and `step` values for `Slider` component. This will work even for negative and decimal values. ```python import dash_mantine_components as dmc component = dmc.Slider(min=-10, max=10, step=0.5) ``` The following example uses a function to format the `label` 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 marks = [ {"value": 0, "label": "xs"}, {"value": 25, "label": "sm"}, {"value": 50, "label": "md"}, {"value": 75, "label": "lg"}, {"value": 100, "label": "xl"}, ] component = dmc.Container([ dmc.Text("Decimal step"), dmc.Slider( value=0, min=-10, max=10, step=0.1, label={"function": "formatDecimal"}, styles={"markLabel": {"display": "none"}}, ), dmc.Text("Step matched with marks", mt="md"), dmc.Slider( value=50, step=25, marks=marks, label={"function": "labelFromMarks", "options": {"marks": marks}}, styles={"markLabel": {"display": "none"}}, ), ], p="xl") ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; dmcfuncs.formatDecimal = function (value) { return value.toFixed(1); }; dmcfuncs.labelFromMarks = function (value, { marks }) { const match = marks.find(m => m.value === value); return match ? match.label : null; }; ``` ### Domain By default, min and max values define the possible range of values. `domain` prop allows setting the possible range of values independently of the min and max values: ```python import dash_mantine_components as dmc component = dmc.Slider( domain=[0, 100], min=10, max=90, value=25, marks=[ { "value": 10, "label": 'min' }, { "value": 90, "label": 'max' }, ] ) ``` ### pushOnOverlap `pushOnOverlap` prop controls whether the thumbs should push each other when they overlap. By default, `pushOnOverlap` is `True`, if you want to disable this behavior, set it to `False`. Example of `pushOnOverlap=False`: ```python import dash_mantine_components as dmc component = dmc.RangeSlider( pushOnOverlap=False, minRange=20, value=[25, 65] ) ``` ### Marks Add any number of marks to the Slider by setting `marks` prop to an array of objects. ```python marks = [ { "value": 20 }, # displays mark on slider track { "value": 40, "label": '40%' }, # adds mark label below slider track ] ``` ### Restrict selection to marks Setting `restrictToMarks=True` ensures that users can only select values matching the specific marks defined. This feature is especially helpful when you have uneven or non-standard marks and want to ensure users can only pick from those specific points. Note: The `step` prop is ignored when `restrictToMarks=True`. ```python import dash_mantine_components as dmc component = dmc.Stack( [ # Slider dmc.Slider( restrictToMarks=True, value=25, marks=[{"value": index * 25} for index in range(5)], ), # RangeSlider dmc.RangeSlider( restrictToMarks=True, value=[5, 15], marks=[ {"value": 5}, {"value": 15}, {"value": 25}, {"value": 35}, {"value": 70}, {"value": 80}, {"value": 90}, ], ), ] ) ``` ### Disabled ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Slider(value=60, disabled=True), dmc.RangeSlider( mt="xl", mb="xl", value=[25, 75], disabled=True, marks=[ {"value": 0, "label": "xs"}, {"value": 25, "label": "sm"}, {"value": 50, "label": "md"}, {"value": 75, "label": "lg"}, {"value": 100, "label": "xl"}, ], ), ] ) ``` ### Thumb size ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Text("Standard size", size="sm"), dmc.Slider(value=40, label=None), dmc.Text("Thumb size number", size="sm", mt="xl"), dmc.Slider(value=40, thumbSize=50), ] ) ``` ### Thumb children ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = [ dmc.Slider( thumbChildren=DashIconify(icon="mdi:heart", width=16), color="red", label=None, value=40, thumbSize=26, styles={"thumb": {"borderWidth": 2, "padding": 3}}, ), dmc.RangeSlider( mt="xl", styles={"thumb": {"borderWidth": 2, "padding": 3}}, color="red", label=None, value=[20, 60], thumbSize=26, thumbChildren=[ DashIconify(icon="mdi:heart", width=16), DashIconify(icon="mdi:heart-broken", width=16), ], ), ] ``` ### Scale You can use the scale prop to represent the value on a different scale. In the following demo, the value x represents the value 2^x. Increasing x by one increases the represented value by 2 to the power of x. Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. ### Inverted You can invert the track by setting `inverted=True`: ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Slider(inverted=True, value=80), dmc.RangeSlider(inverted=True, value=[40, 60], mt="xl"), ] ) ``` ### Styling the Slider The `Slider` component can be fully customized using Mantine's Styles API. Each element of the `Slider` - from the thumb to the track markers - has its own unique selector that can be styled independently. Try the [interactive example](https://mantine.dev/core/slider/#styles-api) in the upstream Mantine documentation to see how these selectors correspond to different parts of the Slider component. Below, you'll find a comprehensive reference of all available selectors, CSS variables, and data attributes. Here is an example: ```python import dash_mantine_components as dmc component = dmc.Slider( value=79, marks=[ {"value": 20, "label": "20%"}, {"value": 50, "label": "50%"}, {"value": 80, "label": "80%"}, ], size=2, classNames={ "track": "dmc-slider-track", "mark": "dmc-slider-mark", "markLabel": "dmc-slider-markLabel", "thumb": "dmc-slider-thumb", }, ) ``` ```css .dmc-slider-track { &::before { background-color: light-dark(var(--mantine-color-blue-1), var(--mantine-color-dark-3)); } } .dmc-slider-mark { width: 6px; height: 6px; border-radius: 6px; transform: translateX(-3px) translateY(-2px); border-color: light-dark(var(--mantine-color-blue-1), var(--mantine-color-dark-3)); &[data-filled] { border-color: var(--mantine-color-blue-6); } } .dmc-slider-markLabel { font-size: var(--mantine-font-size-sm); color: var(--mantine-color-green-5); margin-bottom: 5px; margin-top: 0; } .dmc-slider-thumb { height: 16px; width: 16px; background-color: var(--mantine-color-green-5); border-width: 1px; box-shadow: var(--mantine-shadow-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. #### Slider selectors | Selector | Static selector | Description | |----------|----------------|-------------| | root | `.mantine-Slider-root` | Root element | | label | `.mantine-Slider-label` | Thumb label | | thumb | `.mantine-Slider-thumb` | Thumb element | | trackContainer | `.mantine-Slider-trackContainer` | Wraps track element | | track | `.mantine-Slider-track` | Slider track | | bar | `.mantine-Slider-bar` | Track filled part | | markWrapper | `.mantine-Slider-markWrapper` | Contains `mark` and `markLabel` elements | | mark | `.mantine-Slider-mark` | Mark displayed on track | | markLabel | `.mantine-Slider-markLabel` | Label of the associated mark, displayed below track | #### Slider CSS variables | Selector | Variable | Description | |----------|----------|-------------| | root | `--slider-size` | Controls track `height` | | root | `--slider-color` | Controls filled track, thumb and marks `background` | | root | `--slider-thumb-size` | Controls thumb `width` and `height` | | root | `--slider-radius` | Controls `border-radius` of track and thumb | #### Slider data attributes | Selector | Attribute | Condition | |----------|-----------|-----------| | trackContainer, track, bar, thumb, mark | `data-disabled` | `disabled` prop is set | | track, bar | `data-inverted` | `inverted` prop is set | | thumb | `data-dragging` | slider is being dragged | | mark | `data-filled` | mark position is less or equal slider value | ### Keyword Arguments #### Slider - 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. - color (optional): Key of `theme.colors` or any valid CSS color, controls color of track and thumb, `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): Disables slider. - domain (list of 2 elements: [number, number]; optional): Domain of the slider, defines the full range of possible values, `[min, max]` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - inverted (boolean; optional): Determines whether track value representation should be inverted, `False` by default. - label (a list of or a singular dash component, string or number; optional): Function to generate label (See https://www.dash-mantine-components.com/functions-as-props) or any react node to render instead, set to None to disable label. - labelAlwaysOn (boolean; optional): Determines whether the label should be visible when the slider is not being dragged or hovered, `False` by default. - labelTransitionProps (dict; optional): Props passed down to the `Transition` component, `{ transition: 'fade', duration: 0 }` by default. `labelTransitionProps` is a dict with keys: - 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: - marks (list of dicts; optional): Marks displayed on the track. `marks` is a list of dicts with keys: - max (number; optional): Maximum possible value, `100` by default. - min (number; optional): Minimal possible value, `0` by default. - mod (string; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - name (string; optional): Hidden input name, use with uncontrolled component. - 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; 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. - precision (number; optional): Number of significant digits after the decimal point. - radius (number; optional): Key of `theme.radius` or any valid CSS value to set `border-radius`, numbers are converted to rem, `'xl'` by default. - restrictToMarks (boolean; optional): Determines whether the selection should be only allowed from the given marks array, False by default. - scale (boolean | number | string | dict | list; optional): Function to generate scale (See https://www.dash-mantine-components.com/functions-as-props) A transformation function to change the scale of the slider. - showLabelOnHover (boolean; optional): Determines whether the label should be displayed when the slider is hovered, `True` by default. - size (number; optional): Controls size of the track, `'md'` by default. - step (number; optional): Number by which value will be incremented/decremented with thumb drag and arrows, `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. - thumbChildren (a list of or a singular dash component, string or number; optional): Content rendered inside thumb. - thumbLabel (string; optional): Thumb `aria-label`. - thumbSize (string | number; optional): Thumb `width` and `height`, by default value is computed based on `size` prop. - updatemode (a value equal to: 'mouseup', 'drag'; default 'mouseup'): Determines when the component should update its value property. If mouseup (the default) then the slider will only trigger its value when the user has finished dragging the slider. If drag, then the slider will update its value continuously as it is being dragged. - value (number; optional): Controlled component value. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. #### RangeSlider - 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. - color (optional): Key of `theme.colors` or any valid CSS color, controls color of track and thumb, `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): Disables slider. - domain (list of 2 elements: [number, number]; optional): Domain of the slider, defines the full range of possible values, `[min, max]` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - inverted (boolean; optional): Determines whether track values representation should be inverted, `False` by default. - label (a list of or a singular dash component, string or number; optional): Function to generate label (See https://www.dash-mantine-components.com/functions-as-props) or any react node to render instead, set to None to disable label. - labelAlwaysOn (boolean; optional): Determines whether the label should be visible when the slider is not being dragged or hovered, `False` by default. - labelTransitionProps (dict; optional): Props passed down to the `Transition` component, `{ transition: 'fade', duration: 0 }` by default. `labelTransitionProps` is a dict with keys: - 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: - marks (list of dicts; optional): Marks displayed on the track. `marks` is a list of dicts with keys: - max (number; optional): Maximum possible value, `100` by default. - maxRange (number; optional): Maximum range interval, `Infinity` by default. - min (number; optional): Minimal possible value, `0` by default. - minRange (number; optional): Minimal range interval, `10` by default. - mod (string; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - name (string; optional): Hidden input name, use with uncontrolled component. - 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; 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. - precision (number; optional): Number of significant digits after the decimal point. - pushOnOverlap (boolean; optional): Determines whether the other thumb should be pushed by the current thumb dragging when minRange/maxRange is reached, True by default. - radius (number; optional): Key of `theme.radius` or any valid CSS value to set `border-radius`, numbers are converted to rem, `'xl'` by default. - restrictToMarks (boolean; optional): Determines whether the selection should be only allowed from the given marks array, False by default. - scale (boolean | number | string | dict | list; optional): Function to generate scale (See https://www.dash-mantine-components.com/functions-as-props) A transformation function to change the scale of the slider. - showLabelOnHover (boolean; optional): Determines whether the label should be displayed when the slider is hovered, `True` by default. - size (number; optional): Controls size of the track, `'md'` by default. - step (number; optional): Number by which value will be incremented/decremented with thumb drag and arrows, `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. - thumbChildren (a list of or a singular dash component, string or number; optional): Content rendered inside thumb. - thumbFromLabel (string; optional): First thumb `aria-label`. - thumbSize (string | number; optional): Thumb `width` and `height`, by default value is computed based on `size` prop. - thumbToLabel (string; optional): Second thumb `aria-label`. - updatemode (a value equal to: 'mouseup', 'drag'; default 'mouseup'): Determines when the component should update its value property. If mouseup (the default) then the Rangeslider will only trigger its value when the user has finished dragging the Rangeslider. If drag, then the Rangeslider will update its value continuously as it is being dragged. - value (list of 2 elements: [number, number]; optional): Controlled component value. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Switch Use the Switch component to capture boolean input from user. Category: Inputs ### Introduction ### Callbacks Use the property `checked` to use dmc.Switch in callbacks. ```python import dash_mantine_components as dmc from dash import html, Output, Input, callback component = html.Div( [ dmc.Switch(id="switch-example", label="Use default settings.", checked=True), dmc.Space(h=10), dmc.Text(id="switch-settings"), ] ) @callback(Output("switch-settings", "children"), Input("switch-example", "checked")) def settings(checked): return f"Using {'default' if checked else 'custom'} settings" ``` ### Inner Labels ```python import dash_mantine_components as dmc component = dmc.Group( [ dmc.Switch(onLabel="ON", offLabel="OFF", radius="xl", size=x) for x in ["xs", "sm", "md", "lg", "xl"] ] ) ``` ### Radius and Size Set the radius and size of the Switch component using the `radius` and `size` prop respectively. ```python import dash_mantine_components as dmc dmc.Switch( size="lg", radius="sm", label="Enable this option", checked=True ) ``` ### Icon Labels You can also add icons in the switch labels. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Switch( offLabel=DashIconify(icon="radix-icons:moon", width=20), onLabel=DashIconify(icon="radix-icons:sun", width=20), size="xl", ) ``` ### Thumb Icon ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Switch( thumbIcon=DashIconify( icon="tabler:walk", width=16, color=dmc.DEFAULT_THEME["colors"]["teal"][5] ), size="lg", color="teal", checked=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-Switch-root | Root element | | track | .mantine-Switch-track | Switch track, contains `thumb` and `trackLabel` | | trackLabel | .mantine-Switch-trackLabel | Label displayed inside `track` | | thumb | .mantine-Switch-thumb | Thumb displayed inside `track` | | input | .mantine-Switch-input | Input element, hidden by default | | body | .mantine-Switch-body | Input body, contains all other elements | | labelWrapper | .mantine-Switch-labelWrapper | Contains `label`, `description` and `error` | | label | .mantine-Switch-label | Label element | | description | .mantine-Switch-description | Description displayed below the label | | error | .mantine-Switch-error | Error message displayed below the label | ### Keyword Arguments #### Switch - 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. - checked (boolean; optional): State of check box. - 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 set input color in checked state, `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. - description (a list of or a singular dash component, string or number; optional): Description displayed below the label. - disabled (boolean; optional): A checkbox can show it is currently unable to be interacted with. - error (a list of or a singular dash component, string or number; optional): Error displayed below the label. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - label (a list of or a singular dash component, string or number; optional): Content of the `label` associated with the radio. - labelPosition (a value equal to: 'left', 'right'; optional): Position of the label relative to the input, `'right'` 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 with strings as keys and values of type boolean | number | string | dict | list; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - offLabel (a list of or a singular dash component, string or number; optional): Inner label when the `Switch` is in unchecked state. - onLabel (a list of or a singular dash component, string or number; optional): Inner label when the `Switch` is in checked state. - 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; 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,` "xl" by default. - size (optional): Controls size of all elements. - 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. - thumbIcon (a list of or a singular dash component, string or number; optional): Icon inside the thumb of the switch. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. - withThumbIndicator (boolean; optional): If set, the indicator will be displayed inside thumb, `True` by default. - wrapperProps (dict; optional): Props passed down to the root element. `wrapperProps` is a dict with keys: ## TextInput Use TextInput component to capture string input from user. Customize the input with label, description, error message etc. Category: Inputs ### Introduction ### Invalid State and Error Use `error` prop to convey an error with an error message and a red border around the input. Note: Dash adds thick red outline to the input element with `:invalid` pseudo-class. This conflicts with Mantine. In order to correct this, just add the following css to your app. ```css input:invalid { outline: none !important; } ``` ```python import dash_mantine_components as dmc component = dmc.Stack( children=[ dmc.TextInput(label="Your Email:", w=200, error=True), dmc.TextInput(label="Your Email:", w=200, error="Enter a valid email"), ], ) ``` ### Disabled State Convey disabled input with `disabled` prop. ```python import dash_mantine_components as dmc component = dmc.TextInput(label="Disabled Input", w=200, disabled=True) ``` ### With Icon Add icon to the left side of the input. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.TextInput( label="Your Email", w=200, placeholder="Your Email", leftSection=DashIconify(icon="ic:round-alternate-email"), ) ``` ### With right section Add icon or loading indicator to the right section of the input. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Stack( children=[ dmc.TextInput( w=200, placeholder="9876543210", rightSection=DashIconify(icon="emojione-v1:mobile-phone"), ), dmc.TextInput( w=200, placeholder="9876543210", rightSection=dmc.Loader(size="xs"), ), ], ) ``` ### 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-TextInput-wrapper | Root element of the Input | | input | .mantine-TextInput-input | Input element | | section | .mantine-TextInput-section | Left and right sections | | root | .mantine-TextInput-root | Root element | | label | .mantine-TextInput-label | Label element | | required | .mantine-TextInput-required | Required asterisk element, rendered inside label | | description | .mantine-TextInput-description | Description element | | error | .mantine-TextInput-error | Error element | ### Keyword Arguments #### TextInput - 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. - autoComplete (string; default 'off'): (string; default "off") Enables the browser to attempt autocompletion based on user history. For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete. - 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. - debounce (number; 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. - 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. - hiddenFrom (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', 'input', 'description', 'error'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', 'none', 'auto', '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`. - 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 with strings as keys and values of type boolean | number | string | dict | list; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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. - 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; 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. - 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', 'none', 'auto', '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 (optional): Controls input `height` and horizontal `padding`, `'sm'` by default. - spellCheck (boolean; optional): Spell check property. - 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; default ''): Value for controlled input. - variant (string; optional): variant. - visibleFrom (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. - wrapperProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional): Props passed down to the root element. ## Textarea Use Textarea component to capture string input in a text area with an auto-size variant. Customize the input with label, description, error message etc. Category: Inputs ### Introduction ### Autosize Textarea will grow until `maxRows` are reached or indefinitely if `maxRows` is not set. ```python import dash_mantine_components as dmc component = dmc.Stack( children=[ dmc.Textarea( label="Autosize with no rows limit", placeholder="Autosize with no rows limit", w=500, autosize=True, minRows=2, ), dmc.Textarea( label="Autosize with 4 rows max", placeholder="Autosize with 4 rows max", w=500, autosize=True, minRows=2, maxRows=4, ), ], ) ``` ### Invalid State and Error Use `error` prop to convey an error with an error message and a red border around the input. Note: Dash adds thick red outline to the input element with `:invalid` pseudo-class. This conflicts with Mantine. In order to correct this, just add the following css to your app. ```css input:invalid { outline: none !important; } ``` ```python import dash_mantine_components as dmc component = dmc.Stack( children=[ dmc.Textarea(label="Your message", w=500, error=True), dmc.Textarea(label="Your message", w=500, error="Message can't be empty!"), ], ) ``` ### inputProps Use the `inputProps` dictionary to pass attributes directly to the underlying [`` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#attributes). In this example, `maxLength` is used to limit the number of characters a user can enter. ```python import dash_mantine_components as dmc component = dmc.Textarea( inputProps={"maxLength": 3}, label="Enter text", description="Max length of 3 characters", ) ``` ### 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-Textarea-wrapper | Root element of the Input | | input | .mantine-Textarea-input | Input element | | section | .mantine-Textarea-section | Left and right sections | | root | .mantine-Textarea-root | Root element | | label | .mantine-Textarea-label | Label element | | required | .mantine-Textarea-required | Required asterisk element, rendered inside label | | description | .mantine-Textarea-description | Description element | | error | .mantine-Textarea-error | Error element | ### Keyword Arguments #### Textarea - 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. - autoComplete (string; default 'off'): (string; default "off") Enables the browser to attempt autocompletion based on user history. For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete. - autosize (boolean; optional): Determines whether the textarea height should grow with its content, `False` 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. - debounce (number; 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. - 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. - hiddenFrom (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', 'input', 'description', 'error'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', 'none', 'auto', '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`. - 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: - maxRows (number; optional): Maximum rows for autosize textarea to grow, ignored if `autosize` prop is not set. - minRows (number; optional): Minimum rows of autosize textarea, ignored if `autosize` prop is not set. - mod (string | dict with strings as keys and values of type boolean | number | string | dict | list; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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. - 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; 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. - required (boolean; optional): Adds required attribute to the input and a red asterisk on the right side of label, `False` by default. - resize (a value equal to: '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'none', 'block', 'inline', 'both', 'horizontal', 'vertical'; optional): Controls `resize` CSS property, `'none'` 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', 'none', 'auto', '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 (optional): Controls input `height` and horizontal `padding`, `'sm'` by default. - spellCheck (boolean; optional): Spell check property. - 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; default ''): Content. - variant (string; optional): variant. - visibleFrom (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. - wrapperProps (dict with strings as keys and values of type boolean | number | string | dict | list; optional): Props passed down to the root element. ## AppShell Responsive shell for your application with header, navbar, aside and footer. Category: Layout ### Examples Since `AppShell` components have fixed position, it is not possible to include live demos on this page. Please see the code in the [dmc-docs GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell). Or run the app and edit the code on **[PyCafe](https://py.cafe/dash.mantine.components)**. 1. Basic AppShell with Header and Navbar - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/basic_appshell.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/basic-appshell-collapsible-navbar) ```python """ Basic Appshell with header and navbar that collapses on mobile. """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger(id="burger", size="sm", hiddenFrom="sm", opened=False), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( id="navbar", children=[ "Navbar", *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], p="md", ), dmc.AppShellMain("Main"), ], header={"height": 60}, padding="md", navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def navbar_is_open(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` 2. Responsive Width and Height - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/responsive_sizes.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/appshell-responsive-width-height) ```python """ Responsive width and height App shell with responsive navbar width and height """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger( id="burger", size="sm", hiddenFrom="sm", opened=False, ), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( id="navbar", children=[ "Navbar", *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], p="md", ), dmc.AppShellMain("Main"), ], header={ "height": {"base": 60, "md": 70, "lg": 80}, }, navbar={ "width": {"base": 200, "md": 300, "lg": 400}, "breakpoint": "sm", "collapsed": {"mobile": True}, }, padding="md", id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def toggle_navbar(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` 3. Mobile-Only Navbar - Buttons in the header are displayed in the navbar on mobile. - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/mobile_navbar.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/responsive-mobile-navbar-demo) ```python """ Mobile only navbar Navbar is only visible on mobile, links that are rendered in the header on desktop are hidden on mobile in header and rendered in navbar instead. """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" buttons = [ dmc.Button("Home", variant="subtle", color="gray"), dmc.Button("Blog", variant="subtle", color="gray"), dmc.Button("Contacts", variant="subtle", color="gray"), dmc.Button("Support", variant="subtle", color="gray"), ] layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Group( [ dmc.Burger( id="burger", size="sm", hiddenFrom="sm", opened=False, ), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ] ), dmc.Group( children=buttons, ml="xl", gap=0, visibleFrom="sm", ), ], justify="space-between", style={"flex": 1}, h="100%", px="md", ), ), dmc.AppShellNavbar( id="navbar", children=buttons, py="md", px=4, ), dmc.AppShellMain( "Navbar is only visible on mobile, links that are rendered in the header on desktop are hidden on mobile in header and rendered in navbar instead." ), ], header={"height": 60}, navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"desktop": True, "mobile": True}, }, padding="md", id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def toggle_navbar(opened, navbar): navbar["collapsed"] = {"mobile": not opened, "desktop": True} return navbar if __name__ == "__main__": app.run(debug=True) ``` 4. Collapsible Navbar on Desktop and Mobile - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/responsive_sizes.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/Collapsible-navbar-on-both-desktop-and-moble) ```python """ Responsive width and height App shell with responsive navbar width and height """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger( id="burger", size="sm", hiddenFrom="sm", opened=False, ), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( id="navbar", children=[ "Navbar", *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], p="md", ), dmc.AppShellMain("Main"), ], header={ "height": {"base": 60, "md": 70, "lg": 80}, }, navbar={ "width": {"base": 200, "md": 300, "lg": 400}, "breakpoint": "sm", "collapsed": {"mobile": True}, }, padding="md", id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def toggle_navbar(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` 5. Full AppShell Layout - Includes all elements: navbar, header, aside, and footer. - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/full_layout.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/AppShell-with-all-elements) ```python """ AppShell with all elements Navbar, header, aside and footer used together """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger( id="burger", size="sm", hiddenFrom="sm", opened=False, ), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( id="navbar", children=[ "Navbar", *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], p="md", ), dmc.AppShellMain( "Aside is hidden on md breakpoint and cannot be opened when it is collapsed" ), dmc.AppShellAside("Aside", p="md"), dmc.AppShellFooter("Footer", p="md"), ], header={"height": 60}, footer={"height": 60}, navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, aside={ "width": 300, "breakpoint": "md", "collapsed": {"desktop": False, "mobile": True}, }, padding="md", id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def toggle_navbar(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` 6. Scrollable Navbar with 60 Links - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/navbar_scroll.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/Appshell-with-scrollable-navbar) ```python """ Scrollable Navbar with 60 links """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger(id="burger", size="sm", hiddenFrom="sm", opened=False), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( id="navbar", children=dmc.ScrollArea( [ "60 links in a scrollable section", *[ dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(60) ], ] ), p="md", ), dmc.AppShellMain("Main"), ], header={"height": 60}, padding="md", navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def navbar_is_open(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` 7. Alternate AppShell Layout - Navbar and aside are rendered on top of the header and footer. - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/alt_layout.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/dash-alt-layout-appshell) ```python """ Alt Layout Navbar and Aside are rendered on top on Header and Footer """ import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger(id="burger", size="sm", hiddenFrom="sm", opened=False), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( p="md", children=[ dmc.Group( [ dmc.Burger( id="navbar-burger", size="sm", hiddenFrom="sm", opened=False ), dmc.Text("Navbar"), ] ), *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], ), dmc.AppShellMain( "Alt layout – Navbar and Aside are rendered on top of Header and Footer" ), dmc.AppShellAside("Aside", p="md"), dmc.AppShellFooter("Footer", p="md"), ], layout="alt", header={"height": 60}, footer={"height": 60}, navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, aside={ "width": 300, "breakpoint": "md", "collapsed": {"desktop": False, "mobile": True}, }, padding="md", id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def toggle_navbar(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` 8. AppShell with Theme Switch Component - [View Code on GitHub](https://github.com/snehilvj/dmc-docs/tree/main/help_center/appshell/appshell_with_theme_switch.py) - [Live Demo on PyCafe](https://py.cafe/dash.mantine.components/dash-mantine-theme-toggle-app) ```python """ Basic Appshell with header and navbar that collapses on mobile. Also includes a theme switch. """ import dash_mantine_components as dmc from dash_iconify import DashIconify from dash import Dash, Input, Output, State, callback, clientside_callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" theme_toggle = dmc.Switch( offLabel=DashIconify( icon="radix-icons:sun", width=15, color=dmc.DEFAULT_THEME["colors"]["yellow"][8] ), onLabel=DashIconify( icon="radix-icons:moon", width=15, color=dmc.DEFAULT_THEME["colors"]["yellow"][6], ), id="color-scheme-toggle", persistence=True, color="grey", ) layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Group( [ dmc.Burger( id="burger", size="sm", hiddenFrom="sm", opened=False, ), dmc.Image(src=logo, h=40, flex=0), dmc.Title("Demo App", c="blue"), ] ), theme_toggle, ], justify="space-between", style={"flex": 1}, h="100%", px="md", ), ), dmc.AppShellNavbar( id="navbar", children=[ "Navbar", *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], p="md", ), dmc.AppShellMain("Main"), ], header={"height": 60}, padding="md", navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def navbar_is_open(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar clientside_callback( """ (switchOn) => { document.documentElement.setAttribute('data-mantine-color-scheme', switchOn ? 'dark' : 'light'); return window.dash_clientside.no_update } """, Output("color-scheme-toggle", "id"), Input("color-scheme-toggle", "checked"), ) if __name__ == "__main__": app.run(debug=True) ``` ### Basic usage AppShell is a layout component. It can be used to implement a common Header - Navbar - Footer - Aside layout pattern. All AppShell components have `position: fixed` style - they are not scrolled with the page. The documentation app that you are viewing uses AppShell with Header, Aside, and Navbar. This is the code for the first example above for the basic app shell with header and navbar. The navbar collapses on mobile. ```python import dash_mantine_components as dmc from dash import Dash, Input, Output, State, callback app = Dash() logo = "https://github.com/user-attachments/assets/c1ff143b-4365-4fd1-880f-3e97aab5c302" layout = dmc.AppShell( [ dmc.AppShellHeader( dmc.Group( [ dmc.Burger(id="burger", size="sm", hiddenFrom="sm", opened=False), dmc.Image(src=logo, h=40), dmc.Title("Demo App", c="blue"), ], h="100%", px="md", ) ), dmc.AppShellNavbar( id="navbar", children=[ "Navbar", *[dmc.Skeleton(height=28, mt="sm", animate=False) for _ in range(15)], ], p="md", ), dmc.AppShellMain("Main"), ], header={"height": 60}, padding="md", navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, id="appshell", ) app.layout = dmc.MantineProvider(layout) @callback( Output("appshell", "navbar"), Input("burger", "opened"), State("appshell", "navbar"), ) def navbar_is_open(opened, navbar): navbar["collapsed"] = {"mobile": not opened} return navbar if __name__ == "__main__": app.run(debug=True) ``` ### AppShell components * `AppShell` - root component, it is required to wrap all other components, used to configure layout properties * `AppShellHeader` - section rendered at the top of the page * `AppShellNavbar` - section rendered on the left side of the page * `AppShellAside` - section rendered on the right side of the page * `AppShellFooter` - section rendered at the bottom of the page * `AppShellMain` - main section rendered at the center of the page, has static position, all other sections are offset by its padding * `AppShellSection` - utility component that can be used to render group of content inside `AppShellNavbar` and `AppShellAside` ### AppShell Configuration `AppShell` component accepts, `header`, `footer`, `navbar` and `aside` props to configure corresponding sections. It is required to set these props if you want to use corresponding components. For example, if you want to use `AppShellHeader` component, you need to set `header` prop on the `AppShell` component. ### header and footer properties `header` and `footer` configuration dictionaries are the same and have the following properties: - `height`: Height of the section: number, string or dict with breakpoints as keys and height as value - `collapsed`: boolean; If section is collapsed it is hidden from the viewport and is not offset in `AppShellMain` - `offset`: boolean; Determines whether the section should be offset by the `AppShellMain`. For example, it is useful if you want to hide header based on the scroll position. ### navbar and aside properties `navbar` and `aside` configuration dictionaries are the same as well and have the following properties: - `width`: Width of the section: number, string or dict with breakpoints as keys and width as value - `breakpoint`: Breakpoint at which section should switch to mobile mode. In mobile mode the section always has 100% width and its collapsed state is controlled by the `collapsed.mobile` instead of `collapsed.desktop` - `collapsed`: Determines whether the section should be collapsed. Example: {"desktop": False; "mobile": True }; ### layout prop `layout` prop controls how `AppShellHeader` / `AppShellFooter` and `AppShellNavbar` / `AppShellAside` are positioned relative to each other. It accepts `alt` and `default` values: - `alt` – `AppShellNavbar`/`AppShellAside` height is equal to viewport height, `AppShellHeader`/`AppShellFooter` width is equal to viewport width less the `AppShellNavbar` and `AppShellAside` width. See example #7 above. - `default` – `AppShellNavbar`/`AppShellAside` height is equal to viewport height - `AppShellHeader`/ `AppShellFooter` height, `AppShellHeader`/`AppShellFooter` width is equal to viewport width ### height prop `height` property in `header` and `footer` configuration dicts works the following way: - If you pass a number, the value will be converted to rem and used as height at all viewport sizes. - To change height based on viewport width, use dict with breakpoints as keys and height as values. It works the same way as `style` props. Examples: ```python # Height is a number, it will be converted to rem and used as height at all viewport sizes dmc.AppShell( children=[ dmc.AppShellHeader("Header") # ... ], header={"height": 48} ) ``` ```python # Height is an dict with breakpoints: # - height is 48 when viewport width is < theme.breakpoints.sm # - height is 60 when viewport width is >= theme.breakpoints.sm and < theme.breakpoints.lg # - height is 76 when viewport width is >= theme.breakpoints.lg dmc.AppShell( children=[ dmc.AppShellHeader("Header") ], header={"height": {"base": 48, "sm": 60, "lg": 76}} ) ``` ### Width configuration `width` property in `navbar` and `aside` configuration dictionaries works the following way: - If you pass a number, the value will be converted to rem and used as width when the viewport is larger than breakpoint. - To change `width` based on viewport width, use dict with breakpoints as keys and width as values. It works the same way as `style` props. Note that width is always 100% when the viewport is smaller than breakpoint. Examples ```python # Width is a number, it will be converted to rem and used as width when viewport is larger than theme.breakpoints.sm dmc.AppShell( children=[ dmc.AppShellNavbar("Navbar") # ... ], navbar={"width": 48, "breakpoint": "sm"} ) ``` ```python # Width is an object with breakpoints: # - width is 100% when viewport width is < theme.breakpoints.sm # - width is 200 when viewport width is >= theme.breakpoints.sm and < theme.breakpoints.lg # - width is 300 when viewport width is >= theme.breakpoints.lg dmc.AppShell( children=[ dmc.AppShellNavbar("Navbar") # ... ], navbar={"width": {"sm": 200, "lg": 300 }, "breakpoint": 'sm' } ) ``` ### padding prop `padding` prop controls the padding of the `AppShellMain` component. It is important to use it instead of setting padding on the `AppShellMain` directly because padding of the `AppShellMain` is also used to offset `AppShellHeader`, `AppShellNavbar`, `AppShellAside` and `AppShellFooter` components. `padding` prop works the same way as `style` props and accepts numbers, strings and dicts with breakpoints as keys and padding as values. You can reference theme.spacing values or use any valid CSS values. ```python # Padding is always theme.spacing.md dmc.AppShell( # content padding="md" ) ``` ```python # Padding is: # - 10 when viewport width is < theme.breakpoints.sm # - 15 when viewport width is >= theme.breakpoints.sm and < theme.breakpoints.lg # - theme.spacing.xl when viewport width is >= theme.breakpoints.lg dmc.AppShell( # content padding={"base": 10, "sm": 15, "lg": "xl" } ) ``` ### Collapsed navbar/aside configuration `navbar` and `aside` props have `collapsed` property. The property accepts an dict { mobile: boolean; desktop: boolean } which allows to configure collapsed state depending on the viewport width. See example #4 above: Collapsible Navbar on Desktop and Mobile ### withBorder prop `withBorder` prop is available on `AppShell` and associated sections: `AppShellHeader`, `AppShellNavbar`, `AppShellAside` and `AppShellFooter`. By default, `withBorder` prop is True – all components have a border on the side that is adjacent to the `AppShellMain` component. For example, `AppShellHeader` is located at the top of the page – it has a border on the bottom side, `AppShellNavbar` is located on the left side of the page – it has a border on the right side. To remove the border from all components, set `withBorder=False` on the `AppShell`: ```python dmc.AppShell(withBorder=False) ``` To remove the border from a specific component, set `withBorder=False` on that component: ```python dmc.AppShell( children=[ dmc.AppShellHeader(withBorder=False) ] ) ``` ### zIndex prop `zIndex` prop is available on AppShell and associated sections: `AppShellHeader`, `AppShellNavbar`, `AppShellAside` and `AppShellFooter`. By default, all sections z-index is 200. To change z-index of all sections, set `zIndex` prop on the AppShell: ```python import dash_mantine_components as dmc dmc.AppShell( zIndex=100, children=[ # content ] ) ``` To change z-index of individual sections, set `zIndex` prop on each of them: ```python import dash_mantine_components as dmc dmc.AppShell( children=[ dmc.AppShellHeader("Header", zIndex=2000), dmc.AppShellNavbar("Navbar", zIndex=2000), ] ) ``` ### Control transitions Set `transitionDuration` and `transitionTimingFunction` props on the `AppShell` to control transitions: ```python dmc.AppShell( transitionDuration=500, transitionTimingFunction="ease" , ) ``` ### disabled prop Set `disabled` prop on the `AppShell` to prevent all sections except `AppShellMain` from rendering. It is useful when you want to hide the shell on some pages of your application. ```python dmc.AppShell(disabled=True) ``` ### Usage in docs ```python import dash_mantine_components as dmc dmc.AppShell( [ dmc.AppShellHeader("Header", px=25), dmc.AppShellNavbar("Navbar"), dmc.AppShellAside("Aside", withBorder=False), dmc.AppShellMain(children=[...]), ], header={"height": 70}, padding="xl", navbar={ "width": 300, "breakpoint": "sm", "collapsed": {"mobile": True}, }, aside={ "width": 300, "breakpoint": "xl", "collapsed": {"desktop": False, "mobile": 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. #### AppShell Selectors | Selector | Static selector | Description | |----------|-----------------------------|-----------------------------------| | root | .mantine-AppShell-root | Root element (AppShell component) | | navbar | .mantine-AppShell-navbar | AppShell.Navbar root element | | header | .mantine-AppShell-header | AppShell.Header root element | | main | .mantine-AppShell-main | AppShell.Main root element | | aside | .mantine-AppShell-aside | AppShell.Aside root element | | footer | .mantine-AppShell-footer | AppShell.Footer root element | | section | .mantine-AppShell-section | AppShell.Section root element | #### AppShell CSS Variables | Selector | Variable | Description | |----------|------------------------------------------|-----------------------------------------------| | root | --app-shell-transition-duration | Controls transition duration of all children | | | --app-shell-transition-timing-function | Controls transition timing function of all children | #### AppShell Data Attributes | Selector | Attribute | Condition | Value | |------------------|-------------------|------------------------------|--------------------------------------| | root | data-resizing | User is resizing the window | – | | root | data-layout | – | Value of the `layout` prop | | root | data-disabled | `disabled` prop is set | – | | navbar, header, aside, footer | data-with-border | `withBorder` prop is set either on the AppShell or on the associated component | – | | section | data-grow | `grow` prop is set on the AppShell.Section | – | ### Keyword Arguments ### AppShell - children (a list of or a singular dash component, string or number; required): Content. - id (string; optional): Unique ID to identify this component in Dash callbacks. - aria-* (string; optional): Wild card aria attributes. - aside (dict; optional): AppShell.Aside configuration, controls width, breakpoints and collapsed state. Required if you use AppShell.Aside component. `aside` 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. - 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): If set, Navbar, Aside, Header and Footer components be hidden. - footer (dict; optional): AppShell.Footer configuration, controls height, offset and collapsed state. Required if you use AppShell.Footer component. `footer` is a dict with keys: - header (dict; optional): AppShell.Header configuration, controls height, offset and collapsed state. Required if you use AppShell.Header component. `header` is a dict with keys: - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - layout (a value equal to: 'default', 'alt'; optional): Determines how Navbar/Aside are arranged relative to Header/Footer, `default` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - navbar (dict; optional): AppShell.Navbar configuration, controls width, breakpoints and collapsed state. Required if you use AppShell.Navbar component. `navbar` is a dict with keys: - offsetScrollbars (boolean; optional): Determines whether Header and Footer components should include styles to offset scrollbars. Based on `react-remove-scroll`. `True` by default. - padding (number; optional): Controls padding of the main section, `0` by default. !important!: use `padding` prop instead of `p`. - 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): Duration of all transitions in ms, `200` by default. - transitionTimingFunction (optional): Timing function of all transitions, `ease` by default. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. - withBorder (boolean; optional): Determines whether associated components should have a border, `True` by default. - zIndex (string | number; optional): `z-index` of all associated elements, `200` by default. #### Navbar - children (a list of or a singular dash component, string or number; required): 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. - withBorder (boolean; optional): Determines whether component should have a border, overrides `withBorder` prop on `AppShell` component. - zIndex (string | number; optional): Component `z-index`, by default inherited from the `AppShell`. #### Header - children (a list of or a singular dash component, string or number; required): 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. - withBorder (boolean; optional): Determines whether component should have a border, overrides `withBorder` prop on `AppShell` component. - zIndex (string | number; optional): Component `z-index`, by default inherited from the `AppShell`. #### Aside - children (a list of or a singular dash component, string or number; required): 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. - withBorder (boolean; optional): Determines whether component should have a border, overrides `withBorder` prop on `AppShell` component. - zIndex (string | number; optional): Component `z-index`, by default inherited from the `AppShell`. #### Footer - children (a list of or a singular dash component, string or number; required): 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. - withBorder (boolean; optional): Determines whether component should have a border, overrides `withBorder` prop on `AppShell` component. - zIndex (string | number; optional): Component `z-index`, by default inherited from the `AppShell`. #### Section - children (a list of or a singular dash component, string or number; required): 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. - grow (boolean; optional): Determines whether the section should take all available space, `False` by default. - hiddenFrom (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## AspectRatio Use the Aspect component to maintain responsive consistent width/height ratio. Category: Layout ### Image ```python import dash_mantine_components as dmc component = dmc.AspectRatio( dmc.Image( src="https://www.nasa.gov/wp-content/uploads/2022/07/web_first_images_release.png", alt="Carina Nebula", ), ratio=4/3, ) ``` ### Map embed ```python import dash_mantine_components as dmc from dash import html component = dmc.AspectRatio( html.Iframe( src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3025.3063874233135!2d-74.04668908358428!3d40.68924937933441!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89c25090129c363d%3A0x40c6a5770d25022b!2sStatue%20of%20Liberty%20National%20Monument!5e0!3m2!1sen!2sru!4v1644262070010!5m2!1sen!2sru", title="Google map", ), ratio=16 / 9, ) ``` ### Video embed ```python import dash_mantine_components as dmc from dash import html component = dmc.AspectRatio( html.Iframe( src="https://www.youtube.com/embed/KsTKREWoVC4", title="YouTube video player", allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen", ), ratio=16 / 9, ) ``` ### Inside flex container By default, `AspectRatio` does not have fixed width and height, it will take as much space as possible in a regular container. To make it work inside flex container, you need to set `width` or `flex` property. ```python import dash_mantine_components as dmc from dash import html component = html.Div( dmc.AspectRatio( ratio=1, style={"flex": "0 0 100px"}, children=[ dmc.Image( src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-6.png", alt="Avatar", ) ], ), style={"display": "flex"}, ) ``` ### 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. #### AspectRatio Selectors | Selector | Static selector | Description | |----------|----------------------------------|---------------| | root | .mantine-AspectRatio-root | Root element | --- #### AspectRatio CSS Variables | Selector | Variable | Description | |----------|---------------|-----------------| | root | --ar-ratio | Aspect ratio | ### Keyword Arguments #### AspectRatio - children (a list of or a singular dash component, string or number; optional) - 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - ratio (number; optional): Aspect ratio, e.g. `16 / 9`, `4 / 3`, `1920 / 1080`, `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. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Center Use Center component to center content vertically and horizontally. Category: Layout ### Simple Example ```python import dash_mantine_components as dmc component = dmc.Center( style={"height": 200, "width": "100%"}, children=[ dmc.Badge("Free", style={"marginRight": 5}), dmc.Anchor("Click now!", href="https://mantine.dev/"), ], ) ``` ### Inline To use `Center` with inline elements set `inline` prop. For example, you can center link icon and label: ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Box( dmc.Anchor( href="https://mantine.dev", target="_blank", children=dmc.Center( [ DashIconify( icon="tabler:arrow-left", # Use the Tabler Arrow Left icon width=12, height=12, ), dmc.Box("Back to Mantine website", ml=5), ], inline=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-Card-root | Root element | ### Keyword Arguments #### Center - children (a list of or a singular dash component, string or number; optional) - 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 (optional): Breakpoint above which the component is hidden with `display: none`. - inline (boolean; optional): Determines whether `inline-flex` should be used instead of `flex`, `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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Container Container is the most basic layout element, it centers content horizontally and adds horizontal padding from theme. Category: Layout ### Simple Example Container is the most basic layout element, it centers content horizontally and adds horizontal padding from Mantine's theme. Component accepts these props: * `size` – controls default max width * `fluid` – overwrites size prop and sets max width to 100% ```python import dash_mantine_components as dmc from dash import html style = { "height": 100, "border": f"1px solid {dmc.DEFAULT_THEME['colors']['indigo'][4]}", "marginTop": 20, "marginBottom": 20, } component = html.Div( children=[ dmc.Container("Default container", style=style), dmc.Container( "xs container with xs horizontal padding", size="xs", px="xs", style=style ), dmc.Container( "200px container with 0px horizontal padding", size=200, px=0, style=style ), ] ) ``` ### Fluid Set `fluid` prop to make container fluid, it will take 100% of available width, it is the same as setting `size="100%"`. ```python import dash_mantine_components as dmc from dash import html component = dmc.Container( "Fluid container has 100% max-width", fluid=True, h=50, bg="var(--mantine-color-blue-light)" ) ``` ### Grid strategy Starting from 2.2.0, `Container` supports `strategy="grid"` prop which enables more features. Differences from the default `strategy="block"`: - Uses `display: grid` instead of `display: block` - Does not include default inline padding - Does not set `max-width` on the root element (uses grid template columns instead) Features supported by `strategy="grid"`: - Everything that is supported by `strategy="block"` - Children with `data-breakout` attribute take the entire width of the container's parent element - Children with `data-container` inside `data-breakout` have the same width as the main grid column Example of using breakout feature: ```python import dash_mantine_components as dmc from dash import html component = dmc.Container( [ dmc.Box("Main Content", bg="var(--mantine-color-indigo-light)", h=50), html.Div( [ "Breakout", html.Div( "Container inside breakout", style={ "backgroundColor": "var(--mantine-color-indigo-filled)", "color": "white", "height": 50, }, **{"data-container": ""} ), ], style={ "backgroundColor": "var(--mantine-color-indigo-light)", "marginTop": 16, }, **{"data-breakout": ""} ), ], size=500, strategy="grid", ) ``` **Note — Adding custom HTML attributes to Dash components:** * For `dash-html-components`, you can add custom attributes using Python’s `**` unpacking syntax: ```python html.Div(**{"data-breakout": ""}) ``` * For DMC components that support the [Styles API](/styles-api), use the `attributes` prop to pass attributes to elements of the component: ```python dmc.Paper(attributes={"root": "data-breakout"}) ``` ### 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. #### Container Selectors | Selector | Static selector | Description | |----------|-----------------------------|---------------| | root | .mantine-Container-root | Root element | #### Container CSS Variables | Selector | Variable | Description | |----------|-------------------|---------------------------| | root | --container-size | Controls container max-width | ### Keyword Arguments #### Container - children (a list of or a singular dash component, string or number; optional) - 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. - fluid (boolean; optional): Determines whether the container should take 100% of its parent width. If set, `size` prop is ignored. `False` by default. - hiddenFrom (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - size (number; optional): Sets `max-width` of the container, value is not responsive – it is the same for all screen sizes. Numbers are converted to rem. Ignored when `fluid` prop is set. `'md'` by default. - strategy (a value equal to: 'block', 'grid'; optional): Centering strategy. Default value: 'block'. - 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Flex Use the Flex component to compose elements in a flex container. Category: Layout ### Introduction ### Supported Props | Prop | CSS Property | Theme Key | |-------------|------------------|-----------------| | gap | gap | theme.spacing | | rowGap | rowGap | theme.spacing | | columnGap | columnGap | theme.spacing | | align | alignItems | – | | justify | justifyContent | – | | wrap | flexWrap | – | | direction | flexDirection | – | ### Responsive Props Flex component props can have responsive values the same way as other style props: ```python import dash_mantine_components as dmc component = dmc.Flex( [ dmc.Button("Button 1"), dmc.Button("Button 2"), dmc.Button("Button 3"), ], direction={"base": "column", "sm": "row"}, gap={"base": "sm", "sm": "lg"}, justify={"sm": "center"}, ) ``` ### Comparison: Group, Stack, and Flex `Flex` component is an alternative to `Group` and `Stack`. `Flex` is more flexible, it allows creating both horizontal and vertical flexbox layouts, but requires more configuration. | Feature | Group | Stack | Flex | |----------------------------|-------|-------|------| | Direction | horizontal | vertical | both | | Equal width children | ✅ | ❌ | ❌ | | flex-wrap support | ✅ | ❌ | ✅ | | Responsive flexbox props | ❌ | ❌ | ✅ | ### Browser support `Flex` uses flexbox gap to add spacing between children. In older browsers, `Flex` children may not have spacing. ### 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-Flex-root | Root element | ### Keyword Arguments #### Flex - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - align (optional): `align-items` CSS property. - 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. - columnGap (number; optional): `column-gap` CSS property. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - direction (optional): `flex-direction` CSS property. - gap (number; optional): `gap` CSS property. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - justify (optional): `justify-content` CSS property. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - rowGap (number; optional): `row-gap` CSS property. - 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 (optional): Breakpoint below which the component is hidden with `display: none`. - wrap (optional): `flex-wrap` CSS property. ## Grid Responsive 12 columns grid system Category: Layout ### Usage Use Grid component to create layouts with a flexbox grid system. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span=6), dmc.GridCol(dmc.Box("2", style=style), span=3), dmc.GridCol(dmc.Box("3", style=style), span=3), ], gutter="xl", ) ``` ### Columns span `The GridCol` `span` prop controls the ratio of column width to the total width of the row. By default, grid uses 12 columns layout, so `span` prop can be any number from 1 to 12. Examples: ```python dmc.GridCol(span=3) # 3 / 12 = 25% of row width dmc.GridCol(span=4) # 4 / 12 = 33% of row width dmc.GridCol(span=6) # 6 / 12 = 50% of row width dmc.GridCol(span=12) # 12 / 12 = 100% of row width ``` `span` prop also supports dictionary syntax to change column width based on viewport width, it accepts `xs`, `sm`, `md`, `lg` and `xl` keys and values from 1 to 12. The syntax is the same as in `style` props. In the following example `span={'base': 12, 'md': 6, 'lg': 3`}: - `base` – 12 / 12 = 100% of row width when viewport width is less than `md` breakpoint - `md` – 6 / 12 = 50% of row width when viewport width is between md and `lg` breakpoints - `lg` – 3 / 12 = 25% of row width when viewport width is greater than `lg` breakpoint ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span={"base": 12, "md": 6, "lg":3}), dmc.GridCol(dmc.Box("2", style=style), span={"base": 12, "md": 6, "lg":3}), dmc.GridCol(dmc.Box("3", style=style), span={"base": 12, "md": 6, "lg":3}), dmc.GridCol(dmc.Box("4", style=style), span={"base": 12, "md": 6, "lg":3}), ], ) ``` ### Gutter Set `gutter` prop to control spacing between columns. The prop works the same way as `style` props – you can reference theme.spacing values with `xs`, `sm`, `md`, `lg` and `xl` strings and use dictionary syntax to change gutter based on viewport width. You can also set gutter to a number to set spacing in px. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span=4), dmc.GridCol(dmc.Box("2", style=style), span=4), dmc.GridCol(dmc.Box("3", style=style), span=4), ], gutter={ "base": 5, "xs": "md", "md": "xl", "xl": 50 }, ) ``` ### Grow Set `grow` prop on Grid to force last row to take 100% of container width. ### Column Offset Set `offset` prop on `GridCol` component to add gaps to the grid. `offset` prop supports the same syntax as span prop: a number from 1 to 12 or a dictionary with `xs`, `sm`, `md`, `lg` and `xl` keys and values from 1 to 12. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span=3), dmc.GridCol(dmc.Box("2", style=style), span=3), dmc.GridCol(dmc.Box("3", style=style), span=3, offset=3), ], gutter="xl", ) ``` ### Order Set the `order` prop on `GridCol` component to change the order of columns. `order` prop supports the same syntax as `span` prop: a number from 1 to 12 or a dictionary with `xs`, `sm`, `md`, `lg` and `xl` keys and values from 1 to 12. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("2", style=style), span=3, order={"base": 2, "sm": 1, "lg": 3}), dmc.GridCol(dmc.Box("3", style=style), span=3, order={"base": 3, "sm": 2, "lg": 2}), dmc.GridCol(dmc.Box("1", style=style), span=3, order={"base": 1, "sm": 3, "lg": 1}), ], ) ``` ### Multiple rows Once children columns span and offset sum exceeds `columns` prop (defaults to 12), columns are placed on next row. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span=4), dmc.GridCol(dmc.Box("2", style=style), span=4), dmc.GridCol(dmc.Box("3", style=style), span=4), dmc.GridCol(dmc.Box("4", style=style), span=4), ], gutter="xl", ) ``` ### Justify and Align Since grid is a flexbox container, you can control justify-content and align-items properties by using `justify` and `align` props respectively. Note the minimum height set on column 2 and 3. ```python import dash_mantine_components as dmc dmc.Grid( children=[ dmc.GridCol(dmc.Box("1"), span=4), dmc.GridCol(dmc.Box("2", style={"minHeight":80}), span=4), dmc.GridCol(dmc.Box("3", style={"minHeight":120}), span=4), ], justify="center", align="stretch", ) ``` ### Auto Sized Columns All columns in a row with `span` or a `breakpoint` of `auto` will have equal size, growing as much as they can to fill the row. In this example, the second column takes up 50% of the row while the other two columns automatically resize to fill the remaining space. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("span=auto", style=style), span="auto"), dmc.GridCol(dmc.Box("span=6", style=style), span=6), dmc.GridCol(dmc.Box("span=auto", style=style), span="auto"), ], gutter="xl", ) ``` ### Fit Content If you set `span` or a `breakpoint` to `content`, the column's size will automatically adjust to match the width of its content. ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("content width", style=style), span="content"), dmc.GridCol(dmc.Box("2", style=style), span=6), ], gutter="xl", ) ``` ### Change columns count By default, grids uses 12 columns layout, you can change it by setting `columns` prop on `Grid` component. Note that in this case, columns span and offset will be calculated relative to this value. In the following example, first column takes 50% with 12 span (12/24), second and third take 25% (6/24): ```python import dash_mantine_components as dmc style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span=12), dmc.GridCol(dmc.Box("2", style=style), span=6), dmc.GridCol(dmc.Box("3", style=style), span=6), ], columns=24 ) ``` ### Container queries To use [container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries) instead of media queries, set `type='container'`. With container queries, all responsive values are adjusted based on the container width, not the viewport width. Note that, when using container queries, it is also required to set `breakpoints` prop to the exact container width values. To see how the grid 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 style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.Box( # Wrapper div is added for demonstration purposes only, # it is not required in real projects dmc.Grid( children=[ dmc.GridCol(dmc.Box("1", style=style), span={"base": 12, "md": 6, "lg": 3}), dmc.GridCol(dmc.Box("2", style=style), span={"base": 12, "md": 6, "lg": 3}), dmc.GridCol(dmc.Box("3", style=style), span={"base": 12, "md": 6, "lg": 3}), dmc.GridCol(dmc.Box("4", style=style), span={"base": 12, "md": 6, "lg": 3}), ], gutter="xl", type="container", breakpoints={ "xs": "100px", "sm": "200px", "md": "300px", "lg": "400px", "xl": "500px", }, ), style={"resize": 'horizontal', "overflow": 'hidden', "maxWidth": '100%', "margin": 24 }, ) ``` ### overflow: hidden By default, `Grid` has `overflow: visible` style on the root element. In some cases you might want to change it to `overflow: hidden` to prevent negative margins from overflowing the grid container. For example, if you use `Grid` without parent container which has padding. ```python dmc.Grid([ dmc.GridCol("1", span=6), dmc.GridCol("2", span=6), ], overflow="hidden") ``` ### 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. #### Grid Selectors | Selector | Static selector | Description | |------------|-----------------------------|------------------------------------------| | container | .mantine-Grid-container | Container element, only used with `type="container"` prop | | root | .mantine-Grid-root | Root element | | inner | .mantine-Grid-inner | Columns wrapper | | col | .mantine-Grid-col | `Grid.Col` root element | --- #### Grid CSS Variables | Selector | Variable | Description | |----------|-------------------|----------------------------------| | root | --grid-overflow | Controls `overflow` property | | | --grid-align | Controls `align-items` property | | | --grid-justify | Controls `justify-content` property | ### Keyword Arguments #### Grid - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - align (optional): Sets `align-items`, `stretch` 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. - breakpoints (dict; optional): Breakpoints values, only applicable when `type="container"` is set, ignored when `type` is not set or `type="media"` is set. `breakpoints` is a dict with keys: - 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. - columns (number; optional): Number of columns in each row, `12` 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. - grow (boolean; optional): Determines whether columns in the last row should expand to fill all available space, `False` by default. - gutter (number; optional): Gutter between columns, key of `theme.spacing` or any valid CSS value, `'md'` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - justify (optional): Sets `justify-content`, `flex-start` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - overflow (optional): Sets `overflow` CSS property on the root element, `'visible'` 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 (optional): Breakpoint below which the component is hidden with `display: none`. #### GridCol - children (a list of or a singular dash component, string or number; optional) - 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - offset (number; optional): Column offset on the left side – number of columns that should be left empty before this column. - order (number; optional): Column order, can be used to reorder columns at different viewport sizes. - span (number; optional): Column span, `12` 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Group Use Group component to place components in a horizontal flex container. Category: Layout ### Usage ### preventGrowOverflow `preventGrowOverflow` prop allows you to control how `Group` children should behave when there is not enough space to fit them all on one line. By default, children are not allowed to take more space than (1 / children.length) * 100% of parent width (`preventGrowOverflow` is set to True). To change this behavior, set `preventGrowOverflow` to False and children will be allowed to grow and take as much space as they need. ```python import dash_mantine_components as dmc component = dmc.Box( style={"overflow": "hidden"}, children=[ dmc.Box( maw=500, p="md", mx="auto", bg="var(--mantine-color-blue-light)", children=[ dmc.Text( size="sm", mb=5, children=( "preventGrowOverflow: true – each child width is always limited " "to 33% of parent width (since there are 3 children)" ), ), dmc.Group( grow=True, wrap="nowrap", children=[ dmc.Button("First button", variant="default"), dmc.Button("Second button with large content", variant="default"), dmc.Button("Third button", variant="default"), ], ), dmc.Text( size="sm", mb=5, mt="md", children=( "preventGrowOverflow: false – children will grow based on their " "content, they can take more than 33% of parent width" ), ), dmc.Group( grow=True, preventGrowOverflow=False, wrap="nowrap", children=[ dmc.Button("First button", variant="default"), dmc.Button("Second button with large content", variant="default"), dmc.Button("Third button", variant="default"), ], ), ], ) ], ) ``` ### Group children `Group` works correctly only with components. Strings, or numbers may have incorrect styles if `grow` prop is set: ```python # don't do this dmc.Group([ "Some text", dmc.Text("Some more text"), 20, ], grow=True) ``` ### Browser support `Group` uses flexbox `gap` to add spacing between children. In older browsers, `Group` children may not have spacing. ### 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. #### Group Selectors | Selector | Static selector | Description | |----------|-------------------------|----------------| | root | .mantine-Group-root | Root element | #### Group CSS Variables | Selector | Variable | Description | |----------|--------------------------|--------------------------------------------------------------| | root | --group-align | Controls `align-items` property | | | --group-justify | Controls `justify-content` property | | | --group-gap | Controls `gap` property | | | --group-wrap | Controls `flex-wrap` property | | | --group-child-width | Controls max-width of child elements when `grow` and `preventGrowOverflow` are set | #### Group Data Attributes | Selector | Attribute | Condition | |----------|-------------|-----------------| | root | data-grow | `grow` prop is set | ### Keyword Arguments #### Group - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - align (optional): Controls `align-items` CSS property, `'center'` 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. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - gap (number; optional): Key of `theme.spacing` or any valid CSS value for `gap`, numbers are converted to rem, `'md'` by default. - grow (boolean; optional): Determines whether each child element should have `flex-grow: 1` style, `False` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - justify (optional): Controls `justify-content` CSS property, `'flex-start'` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - preventGrowOverflow (boolean; optional): Determines whether children should take only dedicated amount of space (`max-width` style is set based on the number of children), `True` 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 (optional): Breakpoint below which the component is hidden with `display: none`. - wrap (a value equal to: '-moz-initial', 'inherit', 'initial', 'revert', 'revert-layer', 'unset', 'nowrap', 'wrap', 'wrap-reverse'; optional): Controls `flex-wrap` CSS property, `'wrap'` by default. ## Layout Overview This guide gives an overview of layout components available in Dash Mantine components. Category: Layout ### SimpleGrid Use [SimpleGrid](/components/simplegrid) if you need columns with equal size. The `cols`, `spacing` and `verticalSpacing` props accepts dictionaries to set responsive values based on viewport width. ### Grid Use [Grid](/components/grid) if you need columns with different sizes. You can also set spans, spacing, offsets, and ordering and more. ### Group Use [Group](/components/group) if you want to put items next to each other horizontally. ### Stack Use [Stack](/components/stack) if you want to put items next to each other vertically ### Flex Use [Flex](/components/flex) if you want to create both horizontal and vertical flexbox layouts. It's more flexible than `Group` and `Stack` but requires more configuration. ### AspectRatio Use [AspectRatio](/components/aspectratio) to ensure that content always maintains a specific width-to-height ratio, no matter the screen size. Great for images and videos. ### Center Use [Center](/compnents/center) component to center content vertically and horizontally. This example centers an icon with a link with the `inline` prop: ### Container Use [Container](/components/container) to center content horizontally and add horizontal padding from theme. Good for limiting width and centering content on large screens. ### Box [Box](/components/box) is like an `html.Div` but also includes Mantine style props. ### Paper Use [Paper](/components/paper) to group content visually like a card. It includes props for background, padding, shadow, borders, and rounded corners. ### AppShell The [AppShell](/components/appshell) component is a layout component designed to create responsive and consistent app layouts. It includes: - `AppShell` - root component, it is required to wrap all other components, used to configure layout properties - `AppShellHeader` - section rendered at the top of the page - `AppShellNavbar` - section rendered on the left side of the page - `AppShellAside` - section rendered on the right side of the page - `AppShellFooter` - section rendered at the bottom of the page - `AppShellMain` - main section rendered at the center of the page, has static position, all other sections are offset by its padding - `AppShellSection` - utility component that can be used to render group of content inside `AppShellNavbar` and `AppShellAside` This DMC documentation app is built using `AppShell` components. See the [AppShell](/components/appshell) docs for more info and examples: ## SimpleGrid Use SimpleGrid component to create a grid where each column takes equal width. You can use it to create responsive layouts. Category: Layout ### Usage `SimpleGrid` is a responsive grid system with equal-width columns. It uses CSS grid layout. If you need to set different widths for columns, use `Grid` component instead. ### spacing and verticalSpacing props `spacing` prop is used both for horizontal and vertical spacing if `verticalSpacing` is not set: ```python # `spacing` is used for both horizontal and vertical spacing dmc.SimpleGrid(spacing="xl") # `spacing` is used for horizontal spacing, `verticalSpacing` for vertical dmc.SimpleGrid(spacing="xl", verticalSpacing="lg") ``` ### Responsive Props `cols`, `spacing` and `verticalSpacing` props support object notation for responsive values, it works the same way as [style props](/style-props): the object may have `base`, `xs`, `sm`, `md`, `lg` and `xl` key, and values from those keys will be applied according to current viewport width. `cols` prop can be understood from the below example as: - 1 column if viewport width is less than `sm` breakpoint - 2 columns if viewport width is between `sm` and `lg` breakpoints - 5 columns if viewport width is greater than `lg` breakpoint Same logic applies to `spacing` and `verticalSpacing` props. Resize browser to see breakpoints behavior. ```python import dash_mantine_components as dmc from dash import html style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = dmc.SimpleGrid( cols={"base": 1, "sm": 2, "lg": 5}, spacing={"base": 10, "sm": "xl"}, verticalSpacing={"base": "md", "sm": "xl"}, children=[ html.Div("1", style=style), html.Div("2", style=style), html.Div("3", style=style), html.Div("4", style=style), html.Div("5", style=style), ], ) ``` ### Container queries To use [container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries) instead of media queries, set `type='container'`. With container queries, grid columns and spacing will be adjusted based on the container width, not the viewport width. Note that, when using container queries, `cols`, `spacing` and `verticalSpacing` props cannot reference `theme.breakpoints` values in keys. It is required to use exact `px` or `em` values. To see how the grid 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 style = { "border": f"1px solid var(--mantine-primary-color-filled)", "textAlign": "center", } component = html.Div( # Wrapper div is added for demonstration purposes only, # it is not required in real projects dmc.SimpleGrid( type="container", cols={"base": 1, "300px": 2, "500px": 5}, spacing={"base": 10, "300px": "xl"}, children=[ html.Div("1", style=style), html.Div("2", style=style), html.Div("3", style=style), html.Div("4", style=style), html.Div("5", style=style), ], p="xs", ), style={"resize": "horizontal", "overflow": "hidden", "maxWidth": "100%"}, ) ``` ### 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-SimpleGrid-root | Root element | ### Keyword Arguments #### SimpleGrid - children (a list of or a singular dash component, string or number; optional) - 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. - cols (number; optional): Number of columns, `1` 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - spacing (number; optional): Spacing between columns, `'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. - 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. - verticalSpacing (number; optional): Spacing between rows, `'md'` by default. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Space Use the Space component to add horizontal or vertical spacing from theme. Category: Layout ### Simple Example Space component can be customized with two props: `h` and `w`, shortcuts for height and width. These can take either values from Mantine's theme i.e. xs, sm, md, lg, xl or number. ```python import dash_mantine_components as dmc from dash import html component = html.Div( [ dmc.Group([dmc.Badge("Badge 1"), dmc.Badge("Badge 2")]), dmc.Space(h="xl"), dmc.Group([dmc.Badge("Badge 1"), dmc.Space(w="lg"), dmc.Badge("Badge 2")]), dmc.Space(h=30), dmc.Group([dmc.Badge("Badge 1"), dmc.Space(w=45), dmc.Badge("Badge 2")]), ] ) ``` ### Where to use In most cases, you would want to use margin props instead of `Space` when working with Mantine components: ```python import dash_mantine_components as dmc from dash import html html.Div([ dmc.Text("First line"), dmc.Text("Second line", mt="md"), ]) ``` But when you work with other components like `html` or `dcc`, you do not have access to Mantine's theme spacing, and you may want to use dmc.Space component: ```python import dash_mantine_components as dmc from dash import html html.Div([ html.P("First line"), dmc.Space(h="md"), html.P("Second line"), ]) ``` ### Keyword Arguments #### Space - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - aria-* (string; optional): Wild card aria attributes. - className (string; optional): Class added to the root element, if applicable. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - tabIndex (number; optional): tab-index. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Stack Use Stack component to compose elements and components in a vertical flex container Category: Layout ### Usage `Stack` is a vertical flex container. If you need a horizontal flex container, use `Group` component instead. If you need to have full control over flex container properties, use `Flex` component. Adjust stack styles with `align`, `justify`, and `spacing` props. ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Button("1", variant="outline"), dmc.Button("2", variant="outline"), dmc.Button("3", variant="outline"), ], align="center", gap="xl", ) ``` ### Interactive Demo ### 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. #### Stack Selectors | Selector | Static selector | Description | |----------|-------------------------|----------------| | root | .mantine-Stack-root | Root element | #### Stack CSS Variables | Selector | Variable | Description | |----------|------------------|---------------------------------| | root | --stack-align | Controls `align-items` property | | | --stack-justify | Controls `justify-content` property | | | --stack-gap | Controls `gap` property | ### Keyword Arguments #### Stack - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - align (optional): Controls `align-items` CSS property, `'stretch'` 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. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - gap (number; optional): Key of `theme.spacing` or any valid CSS value to set `gap` property, numbers are converted to rem, `'md'` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - justify (optional): Controls `justify-content` CSS property, `'flex-start'` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Box Base component for all Mantine components Category: Miscellaneous ### Usage The `Box` component serves as a base for all other components and can be used as a replacement for `html.Div` as a basic container. The key advantage of using `Box` is its support for [Style Props](/style-props), allowing for cleaner, more readable styling directly within the component. ### Example Both examples below produce the same result: ```python # Using html.Div html.Div( [ # your content here ], style={"marginTop": 8, "padding": 24} ) # Using dmc.Box with Style Props dmc.Box( [ # your content here ], mt=8, p=24 ) ``` > Please see the [Style Props](/style-props) section for more information. ### Keyword Arguments #### Box - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - aria-* (string; optional): Wild card aria attributes. - className (string; optional): Class added to the root element, if applicable. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - tabIndex (number; optional): tab-index. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Collapse Use the Collapse component to animate presence with slide down/up transition Category: Miscellaneous ### Simple Example ```python from dash import callback, Input, Output import dash_mantine_components as dmc component = dmc.Box([ dmc.Button("Toggle Content", id="collapse-btn", n_clicks=0), dmc.Collapse( children=dmc.Text("Hello World!", my="lg"), opened=False, id="collapse-simple" ) ]) @callback( Output("collapse-simple", "opened"), Input("collapse-btn", "n_clicks"), ) def update(n): if n % 2 == 0: return False return True ``` ### Change transition Set following props to control transition: - `transitionDuration` – duration in ms - `transitionTimingFunction` – [CSS timing function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) ("ease", "linear", etc.), defaults to "ease" ```python from dash import callback, Input, Output import dash_mantine_components as dmc component = dmc.Box([ dmc.Button("Toggle Content", id="collapse-transition-btn", n_clicks=0), dmc.Collapse( children=dmc.Text("Hello World!", my="lg"), opened=False, transitionDuration=1000, transitionTimingFunction="linear", id="collapse-transition" ) ]) @callback( Output("collapse-transition", "opened"), Input("collapse-transition-btn", "n_clicks"), ) def update(n): if n % 2 == 0: return False return True ``` ### Nested Collapse components ```python from dash import callback, Input, Output import dash_mantine_components as dmc component = dmc.Box([ dmc.Button("Toggle Content", id="collapse-root-btn", n_clicks=0, mb="sm", size="lg"), dmc.Collapse( children=dmc.Box([ dmc.Text("Hello World!", mt="lg"), dmc.Button( "Toggle Content", id="collapse-inner-btn", n_clicks=0, variant="outline", size="sm", my="lg", ml="lg" ), dmc.Collapse(children= dmc.Text("Hello Nested Worlds!", ml="lg"), id="collapse-inner") ]), opened=False, id="collapse-root" ) ]) @callback( Output("collapse-root", "opened"), Input("collapse-root-btn", "n_clicks"), ) def update(n): if n % 2 == 0: return False return True @callback( Output("collapse-inner", "opened"), Input("collapse-inner-btn", "n_clicks"), ) def update(n): if n % 2 == 0: return False return True ``` ### Keyword Arguments #### Collapse - 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. - animateOpacity (boolean; optional): Determines whether opacity should be animated, `True` by default. - aria-* (string; optional): Wild card aria attributes. - className (string; optional): Class added to the root element, if applicable. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - keepMounted (boolean; optional): Keep element in DOM when collapsed, useful for nested collapses. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - opened (boolean; default False): Opened state. - tabIndex (number; optional): tab-index. - transitionDuration (number; optional): Transition duration in ms, `200` by default. - transitionTimingFunction (string; optional): Transition timing function, default value is `ease`. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Divider Use Divider component as an alternative to html.Hr. Category: Miscellaneous ### Simple Example ```python import dash_mantine_components as dmc component = dmc.Stack( children=[ dmc.Divider(variant="solid"), dmc.Divider(variant="dashed"), dmc.Divider(variant="dotted"), ], ) ``` ### With Label You can provide `label` and `labelPosition` to customize dmc.Divider. ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Divider(label="Click on update button to refresh"), dmc.Divider(label="Divider with centered content", labelPosition="center"), dmc.Divider(label="Divider with content on the right", labelPosition="right"), ], ) ``` ### Different Sizes Set the `size` property to change the size of the divider. ```python import dash_mantine_components as dmc component = dmc.Stack( children=[ dmc.Divider(size="xs"), dmc.Divider(size="sm"), dmc.Divider(size="md"), dmc.Divider(size="lg"), dmc.Divider(size="xl"), dmc.Divider(size=10), ], ) ``` ### Vertical Divider Divider can be used in vertical orientations by setting `orientation="vertical"` and providing it some height. ```python import dash_mantine_components as dmc component = dmc.Group( [ dmc.Badge("Badge 1"), dmc.Divider(orientation="vertical", style={"height": 20}), dmc.Badge("Badge 2"), dmc.Divider(orientation="vertical", style={"height": 20}), dmc.Badge("Badge 3"), ] ) ``` ### With Color Set the Divider color from one of the colors of Mantine default theme using the `color` prop. ```python import dash_mantine_components as dmc component = dmc.Divider(color="red") ``` ### 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-Divider-root | Root element | | label | .mantine-Divider-label | Label element | ### Keyword Arguments #### Divider - 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. - color (optional): Key of `theme.colors` or any valid CSS color value, by default value depends on color scheme. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - label (a list of or a singular dash component, string or number; optional): Divider label, visible only when `orientation` is `horizontal`. - labelPosition (a value equal to: 'left', 'right', 'center'; optional): Controls label position, `'left'` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - orientation (a value equal to: 'horizontal', 'vertical'; optional): Controls orientation, `'horizontal'` by default. - size (number; optional): Controls width/height (depends on orientation), `'xs'` 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Paper Render white or dark background depending on color scheme with Paper component with border, shadow, etc. Category: Miscellaneous ### Introduction Paper component renders white (or theme.colors.dark[7] for dark theme) background with shadow, border-radius and padding from theme. ### Shadow ```python import dash_mantine_components as dmc dmc.Paper( children=[], shadow="xs", ) ``` ### Padding ```python import dash_mantine_components as dmc dmc.Paper( children=[], p="xs", # or p=10 for padding of 10px ) ``` ### Radius ```python import dash_mantine_components as dmc dmc.Paper( children=[], radius="sm", # or p=10 for border-radius of 10px ) ``` ### 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-Paper-root | Root element | ### Keyword Arguments #### Paper - 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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`. - shadow (optional): Key of `theme.shadows` or any valid CSS value to set `box-shadow`. - 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 (optional): Breakpoint below which the component is hidden with `display: none`. - withBorder (boolean; optional): Adds border to the root element. ## ScrollArea Use the ScrollArea component to customize scrollbars. Category: Miscellaneous ### Introduction The ScrollArea component supports the following props: - `type` defines scrollbars behavior: - `hover` - scrollbars are visible on hover - `scroll` - scrollbars are visible on scroll - `auto` - similar to `overflow: auto` - scrollbars are always visible when the content is overflowing - `always` - same as auto but scrollbars are always visible regardless of whether the content is overflowing - `never` - scrollbars are always hidden - `offsetScrollbars` - offset scrollbars with padding - x – adds padding to offset horizontal scrollbar only - y – adds padding to offset vertical scrollbar only - xy – adds padding to offset both scrollbars - present – adds padding only when scrollbars are visible - `scrollbarSize` - scrollbar size, controls scrollbar and thumb width/height - `scrollHideDelay` - delay in ms to hide scrollbars, applicable only when type is hover or scroll - `overscrollBehavior` – controls overscroll-behavior of the viewport - `scrollTo` sets scroll position of the viewport This example has a vertical scroll bar. This is how the ScrollArea height and width is defined in the example above ```python html.Div( [ dmc.Title("Charizard (Pokémon)", order=3), dmc.ScrollArea( h=250, w=350, children = dmc.Paper(dmc.Text(text), withBorder=True), ) ] ) ``` ### Horizontal scrollbars The horizontal scroll bar will be displayed when the content of the ScrollArea is wider than the ScrollArea. ```python import dash_mantine_components as dmc from docs.scrollarea.text import text component = dmc.Center( dmc.ScrollArea( h=250, w=350, children=dmc.Paper( [dmc.Title("Charizard (Pokémon)", order=3), dmc.Text(text)], w=600 ), ), ) ``` ### Disable horizontal scrollbars To disable horizontal scrollbars set `scrollbars="y"` prop: ```python import dash_mantine_components as dmc from docs.scrollarea.text import text component = dmc.Center( dmc.ScrollArea( h=250, w=350, scrollbars="y", children=dmc.Paper( [dmc.Title("Charizard (Pokémon)", order=3), dmc.Text(text)], w=600 ), ), ) ``` ### Scroll To The `scrollTo` prop sets the scroll position of the viewport with the following options: * `top` – The vertical position as pixels (number) or percentage (string) from '0%' to '100%' * `left` – The horizontal position as pixels (number) or percentage (string) from '0%' to '100%' * `behavior` – scroll behavior: `auto` (instant) or `smooth` (animated), `smooth` by default For example: ```python # Scroll to specific pixel positions dmc.ScrollArea(scrollTo={"top": 100, "left": 50}) # Scroll to percentage positions dmc.ScrollArea(scrollTo={"top": "25%", "left": "75%"}) # Mixed usage dmc.ScrollArea(scrollTo={"top": 200, "left": "50%", "behavior": "auto"}) ``` --- ```python import dash_mantine_components as dmc from dash import callback, Input, Output, ctx content = [ dmc.Box([ dmc.Title(f"Section {i}", order=4, mt="sm", id=f"section-{i}"), dmc.Text(""" Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta perspiciatis reiciendis voluptate eaque itaque quos. Natus iure tenetur libero, reprehenderit ad, sequi, in aliquam eos necessitatibus expedita delectus veniam culpa! """) ]) for i in range(1, 11) ] component = dmc.Box([ dmc.ScrollArea( content, id="scrollArea", h=250, w=350, ), dmc.Group([ dmc.Button("Scroll to Top", id="scrollto-top"), dmc.Button("Scroll to Middle", id="scrollto-middle"), dmc.Button("Scroll to Bottom", id="scrollto-bottom"), ], mt="lg"), ]) @callback( Output("scrollArea", "scrollTo"), Input("scrollto-top", "n_clicks"), Input("scrollto-middle", "n_clicks"), Input("scrollto-bottom", "n_clicks"), ) def scroll_to(t, m, b): if ctx.triggered_id == "scrollto-middle": return {"top": "50%"} if ctx.triggered_id == "scrollto-bottom": return {"top": "100%"} return {"top": 0} ``` ### ScrollAreaAutosize `ScrollAreaAutosize` component allows to create scrollable containers when given max-height is reached. ```python import dash_mantine_components as dmc from dash import callback, Output, Input, ctx lorem = ( "Lorem ipsum, dolor sit amet consectetur adipisicing elit. " "Dicta perspiciatis reiciendis voluptate eaque itaque quos. " "Natus iure tenetur libero, reprehenderit ad, sequi, in aliquam eos " "necessitatibus expedita delectus veniam culpa!" ) component = dmc.Stack( [ dmc.ScrollAreaAutosize(mah=300, maw=400, p="sm", id="scrollarea-autosize"), dmc.Group( m="lg", children=[ dmc.Button( "1 paragraph", id="btn-1-paragraph", color="red", ), dmc.Button( "4 paragraphs", id="btn-4-paragraphs", ), ], ), ] ) @callback( Output("scrollarea-autosize", "children"), Input("btn-1-paragraph", "n_clicks"), Input("btn-4-paragraphs", "n_clicks"), ) def update_paragraphs(inc, dec): if ctx.triggered_id == "btn-1-paragraph": return dmc.Box(lorem, p="sm") return [dmc.Box(lorem, p="sm") for _ in range(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. #### ScrollArea Selectors | Selector | Static selector | Description | | --------- | ------------------------------- | ------------------------------------------------- | | root | `.mantine-ScrollArea-root` | Root element | | content | `.mantine-ScrollArea-content` | Wraps component children | | viewport | `.mantine-ScrollArea-viewport` | Main scrollable area | | scrollbar | `.mantine-ScrollArea-scrollbar` | Horizontal or vertical scrollbar root | | thumb | `.mantine-ScrollArea-thumb` | Scrollbar thumb | | corner | `.mantine-ScrollArea-corner` | Corner between horizontal and vertical scrollbars | #### ScrollArea CSS variables | Selector | Variable | Description | |----------|------------------------------|----------------| | root | `--scrollarea-scrollbar-size` | Scrollbar size | #### ScrollArea data attributes | Selector | Attribute | Condition | Value | |------------------|--------------------|------------------------------------|-------------------------------------| | scrollbar, corner| `data-hidden` | `type="never"` | – | | corner | `data-hovered` | One of the scrollbars is hovered | – | | scrollbar | `data-orientation` | – | "horizontal" or "vertical" depending on scrollbar position | ### Keyword Arguments #### ScrollArea - 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - offsetScrollbars (optional): Determines whether scrollbars should be offset with padding on given axis, `False` by default. - overscrollBehavior (optional): Defines `overscroll-behavior` of the viewport. https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior. - scrollHideDelay (number; optional): Scroll hide delay in ms, applicable only when type is set to `hover` or `scroll`, `1000` by default. - scrollTo (dict; optional): Scroll to a position in the scroll area. `scrollTo` is a dict with keys: - scrollbarSize (string | number; optional): Scrollbar size, any valid CSS value for width/height, numbers are converted to rem, default value is 0.75rem. - scrollbars (optional): Axis at which scrollbars must be rendered, `'xy'` 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: 'auto', 'always', 'scroll', 'hover', 'never'; optional): Defines scrollbars behavior, `hover` by default - `hover` – scrollbars are visible when mouse is over the scroll area - `scroll` – scrollbars are visible when the scroll area is scrolled - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## VisuallyHidden Hide element visually but keep it accessible for screen readers Category: Miscellaneous ### Usage `VisuallyHidden` is a utility component that hides content visually but leaves it available to screen readers. This example uses it with the `ActionIcon` component: ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.ActionIcon([ DashIconify(icon="mdi:heart-outline"), dmc.VisuallyHidden("Like post") ], variant="outline") ``` ### Keyword Arguments #### VisuallyHidden - 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 (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 with strings as keys and values of type boolean | number | string | dict | list; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Anchor Use the Anchor component to add links with Mantine's theme styles. Category: Navigation ### Simple Example dmc.Anchor is a wrapper around dmc.Text component and works similar to dcc.Link, so you can use it with multipage apps. It takes the same props as dmc.Text. ```python import dash_mantine_components as dmc component = dmc.Anchor( "Dash Mantine Components Announcement", href="https://community.plotly.com/t/dash-mantine-components/58414", ) ``` ### Underline ```python import dash_mantine_components as dmc component = dmc.Group([ dmc.Anchor( "Underline always", href="https://www.dash-mantine-components.com/", target="_blank", underline = "always", ), dmc.Anchor( "Underline on hover", href="https://www.dash-mantine-components.com/", target="_blank", underline = "hover", ), dmc.Anchor( "Underline never", href="https://www.dash-mantine-components.com/", target="_blank", underline = "never", ), dmc.Anchor( "Underline not hover", href="https://www.dash-mantine-components.com/", target="_blank", underline = "not-hover", ), ]) ``` You can also configure underline prop for all Anchor components with default props: ```python dmc.MantineProvider( theme={ "components": { "Anchor": { "defaultProps": { "underline": "always", }, }, }, } ) ``` ### Text props Text props `Anchor` components supports all `Text` component props. For example, you can use gradient variant: ```python import dash_mantine_components as dmc component = dmc.Anchor( "A link with pink to yellow gradient", href="#text-props", variant="gradient", gradient={"from": "pink", "to": "yellow"}, fw=500, fz="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. #### Anchor selectors | Selector | Static selector | Description | |----------|----------------|-------------| | root | .mantine-Anchor-root | Root element | #### Anchor CSS variables | Selector | Variable | Description | |----------|----------|-------------| | root | --text-fz | Controls font-size property | | root | --text-lh | Controls line-height property | | root | --text-gradient | Text fill gradient | | root | --text-line-clamp | Number of lines that should be visible | #### Anchor data attributes | Selector | Attribute | Condition | Value | |----------|-----------|-----------|-------| | root | data-truncate | `truncate` prop is set | Value of `truncate` prop | | root | data-line-clamp | `lineClamp` prop is a number | – | | root | data-inline | `inline` prop is set | – | | root | data-inherit | `inherit` prop is set | – | | root | data-underline | – | Value of `underline` prop | ### Keyword Arguments #### Anchor - 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. - gradient (dict; optional): Gradient configuration, ignored when `variant` is not `gradient`, `theme.defaultGradient` by default. `gradient` is a dict with keys: - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - href (string; required): href. - inherit (boolean; optional): Determines whether font properties should be inherited from the parent, `False` by default. - inline (boolean; optional): Sets `line-height` to 1 for centering, `False` by default. - lightHidden (boolean; optional): Determines whether component should be hidden in light color scheme with `display: none`. - lineClamp (number; optional): Number of lines after which Text will be truncated. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - refresh (boolean; optional): Whether to refresh the page. - size (optional): Controls `font-size` and `line-height`, `'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. - target (a value equal to: '_blank', '_self'; optional): Target. - truncate (optional): Side on which Text must be truncated, if `True`, text is truncated from the start. - underline (a value equal to: 'always', 'hover', 'never'; optional): Determines in which cases link should have `text-decoration: underline` styles, `hover` by default. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Breadcrumbs Breadcrumbs is a navigation component that is used to indicate current page's location within a navigational hierarchy. Category: Navigation ### Simple Example Breadcrumbs accept any react nodes as children and places given separator (defaults to `/`) between them. ```python import dash_mantine_components as dmc from dash import dcc, html component = html.Div( [ # default separator dmc.Breadcrumbs( children=[ dcc.Link("Home", href="/"), dcc.Link("Dash Mantine Components", href="/"), dcc.Link("Breadcrumbs", href="/components/breadcrumbs"), ], ), dmc.Space(h=20), # separator provided dmc.Breadcrumbs( separator="→", children=[ dmc.Anchor("Home", href="/", underline=False), dmc.Anchor("Dash Mantine Components", href="/", underline=False), dmc.Anchor( "Breadcrumbs", href="/components/breadcrumbs", underline=False ), ], ), ] ) ``` ### 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-Breadcrumbs-root | Root element | | breadcrumb | .mantine-Breadcrumbs-breadcrumb | Breadcrumb item wrapper | | separator | .mantine-Breadcrumbs-separator | Separator between children | ### Keyword Arguments #### Breadcrumbs - children (a list of or a singular dash component, string or number; required): React nodes that should be separated with `separator`. - 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 (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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - separator (a list of or a singular dash component, string or number; optional): Separator between children, `'/'` by default. - separatorMargin (number; optional): Controls spacing between separator and breadcrumb, `'xs'` 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 (optional): Breakpoint below which the component is hidden with `display: none`. ## Burger Open/close navigation button. Use the dmc.Burger component to toggle navigation menus. Category: Navigation ### Simple Example Burger component renders open/close menu button. If it's burger state is clicked, the `opened` property is set to `True`, and if it's cross state is clicked, the `opened` property is set to `False`. ```python import dash_mantine_components as dmc from dash import Input, Output, callback, html component = html.Div( [dmc.Burger(id="burger-button", opened=False), dmc.Text(id="burger-state", mt="md")] ) @callback(Output("burger-state", "children"), Input("burger-button", "opened")) def is_open(opened): return str(opened) ``` ### Size and Line Size Use `size` prop to control the `Burger` width and height, numbers are converted to rem, 'md' by default. Use the `lineSize` prop to control height of lines, by default calculated based on `size` prop. ```python dmc.Burger(id="burger-button", opened=False, lineSize=2, size="md") ``` ### Colors ```python import dash_mantine_components as dmc component = dmc.Group( [ dmc.Burger(), dmc.Burger(color="red"), dmc.Burger(color="green"), ] ) ``` ### 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. #### Burger Selectors | Selector | Static selector | Description | |----------|--------------------------|---------------------------------------| | root | .mantine-Burger-root | Root element (button) | | burger | .mantine-Burger-burger | Inner element that contains burger lines | #### Burger CSS Variables | Selector | Variable | Description | |----------|-------------------------------------|--------------------------------------------| | root | --burger-line-size | Controls height of lines | | | --burger-color | Controls background-color of lines | | | --burger-size | Controls width and height of the button | | | --burger-transition-duration | Controls transition-duration of lines | | | --burger-transition-timing-function | Controls transition-timing-function of lines | #### Burger Data Attributes | Selector | Attribute | Condition | |----------|--------------|--------------------| | burger | data-opened | `opened` prop is set | ### Keyword Arguments #### Burger - 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. - color (optional): Key of `theme.colors` of any valid CSS value, by default `theme.white` in dark color scheme and `theme.black` in light. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (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`. - lineSize (number; optional): Height of the burger lines. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - opened (boolean; default False): State of the burger, when `True` burger is transformed into X, `False` by default. - 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; 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. - size (number; optional): Controls burger `width` and `height`, 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. - transitionDuration (number; optional): `transition-duration` property value in ms, `300` by default. - transitionTimingFunction (string; optional): `transition-timing-function` property value, `'ease'` by default. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## NavLink A Navlink component. Category: Navigation ### Basic usage Use `NavLink`'s `n_clicks` property in callbacks, or you can set `href` to make it a link. ```python import dash_mantine_components as dmc from dash import html from dash_iconify import DashIconify def get_icon(icon): return DashIconify(icon=icon, height=16) component = html.Div( [ dmc.NavLink( label="With icon", leftSection=get_icon(icon="bi:house-door-fill"), ), dmc.NavLink( label="With right section", leftSection=get_icon(icon="tabler:gauge"), rightSection=get_icon(icon="tabler-chevron-right"), ), dmc.NavLink( label="Disabled", leftSection=get_icon(icon="tabler:circle-off"), disabled=True, ), dmc.NavLink( label="With description", description="Additional information", leftSection=dmc.Badge( "3", size="xs", variant="filled", color="red", w=16, h=16, p=0 ), ), dmc.NavLink( label="Active subtle", leftSection=get_icon(icon="tabler:activity"), rightSection=get_icon(icon="tabler-chevron-right"), variant="subtle", active=True, ), dmc.NavLink( label="Active light", leftSection=get_icon(icon="tabler:activity"), rightSection=get_icon(icon="tabler-chevron-right"), active=True, ), dmc.NavLink( label="Active filled", leftSection=get_icon(icon="tabler:activity"), rightSection=get_icon(icon="tabler-chevron-right"), variant="filled", active=True, ), ], style={"width": 240}, ) ``` ### Active styles Set `active` prop to add active styles to `NavLink`. You can customize active styles with `color` and `variant` properties. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify dmc.NavLink( label="With right section", leftSection=DashIconify(icon="tabler:gauge"), active=True, variant="filled", color="orange", id="navlink-interactive", rightSection=DashIconify(icon="tabler-chevron-right"), ), ``` ### Setting Active prop based on URL The `active` prop in `NavLink` controls whether a link is highlighted as active. It can be set manually (`True`/`False`) or automatically based on the current URL. *New in dash-mantine-components > = 1.0.0* Now, `active` can be set dynamically: - `"exact"` → Active when the current pathname matches `href`. - `"partial"` → Active when the current pathname starts with `href` (includes subpages). Example: - User on `/page-1/subject-1` → The second and third links are active (since `"partial"` includes subpages). - User on `/page-1` → Only the second link is active. ```python html.Div([ dmc.NavLink(label="Home", href="/home", active="exact"), dmc.NavLink(label="Page 1", href="/page-1", active="partial"), dmc.NavLink(label="Subject 1", href="/page-1/subject-1", active="exact"), ]) ``` See a complete example in Multi-Page App Example with Active Links section. ### Setting active prop in a callback Use a callback to set `active` prop if you are using dash-mantine-components<1.0.0 This example demonstrates how to use a callback to set the `active` prop of the `NavLink` when the user navigates to a different page. It uses the "Dash Pages" feature but can be adapted to any other page navigation system. ```python # Create Navlinks (using dash.page_registry) [ dmc.NavLink( label=f"{page['name']}", href=page["relative_path"], id={"type": "navlink", "index": page["relative_path"]}, ) for page in page_registry.values() ] # ... # Callback (using the dcc.location provided by Dash Pages) @app.callback(Output({"type": "navlink", "index": ALL}, "active"), Input("_pages_location", "pathname")) def update_navlinks(pathname): return [control["id"]["index"] == pathname for control in callback_context.outputs_list] ``` ### Nested NavLinks To create nested links put dmc.NavLink as children of another dmc.NavLink. ```python import dash_mantine_components as dmc from dash import html from dash_iconify import DashIconify def get_icon(icon): return DashIconify(icon=icon, height=16) component = html.Div( style={"width": 240}, children=[ dmc.NavLink( label="First parent link", leftSection=get_icon(icon="tabler:gauge"), childrenOffset=28, children=[ dmc.NavLink(label="First child link"), dmc.NavLink(label="Second child link"), dmc.NavLink( label="Nested parent link", childrenOffset=28, children=[ dmc.NavLink(label="First child link"), dmc.NavLink(label="Second child link"), dmc.NavLink(label="Third child link"), ], ), ], ), dmc.NavLink( label="Second parent link", leftSection=get_icon(icon="tabler:fingerprint"), childrenOffset=28, opened=True, children=[ dmc.NavLink(label="First child link"), dmc.NavLink(label="Second child link"), dmc.NavLink(label="Third child link"), ], ), ], ) ``` ### Multi-Page App Example with Active Links Here's a minimal multi-page app example using Pages. It demonstrates how `active="exact"` and `active="partial"` automatically apply active styles based on the current URL ```python import dash import dash_mantine_components as dmc from dash import Dash, html app = Dash(use_pages=True, pages_folder="") dash.register_page("home", path="/", layout=html.Div("I'm home")) dash.register_page("page1", path="/page-1", layout=html.Div("Info about page 1 subjects")) dash.register_page("page1s1", path="/page-1/sub-1", layout=html.Div("page 1 subject 1")) dash.register_page("page1s2", path="/page-1/sub-2", layout=html.Div("page 1 subject 2")) component = dmc.Box([ dmc.NavLink(label="home", href="/", active='exact'), dmc.NavLink( label="Page 1", childrenOffset=28, href="/page-1", active='partial', children=[ dmc.NavLink(label="Subject 1", href="/page-1/sub-1", active="exact"), dmc.NavLink(label="Subject 2", href="/page-1/sub-2", active="exact"), ], ), dmc.Divider(mb="lg"), dash.page_container ]) app.layout = dmc.MantineProvider([component]) if __name__ == "__main__": app.run(debug=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-NavLink-root | Root element | | body | .mantine-NavLink-body | Contains label and description | | section | .mantine-NavLink-section | Left and right sections | | label | .mantine-NavLink-label | NavLink label | | description | .mantine-NavLink-description | Dimmed description displayed below the label | | children | .mantine-NavLink-children | Wrapper around nested links | | chevron | .mantine-NavLink-chevron | Default chevron icon | | collapse | .mantine-NavLink-collapse | Nested links Collapse container | ### Keyword Arguments #### NavLink - children (a list of or a singular dash component, string or number; optional): Child `NavLink` components. - id (string; optional): Unique ID to identify this component in Dash callbacks. - active (default False): Controls whether the link is styled as active (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. - 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`. - childrenOffset (number; optional): Key of `theme.spacing` or any valid CSS value to set collapsed links `padding-left`, `'lg'` 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` of any valid CSS color to control active styles, `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. - description (a list of or a singular dash component, string or number; optional): Link description, displayed below the label. - disableRightSectionRotation (boolean; optional): If set, right section will not be rotated when collapse is opened, `False` by default. - disabled (boolean; optional): If set, disabled styles will be added to the root element, `False` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - href (string; optional): href. - label (a list of or a singular dash component, string or number; optional): Main link label. - leftSection (a list of or a singular dash component, string or number; optional): Section displayed on the left side of 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - n_clicks (number; default 0): An integer that represents the number of times that this element has been clicked on. - noWrap (boolean; optional): If set, label and description will not wrap to the next line, `False` by default. - opened (boolean; default False): Controlled nested items collapse state. - 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; 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. - refresh (boolean; optional): Whether to refresh the page. - rightSection (a list of or a singular dash component, string or number; optional): Section displayed on the right side of the label. - 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 (a value equal to: '_blank', '_self'; optional): Target. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Pagination Display active page and navigate between multiple pages Category: Navigation ### Introduction ### Siblings Control the number of active item siblings with `siblings` prop. ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Pagination(total=20, siblings=1, value=10), dmc.Pagination(total=20, siblings=2, value=10, my=15), dmc.Pagination(total=20, siblings=3, value=10), ] ) ``` ### Boundaries Control the number of items displayed after previous(<) and before next(>) buttons with `boundaries` prop. ```python import dash_mantine_components as dmc component = dmc.Stack( [ dmc.Pagination(total=20, boundaries=1, value=10), dmc.Pagination(total=20, boundaries=2, value=10, my=15), dmc.Pagination(total=20, boundaries=3, value=10), ] ) ``` ### Hide pages controls Set `withPages=False` to hide pages controls: ```python from dash import html, Output, Input, callback import dash_mantine_components as dmc limit = 10 total = 145 total_pages = (total + limit - 1) // limit component = dmc.Group( justify="flex-end", children=[ dmc.Text(id="message-withPages", size="sm"), dmc.Pagination(id="pagination-withPages", total=total_pages, value=1, withPages=False), ], ) @callback( Output("message-withPages", "children"), Input("pagination-withPages", "value"), ) def update_message(page): start = limit * (page - 1) + 1 end = min(total, limit * page) return f"Showing {start} – {end} of {total}" ``` ### 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-Pagination-root | Root element | | control | .mantine-Pagination-control | Control element: items, next/previous, first/last buttons | | dots | .mantine-Pagination-dots | Dots icon wrapper | ### Keyword Arguments #### Pagination - 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 active item text color should depend on `background-color` of the indicator. 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`. - boundaries (number; optional): Number of elements visible on the left/right edges, `1` 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`, active item 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): Determines whether all controls should be disabled, `False` by default. - gap (number; optional): Key of `theme.spacing`, gap between controls, `8` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - hideWithOnePage (boolean; optional): Determines whether the pagination should be hidden when only one page is available (total=1), 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - 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; 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. - siblings (number; optional): Number of siblings displayed on the left/right side of the selected page, `1` by default. - size (number; optional): `height` and `min-width` of controls, `'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. - total (number; required): Total number of pages, must be an integer. - value (number; optional): Active page for controlled component, must be an integer in [0, total] interval. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. - withControls (boolean; optional): Determines whether next/previous controls should be rendered, True by default. - withEdges (boolean; optional): Determines whether first/last controls should be rendered, False by default. - withPages (boolean; optional): Determines whether pages controls should be displayed, `True` by default. ## Stepper Use the Stepper, StepperStep and StepperCompleted components to display content divided into a steps sequence Category: Navigation ### Basic usage ```python import dash_mantine_components as dmc from dash import html, Output, Input, State, ctx, callback min_step = 0 max_step = 3 active = 1 component = html.Div( [ dmc.Stepper( id="stepper-basic-usage", active=active, children=[ dmc.StepperStep( label="First step", description="Create an account", children=dmc.Text("Step 1 content: Create an account", ta="center"), ), dmc.StepperStep( label="Second step", description="Verify email", children=dmc.Text("Step 2 content: Verify email", ta="center"), ), dmc.StepperStep( label="Final step", description="Get full access", children=dmc.Text("Step 3 content: Get full access", ta="center"), ), dmc.StepperCompleted( children=dmc.Text( "Completed, click back button to get to previous step", ta="center", ) ), ], ), dmc.Group( justify="center", mt="xl", children=[ dmc.Button("Back", id="back-basic-usage", variant="default"), dmc.Button("Next step", id="next-basic-usage"), ], ), ] ) @callback( Output("stepper-basic-usage", "active"), Input("back-basic-usage", "n_clicks"), Input("next-basic-usage", "n_clicks"), State("stepper-basic-usage", "active"), prevent_initial_call=True, ) def update(back, next_, current): button_id = ctx.triggered_id step = current if current is not None else active if button_id == "back-basic-usage": step = step - 1 if step > min_step else step else: step = step + 1 if step < max_step else step return step ``` ### Color, radius and size You can use any color from Mantine's theme colors. Colors can also be set on individual steps. ```python import dash_mantine_components as dmc dmc.Stepper( active=1, color="green", radius="lg", size="sm", children=[ dmc.StepperStep(label="First step", description="Create an account"), dmc.StepperStep(label="Second step", description="Verify email"), ], ) ``` Component size is controlled by two props: `size` and `iconSize`. `size` prop controls icon size, label and description font size. `iconSize` allows to overwrite icon size separately from other size values. ```python import dash_mantine_components as dmc dmc.Stepper( active=1, iconSize=42, children=[ dmc.StepperStep(label="First step", description="Create an account"), dmc.StepperStep(label="Second step", description="Verify email"), ], ) ``` ### Loading state To indicate loading state set `loading` prop on `Step` component, `Loader` will replace step icon. ```python import dash_mantine_components as dmc from dash import html component = html.Div( [ dmc.Stepper( active=1, children=[ dmc.StepperStep( label="First step", description="Create an account", children=dmc.Text("Step 1 content: Create an account", ta="center"), ), dmc.StepperStep( label="Second step", description="Verify email", children=dmc.Text("Step 2 content: Verify email", ta="center"), loading=True, ), dmc.StepperStep( label="Final step", description="Get full access", children=dmc.Text("Step 3 content: Get full access", ta="center"), ), ], ), ] ) ``` ### Custom icons You can replace step icon by setting `icon` prop on Step component. To change completed check icon set `completedIcon` on Stepper component. You can also change completed icon for each step, for example, to indicate error state. ```python import dash_mantine_components as dmc from dash import callback, Output, Input, State, ctx from dash_iconify import DashIconify min_step = 0 max_step = 3 active = 1 def get_icon(icon): return DashIconify(icon=icon, height=20) component = dmc.Container( [ dmc.Stepper( id="stepper-custom-icons", active=active, children=[ dmc.StepperStep( label="First step", description="Create an account", icon=get_icon(icon="material-symbols:account-circle"), progressIcon=get_icon(icon="material-symbols:account-circle"), completedIcon=get_icon(icon="mdi:account-check"), children=[ dmc.Text("Step 1 content: Create an account", ta="center") ], ), dmc.StepperStep( label="Second step", description="Verify email", icon=get_icon(icon="ic:outline-email"), progressIcon=get_icon(icon="ic:outline-email"), completedIcon=get_icon( icon="material-symbols:mark-email-read-rounded" ), children=[dmc.Text("Step 2 content: Verify email", ta="center")], ), dmc.StepperStep( label="Final step", description="Get full access", icon=get_icon(icon="material-symbols:lock-outline"), progressIcon=get_icon(icon="material-symbols:lock-outline"), completedIcon=get_icon(icon="material-symbols:lock-open-outline"), children=[dmc.Text("Step 3 content: Get full access", ta="center")], ), dmc.StepperCompleted( children=[ dmc.Text( "Completed, click back button to get to previous step", ta="center", ) ] ), ], ), dmc.Group( justify="center", mt="xl", children=[ dmc.Button("Back", id="back-custom-icons", variant="default"), dmc.Button("Next step", id="next-custom-icons"), ], ), ] ) @callback( Output("stepper-custom-icons", "active"), Input("back-custom-icons", "n_clicks"), Input("next-custom-icons", "n_clicks"), State("stepper-custom-icons", "active"), prevent_initial_call=True, ) def update_with_icons(back, next_, current): button_id = ctx.triggered_id step = current if current is not None else active if button_id == "back-custom-icons": step = step - 1 if step > min_step else step else: step = step + 1 if step < max_step else step return step ``` ### Vertical orientation ```python import dash_mantine_components as dmc component = dmc.Stepper( active=1, orientation="vertical", children=[ dmc.StepperStep(label="First step", description="Create an account"), dmc.StepperStep(label="Second step", description="Verify email"), dmc.StepperStep(label="Final step", description="Get full access"), ], ) ``` ### 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-Stepper-root | Root element | | steps | .mantine-Stepper-steps | Steps controls wrapper | | separator | .mantine-Stepper-separator | Separator line between step controls | | verticalSeparator | .mantine-Stepper-verticalSeparator | Vertical separator line between step controls | | separatorActive | .mantine-Stepper-separatorActive | Separator active modifier | | verticalSeparatorActive | .mantine-Stepper-verticalSeparatorActive | Vertical separator active modifier | | content | .mantine-Stepper-content | Current step content wrapper | | stepWrapper | .mantine-Stepper-stepWrapper | Wrapper for the step icon and separator | | step | .mantine-Stepper-step | Step control button | | stepIcon | .mantine-Stepper-stepIcon | Step icon wrapper | | stepCompletedIcon | .mantine-Stepper-stepCompletedIcon | Completed step icon, rendered within stepIcon | | stepBody | .mantine-Stepper-stepBody | Contains stepLabel and stepDescription | | stepLabel | .mantine-Stepper-stepLabel | Step label | | stepDescription | .mantine-Stepper-stepDescription | Step description | | stepLoader | .mantine-Stepper-stepLoader | Step loader | ### Keyword Arguments #### Stepper - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - active (number; required): Index of the active step. - allowNextStepsSelect (boolean; optional): Determines whether next steps can be selected, `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. - autoContrast (boolean; optional): Determines whether icon 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, controls colors of active and progress steps, `theme.primaryColor` by default. - completedIcon (a list of or a singular dash component, string or number; optional): Step icon displayed when step is completed, check icon by default. - contentPadding (number; optional): Key of `theme.spacing` or any valid CSS value to set `padding-top` of the content. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - icon (a list of or a singular dash component, string or number; optional): Step icon, default value is step index + 1. - iconPosition (a value equal to: 'left', 'right'; optional): Icon position relative to the step body, `'left'` by default. - iconSize (string | number; optional): Controls size of the step icon, by default icon size is inferred from `size` prop. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - orientation (a value equal to: 'vertical', 'horizontal'; optional): Stepper orientation, `'horizontal'` by default. - progressIcon (a list of or a singular dash component, string or number; optional): Step icon displayed when step is in progress, default value is step index + 1. - radius (number; optional): Key of `theme.radius` or any valid CSS value to set steps border-radius, `"xl"` by default. - size (a value equal to: 'xs', 'sm', 'md', 'lg', 'xl'; optional): Controls size of various Stepper elements. - 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 (optional): Breakpoint below which the component is hidden with `display: none`. - wrap (boolean; optional): Determines whether steps should wrap to the next line if no space is available, `True` by default. #### StepperStep - children (a list of or a singular dash component, string or number; optional) - id (string; optional): Unique ID to identify this component in Dash callbacks. - allowStepClick (boolean; optional): Set to False to disable clicks on step. - allowStepSelect (boolean; optional): Should step selection be allowed. - 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`, by default controlled by Stepper component. - completedIcon (a list of or a singular dash component, string or number; optional): Step icon displayed when step is completed. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - description (a list of or a singular dash component, string or number; optional): Step description. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - icon (a list of or a singular dash component, string or number; optional): Step icon, defaults to step index + 1 when rendered within Stepper. - iconPosition (a value equal to: 'left', 'right'; optional): Icon position relative to step body, controlled by Stepper component. - iconSize (number; optional): Icon wrapper size. - label (a list of or a singular dash component, string or number; optional): Step label, render after icon. - lightHidden (boolean; optional): Determines whether component should be hidden in light color scheme with `display: none`. - loading (boolean; optional): Indicates loading state of the step. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - orientation (a value equal to: 'vertical', 'horizontal'; optional): Component orientation. - progressIcon (a list of or a singular dash component, string or number; optional): Step icon displayed when step is in progress. - state (a value equal to: 'stepInactive', 'stepProgress', 'stepCompleted'; optional): Step state, controlled by Stepper component. - step (number; optional): Step index, controlled by Stepper 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. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. - withIcon (boolean; optional): Determines whether the icon should be displayed. #### StepperCompleted - children (a list of or a singular dash component, string or number; optional) ## Tabs Use the Tab and Tabs component to switch between views. Category: Navigation ### Usage ```python import dash_mantine_components as dmc dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Gallery", value="gallery"), dmc.TabsTab("Messages", value="messages"), dmc.TabsTab("Settings", value="settings"), ] ), dmc.TabsPanel("Gallery tab content", value="gallery"), dmc.TabsPanel("Messages tab content", value="messages"), dmc.TabsPanel("Settings tab content", value="settings"), ], color="red", # default is blue orientation="horizontal", # or "vertical" variant="default", # or "outline" or "pills" value="gallery" ) ``` ### Variants Use the `variant` can be set to `"default"`, `"outline"` or `"pills"` ### Change colors To change colors of all tabs, set `color` on `Tabs` component, to change color of the individual tab, set `color` on `TabsTab`. ```python import dash_mantine_components as dmc component = dmc.Tabs( color="teal", value="first", children=[ dmc.TabsList( children=[ dmc.TabsTab("Teal tab", value="first"), dmc.TabsTab("Blue tab", value="second", color="blue"), ] ), dmc.TabsPanel( "First tab color is teal, it gets this value from context", value="first", pt="xs", ), dmc.TabsPanel( "Second tab color is blue, it gets this value from props, props have the priority and will override context value", value="second", pt="xs", ), ], ) ``` ### Icons on right or left You can use any dash component as icon and rightSection in dmc.TabsTab component. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab( "Gallery", leftSection=DashIconify(icon="tabler:photo"), value="gallery", ), dmc.TabsTab( "Messages", leftSection=DashIconify(icon="tabler:message"), value="messages", ), dmc.TabsTab( "Settings", leftSection=DashIconify(icon="tabler:settings"), value="settings", ), ] ), ], value="messages", ) ``` ```python import dash_mantine_components as dmc from dash_iconify import DashIconify component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab( "Messages", rightSection=dmc.Badge( "6", size="xs", p=0, variant="filled", circle=True ), value="messages", ), dmc.TabsTab( "Settings", rightSection=DashIconify(icon="tabler:alert-circle", width=16), value="settings", ), ] ), ], value="messages", ) ``` ### Tabs Position `Tabs` controls position is controlled with `grow` and `justify` properties in `TabsList` component. If `grow` property is set to `True`, controls will take 100% of available space and `justify` property is ignored. ```python import dash_mantine_components as dmc dmc.Tabs( children=[ dmc.TabsList( justify="right", grow=False, children=[...], ) # tabs panel below ] ) ``` ### Separated Tabs To display tab on the opposite side, set `margin-left` to auto with `ml="auto"` in `TabsTab` component. ```python import dash_mantine_components as dmc component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Gallery", value="gallery"), dmc.TabsTab("Messages", value="messages"), dmc.TabsTab("Settings", value="settings", ml="auto"), ] ), ], value="gallery", ) ``` ### Inverted Tabs To make tabs inverted, place `TabsPanel` components before `TabsList` and add `inverted=True` prop to `Tabs` component. ```python import dash_mantine_components as dmc component = dmc.Tabs( [ dmc.TabsPanel("Gallery tab content", value="gallery", pb="xs"), dmc.TabsPanel("Messages tab content", value="messages", pb="xs"), dmc.TabsPanel("Settings tab content", value="settings", pb="xs"), dmc.TabsList( [ dmc.TabsTab("Gallery", value="gallery"), dmc.TabsTab("Messages", value="messages"), dmc.TabsTab("Settings", value="settings", ml="auto"), ] ), ], value="gallery", inverted=True, ) ``` ### Vertical Tabs placement To change placement of `TabsList` in vertical orientation, set `placement` prop in `Tabs`. ### Disabled tabs Set `disabled=True` prop on `TabsTab` component to disable tab. Disabled tab cannot be activated with mouse or keyboard, and they will be skipped when user navigates with arrow keys: ```python import dash_mantine_components as dmc component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Gallery", value="gallery"), dmc.TabsTab("Messages", value="messages", disabled=True), dmc.TabsTab("Settings", value="settings"), ] ), dmc.TabsPanel("Gallery tab content", value="gallery"), dmc.TabsPanel("Messages tab content", value="messages"), dmc.TabsPanel("Settings tab content", value="settings"), ], value="gallery" ) ``` ### Activation mode By default, tabs are activated when user presses arrows keys or Home/End keys. To disable that set `activateTabWithKeyboard=False` on `Tabs` component. This can be useful if the tab content is updated in a long running callback. Try clicking on a tab to focus, then navigate to other tabs with arrow keys, or home/end keys: ```python import dash_mantine_components as dmc dmc.Tabs( activateTabWithKeyboard=False, children=[ # tabs content ], ) ``` ### Tab deactivation By default, active tab cannot be deactivated. To allow that set `allowTabDeactivation=True` on Tabs component: Try clicking on the active tab to see the deactivated state: ### Content As Callback Attach a callback to the Tabs `value` prop and update a container's `children` property in your callback. ```python import dash_mantine_components as dmc from dash import Input, Output, html, callback from lib.utils import create_graph component = html.Div( [ dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Tab one", value="1"), dmc.TabsTab("Tab two", value="2"), ] ), ], id="tabs-example", value="1", ), html.Div(id="tabs-content", style={"paddingTop": 10}), ] ) @callback(Output("tabs-content", "children"), Input("tabs-example", "value")) def render_content(active): if active == "1": return [dmc.Text("Tab One selected", my=10), create_graph()] else: return [dmc.Text("Tab Two selected", my=10), create_graph()] ``` ### Content As Tab Children Instead of displaying the content through a callback, you can embed the content directly as the `children` property in the Tab component. ```python import dash_mantine_components as dmc from lib.utils import create_graph component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Tab one", value="1"), dmc.TabsTab("Tab two", value="2"), dmc.TabsTab("Tab three", value="3"), ] ), dmc.TabsPanel(create_graph(), value="1"), dmc.TabsPanel(create_graph(), value="2"), dmc.TabsPanel(create_graph(), value="3"), ], value="1", ) ``` ### Styling the Tabs #### With Props This example demonstrates how to style tabs using only props, without requiring additional CSS files: - **Variant**: Sets `variant="pills"` to make the tabs resemble buttons. - **Grow Prop**: Uses the `grow` prop on the `TabsList` component, causing the tabs to expand and fill the full width of the viewport. - **Border**: Adds a border around the tabs with the `bd` prop. For more details, see the [Style Props](/style-props) section. - **Border Color**: Sets the border color using the Mantine CSS variable `var(--mantine-color-default-border)`, ensuring a border color that works well in both light and dark modes. See the [Colors](/colors) section for more details. - **Active Tab Color**: Sets the active tab color with `color="green.3"`. This specifies a lighter shade of a built-in color. Mantine’s color palette includes 10 shades for each color, indexed from 0 (lightest) to 9 (darkest). Learn more in the [Colors](/colors) section. - **Auto Contrast**: Enables `autoContrast=True` to automatically adjust the text color for better readability when using lighter or darker background colors. Additional details can be found in the [Colors](/colors) section. ```python import dash_mantine_components as dmc component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Gallery", value="gallery"), dmc.TabsTab("Messages", value="messages"), dmc.TabsTab("Settings", value="settings"), ], grow=True, bd="1px solid var(--mantine-color-default-border)" ), dmc.TabsPanel("Gallery tab content", value="gallery"), dmc.TabsPanel("Messages tab content", value="messages"), dmc.TabsPanel("Settings tab content", value="settings"), ], color="green.3", autoContrast=True, variant="pills", value="gallery", ) ``` #### With Styles API This example demonstrates styling tabs using the Styles API, allowing for precise control over the appearance of each element in the tabs component. For more information, see the Styles API section below. ```python import dash_mantine_components as dmc component = dmc.Tabs( [ dmc.TabsList( [ dmc.TabsTab("Gallery", value="gallery"), dmc.TabsTab("Messages", value="messages"), dmc.TabsTab("Settings", value="settings"), ], grow=True ), dmc.TabsPanel("Gallery tab content", value="gallery"), dmc.TabsPanel("Messages tab content", value="messages"), dmc.TabsPanel("Settings tab content", value="settings"), ], value="gallery", classNames={"tab": "dmc-tabs"} ) ``` Put the following in a `.css` file in the `/assets` folder ```css .dmc-tabs { position: relative; border: 1px solid light-dark(var(--mantine-color-gray-2), var(--mantine-color-dark-4)); background-color: light-dark(var(--mantine-color-white), var(--mantine-color-dark-6)); &:first-of-type { border-radius: 4px 0 0 4px; } &:last-of-type { border-radius: 0 4px 4px 0; } & + & { border-left-width: 0; } &:hover { background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-5)); } &[data-active] { z-index: 1; background-color: var(--mantine-color-blue-filled); border-color: var(--mantine-color-blue-filled); color: var(--mantine-color-white); &:hover { background-color: var(--mantine-color-blue-filled-hover); } } } ``` ### 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 Tabs Style API [interactive demo](https://mantine.dev/core/tabs/#styles-api) for help in identifying each selector. #### Tabs Selectors | Selector | Static selector | Description | |--------------|------------------------------|------------------------------------------| | root | .mantine-Tabs-root | Root element (Tabs component) | | list | .mantine-Tabs-list | List of tabs (Tabs.List component) | | panel | .mantine-Tabs-panel | Panel with tab content (Tabs.Panel component) | | tab | .mantine-Tabs-tab | Tab button (Tabs.Tab component) | | tabLabel | .mantine-Tabs-tabLabel | Label of Tabs.Tab | | tabSection | .mantine-Tabs-tabSection | Left and right sections of Tabs.Tab | #### Tabs CSS Variables | Selector | Variable | Description | |----------|-----------------|--------------------------------------------------------------| | root | --tabs-color | Controls colors of Tabs.Tab, only applicable for `pills` or `default` variant | | | --tabs-radius | Controls Tabs.Tab border-radius | #### Tabs Data Attributes | Selector | Attribute | Condition | Value | |-------------------|--------------------|-------------------------------------------|------------------------------| | root, tab, list, panel | data-orientation | – | Value of `orientation` prop | | root, tab, list | data-placement | `orientation` is "vertical" on Tabs component | Value of `placement` prop | | tab, list | data-inverted | `inverted` prop is set on Tabs component | – | | list | data-grow | `grow` prop is set on Tabs.List component | – | | tabSection | data-position | – | Position of the section (left or right) | ### Keyword Arguments #### Tabs - children (a list of or a singular dash component, string or number; required): Tabs content. - id (string; optional): Base id, used to generate ids to connect labels with controls, generated randomly by default. - activateTabWithKeyboard (boolean; optional): Determines whether tab should be activated with arrow key press, `True` by default. - allowTabDeactivation (boolean; optional): Determines whether tab can be deactivated, `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. - autoContrast (boolean; optional): Determines whether active item text color should depend on `background-color` of the indicator. 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`. Only applicable when `variant="pills"`. - 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): Changes colors of `Tabs.Tab` components when variant is `pills` or `default`, does nothing for other variants. - darkHidden (boolean; optional): Determines whether component should be hidden in dark color scheme with `display: none`. - data-* (string; optional): Wild card data attributes. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - inverted (boolean; optional): Determines whether tabs should have inverted styles, `False` by default. - keepMounted (boolean; optional): If set to `False`, `Tabs.Panel` content will be unmounted when the associated tab is not active, `True` 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: - loop (boolean; optional): Determines whether arrow key presses should loop though items (first to last and last to first), `True` by default. - mod (string; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - orientation (a value equal to: 'vertical', 'horizontal'; optional): Tabs orientation, `'horizontal'` by default. - 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; 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. - placement (a value equal to: 'left', 'right'; optional): `Tabs.List` placement relative to `Tabs.Panel`, applicable only when `orientation="vertical"`, `'left'` by default. - radius (number; optional): Key of `theme.radius` or any valid CSS value to set `border-radius`, `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. - value (string; optional): Value for controlled component. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. #### TabsList - children (a list of or a singular dash component, string or number; required): `Tabs.Tab` 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. - grow (boolean; optional): Determines whether tabs should take all available space, `False` by default. - hiddenFrom (optional): Breakpoint above which the component is hidden with `display: none`. - justify (optional): Tabs alignment, `flex-start` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 (optional): Breakpoint below which the component is hidden with `display: none`. #### TabsPanel - children (a list of or a singular dash component, string or number; required): Panel 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 (optional): Breakpoint above which the component is hidden with `display: none`. - keepMounted (boolean; optional): If set to `True`, the content will be kept mounted, even if `keepMounted` is set `False` in the parent `Tabs` 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, 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 of associated control. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. #### Tab - children (a list of or a singular dash component, string or number; optional): Tab 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. - 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, controls control color based on `variant`. - 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. - hiddenFrom (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 label, for example, icon. - 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; optional): Element modifiers transformed into `data-` attributes, for example, `{ 'data-size': 'xl' }`, falsy values are removed. - rightSection (a list of or a singular dash component, string or number; optional): Content displayed on the right side of the label, for example, icon. - size (string | number; optional): Size passed from parent component, sets `data-size` if value is not number like. - 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 of associated panel. - variant (string; optional): variant. - visibleFrom (optional): Breakpoint below which the component is hidden with `display: none`. ## Tree Display a Tree structure Category: Navigation ### Simple Example `Tree` component is used to display hierarchical data. `Tree` component has minimal styling by default, you can customize styles with Styles API. ```python import dash_mantine_components as dmc from .data import data component = dmc.Tree(data=data) ``` ### Data Data passed to the `data` prop should follow these rules: - Data must be an array - Each item in the array represents a node in the tree - Each node must be a dictionary with value and label keys - Each node can have children key with an array of child nodes - The value of each node must be unique ```python # ✅ Valid data, all values are unique valid_data = [ { "value": "src", "label": "src", "children": [ {"value": "src/components", "label": "components"}, {"value": "src/hooks", "label": "hooks"}, ], }, {"value": "package.json", "label": "package.json"}, ] # ❌ Invalid data, values are not unique (components is used twice) invalid_data = [ { "value": "src", "label": "src", "children": [{"value": "components", "label": "components"}], }, {"value": "components", "label": "components"}, ] ``` ### Icon Side The expanded and collapsed icons are on the left side of the label by default. To move them to the right side, set `iconSide="right` ```python import dash_mantine_components as dmc from .data import data component = dmc.Tree(data=data, iconSide="right") ``` ### Remove Expanded Icon By default the `Tree` includes a chevron to indicate expanded and collapsed nodes. To remove the icons, set `expandedIcon=None` ```python import dash_mantine_components as dmc from .data import data component = dmc.Tree(data=data, expandedIcon=None) ``` ### Change Expanded Icon Use any icon in the `expandedIcon` prop. If no `collapsedIcon` is set, the icon will be rotated to indicate the collapsed state. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify from .data import data component = dmc.Tree( data=data, expandedIcon=DashIconify(icon="fa6-solid:arrow-down") ) ``` ### Change Expanded and Collapsed Icons When both the `expandedIcon` and `collapsedIcon` props are set, the icons will not be rotated. ```python import dash_mantine_components as dmc from dash_iconify import DashIconify from .data import data component = dmc.Tree( data=data, expandedIcon=DashIconify(icon="fa6-regular:folder-open"), collapsedIcon=DashIconify(icon="fa6-solid:folder-plus"), ) ``` ### Set Expanded state To set the state of the nodes, use the `expanded` prop. Note that leaf nodes can be included, but it will only change the expanded/collapsed display of the nodes with children. ```python import json import dash_mantine_components as dmc from dash import callback, Input, Output from .data import data component = dmc.Stack([ dmc.Tree( data=data, expanded=[ "node_modules", "node_modules/@mantine", "node_modules/@mantine/form", "node_modules/@mantine/form/index.d.ts", ], id="tree-expanded" ), dmc.CodeHighlight(id="expanded-nodes", code="", language="json"), ]) @callback( Output("expanded-nodes", "code"), Input("tree-expanded", "expanded") ) def update(expanded): return json.dumps( expanded, indent=4) ``` ### Expand or Collapse All Expand all will include all items of the `data` prop in the `expanded` prop. ```python import dash_mantine_components as dmc from dash import callback, Input, Output from .data import data component = dmc.Box([ dmc.SegmentedControl( id="tree-expand-all", data=["Expand All", "Collapse All"], value="Collapse All", mb="sm" ), dmc.Tree( data=data, id="tree-all" ) ],p="lg") @callback( Output("tree-all", "expanded"), Input("tree-expand-all", "value") ) def update(value): if value=="Collapse All": return [] return '*' ``` ### Expanded State in callbacks. When using the expanded property as a callback input to track the user's selected expanded state, note that the `expanded` list may include or exclude leaf nodes (nodes without children) depending on user interaction. This happens because users can toggle the state of leaf nodes, even though they don’t affect how the tree data is displayed. To handle this, ensure your callback logic accounts for the possibility that leaf nodes may or may not be present in the `expanded` prop. Note also that the nodes included in the `expanded` prop are ordered based on user interation and the order of operations. ### With Checkboxes Use the `checked` prop to set or track the checked items. Note that only leaves can be checked, and the order will be based on user interation and the order of operations. ```python import json import dash_mantine_components as dmc from dash import callback, Input, Output from .data import data component = dmc.Stack([ dmc.Tree(data=data, checkboxes=True, id="tree-checkboxes" ), dmc.CodeHighlight(id="checked-nodes", code="", language="json"), ]) @callback( Output("checked-nodes", "code"), Input("tree-checkboxes", "checked") ) def update(checked): return json.dumps( checked, indent=4) ``` ### Custom Tree rendering By default, `dmc.Tree` includes a built-in `renderNode` function that covers most common use cases. It requires no JavaScript and supports some customization through props like `checkboxes`, `expandedIcon`, and `iconSide`. If you need more control over how each node is rendered, such as using custom icons based on the data, arranging content differently or advanced styling, you can provide your own `renderNode` function written in JavaScript. This advanced feature is designed for use cases that go beyond what the built-in options support. #### Ignored Props When you supply your own `renderNode` function, the following props are ignored: * `checkboxes` * `expandedIcon` * `collapsedIcon` * `iconSide` These props only apply when you're using the default built-in renderer. If you're using a custom `renderNode`, you are responsible for rendering icons, checkboxes, or any other visual element. #### Example: Files Tree 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 import dash_iconify # required in order to use DashIconify in the renderNode function from .data import data component = dmc.Tree( data=data, renderNode={"function": "myLeaf"}, expanded=[ "node_modules", "node_modules/react", ] ) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; dmcfuncs.myLeaf = function (payload) { const dmc = window.dash_mantine_components; const iconify = window.dash_iconify; function getIcon(name, isFolder, expanded) { const size = 14; if (name.endsWith('package.json')) { return React.createElement(iconify.DashIconify, { icon: 'logos:npm-icon', width: size, height: size }); } if ( name.endsWith('.ts') || name.endsWith('.tsx') || name.endsWith('tsconfig.json') ) { return React.createElement(iconify.DashIconify, { icon: 'logos:typescript-icon', width: size, height: size }); } if (name.endsWith('.css')) { return React.createElement(iconify.DashIconify, { icon: 'vscode-icons:file-type-css', width: size, height: size }); } if (isFolder) { return React.createElement(iconify.DashIconify, { icon: expanded ? 'tabler:folder-open' : 'tabler:folder', width: size, height: size, color: '#f59f00' // Mantine yellow-9 }); } return null; } const { node, expanded, hasChildren, elementProps } = payload; return React.createElement( dmc.Group, { key: payload.node.value, gap: 5, ...elementProps }, getIcon(node.value, hasChildren, expanded), React.createElement('span', null, node.label) ); }; ``` #### Example: Tree with Checkboxes Note: This example uses custom JavaScript defined in the assets folder. Learn more in the "Functions As Props" section of this document. If the "With Checkboxes" example above does not meet your needs, you can use the `renderNode` prop to fully customize how each tree node is rendered using JavaScript. When using a custom `renderNode`, you are responsible for implementing the checkbox and expand/collapse logic yourself. To handle the checked state, you'll need to render a `CheckboxIndicator` manually inside your custom render function and call `tree.checkNode(...)` or `tree.uncheckNode(...)` to update it. ```python import json import dash_mantine_components as dmc from dash import callback, Input, Output import dash_iconify # necessary to import here in order to use in the renderNode function from .data import data component = dmc.Stack([ dmc.Tree( data=data, levelOffset=23, expandOnClick=False, renderNode={"function": "myLeafCheckbox"}, id="tree-checkboxes-renderNode" ), dmc.CodeHighlight(id="checked-nodes-renderNode", code="", language="json"), ]) @callback( Output("checked-nodes-renderNode", "code"), Input("tree-checkboxes-renderNode", "checked") ) def update(checked): return json.dumps( checked, indent=4) ``` ```javascript var dmcfuncs = window.dashMantineFunctions = window.dashMantineFunctions || {}; dmcfuncs.myLeafCheckbox = function (payload) { const React = window.React; const dmc = window.dash_mantine_components; const iconify = window.dash_iconify; const { node, expanded, hasChildren, elementProps, tree } = payload; const checked = tree.isNodeChecked(node.value); const indeterminate = tree.isNodeIndeterminate(node.value); return React.createElement( dmc.Group, { key: node.value, gap: "xs", ...elementProps }, [ React.createElement(dmc.CheckboxIndicator, { key: "checkbox", checked, indeterminate, onClick: (e) => { e.stopPropagation(); if (checked) { tree.uncheckNode(node.value); } else { tree.checkNode(node.value); } }, }), React.createElement( dmc.Group, { key: "label-group", gap: 5, onClick: () => tree.toggleExpanded(node.value), }, [ React.createElement("span", { key: "label" }, node.label), hasChildren && React.createElement(iconify.DashIconify, { key: "icon", icon: "tabler:chevron-down", width: 14, style: { transform: expanded ? "rotate(180deg)" : "rotate(0deg)", transition: "transform 0.2s ease", }, }), ] ), ] ); }; ``` #### renderNode Arguments The `renderNode` function receives a single `payload` object with the following fields: ```js export interface RenderTreeNodePayload { /** Node level in the tree */ level: number; /** `true` if the node is expanded, applicable only for nodes with `children` */ expanded: boolean; /** `true` if the node has non-empty `children` array */ hasChildren: boolean; /** `true` if the node is selected */ selected: boolean; /** Node data from the `data` prop of `Tree` */ node: TreeNodeData; /** Tree controller instance, return value of `useTree` hook */ tree: TreeController; /** Props to spread into the root node element */ elementProps: { className: string; style: React.CSSProperties; onClick: (event: React.MouseEvent) => void; 'data-selected': boolean | undefined; 'data-value': string; 'data-hovered': boolean | undefined; }; } ``` ### 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. #### Tree Selectors | Selector | Static selector | Description | |----------|--------------------------|-------------------------------------| | root | .mantine-Tree-root | Root element | | node | .mantine-Tree-node | Node element (`li`), contains label and subtree elements | | subtree | .mantine-Tree-subtree | Subtree element (`ul`) | | label | .mantine-Tree-label | Node label | #### Tree CSS Variables | Selector | Variable | Description | |----------|-----------------|---------------------------------------| | root | --level-offset | Controls offset of nested tree levels | #### Tree Data Attributes | Selector | Attribute | Condition | Value | |--------------|----------------|------------------------|------------------------| | node, label | data-selected | The node is selected | – | | node, label | data-hovered | The node is hovered | – | | node | data-level | – | Nesting level of the node | ### Keyword Arguments #### Tree - id (string; optional): Unique ID to identify this component in Dash callbacks. - allowRangeSelection (boolean; optional): Determines whether tree nodes range can be selected with click when Shift key is pressed, `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. - checkOnSpace (boolean; optional): Determines whether tree node should be checked on space key press, `False` by default. - checkboxes (boolean; optional): Determines if checkboxes should be rendered, `False` by default. Ignored when using a custom `renderNode` function. - checked (list of strings; optional): Determines checked nodes as a list of values (note that only leaves can be checked), `[]` 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. - clearSelectionOnOutsideClick (boolean; optional): Determines whether selection should be cleared when user clicks outside of the tree, `False` by default. - collapsedIcon (a list of or a singular dash component, string or number; optional): Collapsed state icon. Ignored when using a custom `renderNode` function. - 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 nodes. `data` is a list of dicts with keys: - data-* (string; optional): Wild card data attributes. - expandOnClick (boolean; optional): Determines whether tree node with children should be expanded on click, `True` by default. - expandOnSpace (boolean; optional): Determines whether tree node with children should be expanded on space key press, `True` by default. - expanded (list of strings; optional): Determines expanded nodes as a list of values or `'*'` for all, `[]` by default. - expandedIcon (a list of or a singular dash component, string or number; defaultRichTextEditor
component focuses on usability and is designed to be as simple as possible to bring a familiar editing experience to regular users. RichTextEditor
is based on Tiptap.dev and supports all of its features: