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

Pass boolean value to draggable attribute #60137

Open
1 task done
bonsall opened this issue Jan 31, 2025 · 0 comments
Open
1 task done

Pass boolean value to draggable attribute #60137

bonsall opened this issue Jan 31, 2025 · 0 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@bonsall
Copy link

bonsall commented Jan 31, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

In blazor, when you add the draggable attribute using a boolean value, it produces markup with just the text draggable. For example

<div draggable="@MyBool">Am I really draggable</div>

@code {
    public bool MyBool { get; set }
}

Will produce this output <div draggable>Am I really draggable</div>.

This causes problems in browsers (such as chrome) as they seem to require a value for the draggable attribute, true or false. With the output blazor produces in this situation the browser sometimes allows for dragging and other times does not. It's not clear to me exactly how the browser is behaving but it is spotty and broken at best.

Describe the solution you'd like

for this particular attribute I would like blazor to output the true or false value as the attribute value. For example:

<div draggable="@false">I am not draggable</div>
<div draggable="@true">I am draggable</div>

would produce this markup

<div draggable="false">I am not draggable</div>
<div draggable="true">I am draggable</div>

Additional context

You can work around this behavior by calling .ToString() on your bool, and the current behavior is the documented and expected behavior of blazor. However; if a dev makes the mistake of setting the draggable attribute to a bool value (like my colleague did) it is not clear why the drag/drop functionality is broken and hours can be wasted trying to solve the issue.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

1 participant