I have a razor page where I am displaying the list of selected items from a dropdown menu in a div tag. How can I get @FormattedText auto wrap if the list of items selected exceeds the size of the div.
I tried to apply word-wrap and white-space styles and neither of them worked. The content extends beyond the and the scroll bars are displayed. How can I wrap the content within the ? Thanks for any suggestions!
<style>
.dropdown {
word-wrap: normal;
white-space: normal;
}
</style>
<div class="form-control col-md-4 dropdown dropdown-toggle">
@FormattedText
<div class="dropdown-menu">
@foreach (var item in Items)
{
<div>
<input type="checkbox" @bind="item.IsUpdated" />
<label for="@item.Name">@item.Name</label>
</div>
}
</div>
</div>
List<string> selectedItems = new List<string>();
public string FormattedText
{
get
{
selectedItems.Clear();
selectedItems.AddRange(Items.Where(s => s.IsUpdated).Select( item => { return item.Name; }));
if (selectedItems.Any())
{
return string.Join(",", selectedItems.ToArray());
}
}
set
{
selectedText = value;
}
}
First of all, your Bootstrap
.dropdownstructure is not correct. If you look at their examples,.dropdown-togglerand.dropdown-menuneed to be the same level, wrapped by.dropdown. Also each item in.dropdown-menuneeds to have.dropdown-itemclass as well.So you need to change the structure to:
It will look something like this:
The reason why the formatted text, wrapped in the button, is not wrapping is because
.dropdown-togglerhas stylewhite-space: nowrap;. You can get rid of that style or use Bootstrap utility class.text-wrapon the.dropdown-togglerLastly the dropdown is out of the
.form-control's border. That's because.form-controlhas a fixed height. You can set its height style to auto, or use Bootstrap utility class.h-auto:Now the whole thing looks like this:
demo: https://jsfiddle.net/davidliang2008/3bykc4rf/14/