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

Clicked not working as expected for Button of type Link. #2057

Closed
polonskyg opened this issue Mar 18, 2021 · 4 comments
Closed

Clicked not working as expected for Button of type Link. #2057

polonskyg opened this issue Mar 18, 2021 · 4 comments
Labels
Type: Feature ⚙ Request or idea for a new feature.
Milestone

Comments

@polonskyg
Copy link

polonskyg commented Mar 18, 2021

Describe the bug
I have a Button (ButtonType.Link) inside a Bar.
The Bar has set Visible="@IsVisible"
Then the button has Clicked="ToggleBar" and that method changes the value of IsVisible (a property in the component) which is not doing anything (the Bar should hide, but if I use @OnClick="ToggleBar" in the button (and keep everything else the same, it works and the bar hides.

To Reproduce
Removing some parts for brevity

@using BlazorPro.Spinkit
@inject NavigationManager NavigationManager

<Bar Mode="BarMode.VerticalInline"
     Breakpoint="Breakpoint.Desktop"
     Background="Blazorise.Background.White"
     Visible="@(IsVisible)">
     @*data-collapse="@(IsVisible ? "" :"hide")">*@
    <BarMenu>
        <BarStart>
            <Tabs @bind-SelectedTab="CurrentTab">
                <Items>
                    <Tab Name="Items">@Localizer.Text("title")</Tab>
                </Items>
                <Content>
                    <TabPanel Name="Items">
                        <div style="position:absolute; width:100%;">
                                <Button Type="ButtonType.Link" To="item" @onclick="ToggleBar" Style="position: relative;">
                                    <Icon Name="IconName.Add" />
                                    @Localizer.Text("Add")
                                </Button>
                        </div>
                    </TabPanel>
                </Content>
            </Tabs>
        </BarStart>
    </BarMenu>
</Bar>

@code
{
    private bool IsVisible = false;

    public void ToggleBar()
    {
        IsVisible = !IsVisible;
        StateHasChanged();
    }
}

Expected behavior
When the Add button (link) is clicked the Bar should collapse (hide) and when is clicked again, the bar should be shown.
It was working with Clicked and data-collapsed (commented above) in version 0.9.2.5, but after upgrading to the version 0.9.3.1 is stopped working and I had to use, in the button, @OnClick="ToggleBar" instead of Clicked. The problem with this approach is that the hiding is very slow, like if it has a delay.

@stsrki
Copy link
Collaborator

stsrki commented Mar 18, 2021

You almost got it. Just need to use two-way binding for Visible parameter.

<Bar Mode="BarMode.VerticalInline"
        Breakpoint="Breakpoint.Desktop"
        Background="Blazorise.Background.White"
+        @bind-Visible="@IsVisible">
    <BarMenu>
        <BarStart>
            <Tabs @bind-SelectedTab="CurrentTab">
                <Items>
                    <Tab Name="Items">items</Tab>
                </Items>
                <Content>
                    <TabPanel Name="Items">
                        <div style="position:absolute; width:100%;">
                            <Button Type="ButtonType.Link" To="tests/buttons" @onclick="@ToggleBar" Style="position: relative;">
                                <Icon Name="IconName.Add" />
                                Add
                            </Button>
                        </div>
                    </TabPanel>
                </Content>
            </Tabs>
        </BarStart>
    </BarMenu>
</Bar>

@code
{
    private bool IsVisible = true;
    string CurrentTab = "Items";
    public Task ToggleBar()
    {
        IsVisible = !IsVisible;

+        return Task.CompletedTask;
    }
}

And you don't need StateHasChanged() in this case.

@polonskyg
Copy link
Author

Well, while that might work, my point is that according to the official documentation in the page I should be using Clicked instead of on-click.
Thx! Guillermo.

@stsrki
Copy link
Collaborator

stsrki commented Mar 18, 2021

Do you mean regarding the @onclick="@ToggleBar"? Yeah, it might not be the best decision to disable Clicked event for link buttons. The same thing was done for the Link component and recently I have enabled Clicked to work. I might do the same for the Button.

@polonskyg
Copy link
Author

polonskyg commented Mar 18, 2021 via email

@stsrki stsrki added the Type: Feature ⚙ Request or idea for a new feature. label Mar 18, 2021
@stsrki stsrki added this to the 0.9.4 milestone Mar 18, 2021
This was referenced Mar 25, 2021
@stsrki stsrki closed this as completed Mar 25, 2021
@stsrki stsrki moved this to ✔ Done in Development Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature ⚙ Request or idea for a new feature.
Projects
Archived in project
Development

No branches or pull requests

2 participants