Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix closeButtonProps and clearButtonProps #493

Merged
merged 7 commits into from
Feb 3, 2025

Conversation

AnnMarieW
Copy link
Collaborator

@AnnMarieW AnnMarieW commented Jan 27, 2025

closes #492

  • fix modal closeButtonProps
  • fix clearButtonProps

sample app on PyCafe

@AnnMarieW AnnMarieW changed the title fix modal closeButtonProps fix closeButtonProps and clearButtonProps Jan 28, 2025
Copy link

Test Environment for snehilvj/dash-mantine-components-493
Updated on: 2025-01-28 20:58:10 UTC

@AnnMarieW
Copy link
Collaborator Author

Here's a minimal example for the modal:

Image

import dash_mantine_components as dmc
from dash import Dash, _dash_renderer, html, Output, Input, State, callback

from dash_iconify import DashIconify
_dash_renderer._set_react_version("18.2.0")

app = Dash(__name__)

component = html.Div(
    [
        dmc.Button("Open Modal", id="modal-demo-button"),
        dmc.Modal(
            title="New Modal",
            id="modal-simple",
            closeButtonProps={
                "children": html.Div(" close", id="my-component"),
                "icon": DashIconify(icon="radix-icons:cross-circled", color="red"),
                "style": {"width": 60},
            },
            children=[
                dmc.Text("I am in a modal component."),
            ],
        ),
    ]
)

app.layout = dmc.MantineProvider(component)

@callback(
    Output("modal-simple", "opened"),
    Input("modal-demo-button", "n_clicks"),
    State("modal-simple", "opened"),
    prevent_initial_call=True,
)
def modal_demo(nc1, opened):
    return not opened


if __name__ == "__main__":
    app.run_server(debug=True)


Here's an example showing that you can set an icon and children to component. Not that typically the children should not be used except for adding labels for screen readers.

https://github.com/mantinedev/mantine/blob/master/packages/%40mantine/core/src/components/CloseButton/CloseButton.tsx#L40

Image

import dash_mantine_components as dmc
from dash_iconify import DashIconify
from dash import Dash, _dash_renderer
_dash_renderer._set_react_version("18.2.0")

app = Dash(external_stylesheets=dmc.styles.ALL)

component = dmc.DatePickerInput(
    label="Date clearable",
    value="2025-01-01",
    w=300,
    clearable=True,
    clearButtonProps={
        "children" : dmc.Text("C"),
        "icon": DashIconify(icon="radix-icons:cross-circled", color="red", width=30),
        "size": 24
    }
)

app.layout = dmc.MantineProvider(
    component
)

if __name__ == "__main__":
    app.run(debug=True)

iconSize?: number | string;
/** Content rendered inside the button, for example `VisuallyHidden` with label for screen readers */
children?: React.ReactNode;
/** Replaces default close icon. If set, `iconSize` prop is ignored. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear buttons still have a default "close" icon?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kinda guessing on the clear button props because they aren't listed in their docs

https://mantine.dev/core/input/#inputclearbutton-component
https://mantine.dev/core/input/?t=props

Looking at their source code, it looks like they are taking the CloseButton and just updating it for the calculated size:
https://github.com/mantinedev/mantine/blob/master/packages/%40mantine/core/src/components/Input/InputClearButton/InputClearButton.tsx

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@AnnMarieW AnnMarieW merged commit bff38b4 into snehilvj:master Feb 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants