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

Possible to hover as an action or identify the current step of yada? #31

Open
Hunknown opened this issue Oct 3, 2024 · 2 comments
Open

Comments

@Hunknown
Copy link

Hunknown commented Oct 3, 2024

Hi!

First of all, thank you for this awesome package!

I'm currently trying to set up yada for my project, but I'm struggling to make it work for hover menu (similar to this example from dash-mantine-components in Icons, Right Section, and Colors section). I'm not sure how to make the menu appear from a yada step since it requires the mouse to hover the target button...

I've tried to use "action": "hover" on the target button but the menu stays hidden, so I guess this isn't a supported action (I'm not even sure it's something possible at all actually).

I've also tried to make yada target the first button in the hidden menu but yada will just move to top left corner as the button isn't visible without hovering the button (need to set keepMounted=True to the menu object, or yada will just ignore the step as the button wouldn't even exist in the DOM).

Ultimately, I don't know how to do it unless I could send opened=True to the menu object in some way at this step, but for that, I would need a way to identify at which step yada currently is.

@BSd3v
Copy link
Owner

BSd3v commented Oct 3, 2024

Hello @Hunknown,

Thanks for using YADA, mouseover would be a trigger to cause hover I would think, which this isnt currently supported. But if you can get it to work, you are welcome to open a PR.

As far as knowing which step YADA is on, you can look at window.dash_yada.y, however, you will also need to know which script is running and also listen for other button clicks from the offcanvas element. 😄

@Hunknown
Copy link
Author

Hunknown commented Oct 4, 2024

Hello @BSd3v ,

Thank you for your input, it helped me working on a temporary solution for now.

Originally, I wanted to have a callback on next and previous buttons but as they don't have ids, I didn't know how to implement that so I went for an EventListener from dash_extensions on top of the yada component to listen to any click on any yada component:

html.Div(
    children=dext.EventListener(
        YadaAIO(...),
        events=[
            {
                "event": "click",
                "props": ["view.dash_yada.target.id"],
            }
        ],
        id="el",
    ),
    id="div-yada",
),

Then I added a clientside_callback that will trigger on these clicks on yada components:

clientside_callback(
    """
    function(ne, event) {
        if (!ne || !event) return dash_clientside.no_update;
        
        // list of hover components
        hover_comps = ['my-hover-menu']
        if (hover_comps.includes(event['view.dash_yada.target.id'])) {
            window.dash_yada.target.dispatchEvent(e=(document.createEvent('Events')), e.initEvent('mouseover', true, false), e)
        }
        
    }
    """,
    some_dummy_output,
    Input("el", "n_events"),
    Input("el", "event"),
    prevent_initial_call=True,
)

Not the most elegant way to do it, but well, that will do for now.

Note that it will trigger when yada is moving to the target not after moving to next step (contrary to current available actions), but that's what I wanted to achieve anyway.

I'll have to look how to implement it in your code when I'll have some more time to look into it (like building the amended version to test it for example, since I've never done that before).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants