daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

Make TextContent take an IHtmlString instead of a string #54

Open gulsharan opened 8 years ago

gulsharan commented 8 years ago

Is it possible to have navbar dropdown label allow HTML instead of plain text? I need to add an icon to the left of the caret, sort of like user icon in the image below.

dropdown_with_icon

daveaglick commented 8 years ago

Try passing in new HtmlString("<foo>...</foo>") where you would normally pass in the content. Does that help? If not, care to post an example so I can take a closer look?

gulsharan commented 8 years ago

Sorry for posting an incomplete code earlier. I've updated the code below:

NavbarNav.DropDown() takes a string, so passing an HtmlString does not work. Here's the code I'm using.

@using(var navbar = Html.Bootstrap().Navbar().Begin())
{
    using(var nav = navbar.NavbarNav().Begin())
    {
        using(var dropdown = nav.DropDown("Text Label").Begin())
        {
            ...
        }
    }
}
gulsharan commented 8 years ago

@daveaglick Did you get a chance to look at this?

daveaglick commented 8 years ago

Haven't quite gotten to it yet. I was on the verge of shipping a new version of another OSS project so that took all my free cycles. I'll try to take a look in the next few days.

gulsharan commented 8 years ago

No rush, I think I can work something out for now. Thanks for this awesome library!

daveaglick commented 8 years ago

I finally had a chance to take a close look at this. Unfortunately, I don't think what you want can be achieved right now.

Most components are really flexible and you can use methods like .Content() or .AddChild() to insert HTML and other elements into them. With navbar dropdowns that also works, but it always inserts stuff inside the dropdown. That's because all the stuff that sets up the dropdown inside the navbar is generated before it starts processing children.

The text in the constructor gets inserted via a TextContent property that all components have. The navbar checks to see if this is set and then adds it inside all the stuff at the top of the dropdown. Right now, this TextContent property is just a string and it automatically gets escaped. To make something like what you have in mind work, we would probably to somehow indicate whether this property should be escaped when used (maybe by changing to an object and then allowing it to take IHtmlString or something). That would be a pretty major change since this property is used in lots of components.

Which brings us to: I just don't see having the time to tackle it at the moment. While I still fix bugs and answer questions about this project, it's currently in "maintenance mode" while I shift attention to other projects. I plan to revisit it at some point, but not right now. Sorry!

daveaglick commented 8 years ago

I'll leave this issue open as a reminder to revisit later.

gulsharan commented 8 years ago

@daveaglick Thanks for a detailed response. Not an issue, I understand you're quite busy. I'll play around with it in a fork. If I ever get it to work, I'll send a PR your way for you to review.

Once again, thanks for the awesomeness!