Responsive horizontal tab bar using bootstrap and blazor for a seamless user experience

For my blazor tab control, I need the horizontal tab bar to be responsive when there are numerous tabs. Despite using tc-tabs, the scrollbar does not appear and it forces additional tabs to display on a new line.

https://i.sstatic.net/QTrn7.png

I am interested in exploring two potential solutions: - One that utilizes a scrollbar for overflow handling. - Another option where overflow is managed with arrow buttons located at each end of the tab bar (potentially implemented using razor functionalities).

In addition, I am working on fixing the close button placement at the top right corner of each tab, particularly when the tab name is lengthy.

Edit (Resolved close button alignment + text overflow within tab):

Despite making progress with aligning the close button, I continue to face challenges implementing the scrollbar solution as discussed in this post: Bootstrap horizontal scrollable tab bar

<ul class="nav nav-tabs tc-tabs">
    @foreach (Tab tabItem in ItemsSource) {
        <li class="tc-tab @(SelectedItem == tabItem ? "tc-tab-active" : string.Empty)">
            <div @onclick="@(() => ActivatePage(tabItem))">
                <span class="tc-tab-title @(SelectedItem == tabItem ? "active" : string.Empty)">
                    @tabItem.Title
                </span>
            </div>
            <button class="close tc-tab-close" type="button" aria-label="Close" @onclick="@(() => DeletePage(tabItem))">
                <span aria-hidden="true">&times;</span>
            </button>
        </li>
    }
</ul>

CSS:

tc-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    display: -webkit-box;
}

.tc-tab {
    width: 200px;
    position: relative;
    padding: 5px;
    float: none;
}

.tc-tab-active {
    background-color: darkgray;
    color: white;
}

.tc-tab-title {
    width: 85%;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    position: absolute;
}

.tc-tab-close {
    width: 10%;
}

Answer №1

While not a comprehensive solution, the following method is operational. I implemented it as a guide for creating a Horizontal Tab Bar:

  • Create a single tab with a Tab Component
  • Create a TabBar component to hold multiple tab objects and manipulate them as needed

Each tab includes a close button that will deactivate the tab when clicked.

Tab.razor

<li style="height:auto; width:inherit; padding:5px; border: 1px solid blue; text-align:right;">
    <span style="float: left">@Title</span>
    <a href="#" @onclick="@(() => Close.InvokeAsync(ID))" role="button">X</a>

</li>
 <div style="padding:0px; ">@ChildContent</div> 


 @code {
  [Parameter]
  public int ID { get; set; }
  [Parameter]
   public string Title { get; set; }

  [Parameter]
  public RenderFragment ChildContent { get; set; }

  [Parameter]
  public EventCallback <int> Close {get; set;}
}

TabBar.razor

<ul class="nav nav-tabs tb-tabs">
<li><a href="#" @onclick="@GoForward" role="button">--></a></li>
@foreach (var tab in tabs)
{
    <Tab ID="@tab.ID" Title="@tab.Title" Close="@Close"></Tab>

}

<li><a href="#" @onclick="@GoBackward" role="button">&lt;--</a></li>
</ul>

@code {
// Add functionality for forward movement
private void GoForward()
{

}

// Add functionality for backward movement
private void GoBackward()
{

}

List<NavTab> tabs = new List<NavTab>
    {
        new NavTab{ ID = 1, Title = "Long Name Example 1"},
        new NavTab{ ID = 2, Title = "Small" },
        new NavTab{ ID = 3, Title = "Long Name Example 2" }
   };

private void Close(int ID)
{
    RemoveNavTab(ID);

}

public void RemoveNavTab(int ID)
{

    tabs.Remove(tabs.Where(alert => alert.ID == ID).FirstOrDefault());
    StateHasChanged();
}

public class NavTab
{
    public int ID { get; set; }
    public string Title { get; set; }


}

}

Add the following code to the MainLayout before the "About" anchor element:

<div>
   <TabBar />
</div>

Test the code once you run your app...

Note: I've provided an outline, now it's up to you to enhance it with required features. Utilize FlexBox for CSS tab management, implement logic to determine displayed text size, etc.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Save information in a session using html and javascript

I'm having trouble accessing a session variable in my javascript code. I attempted to retrieve it directly but ran into issues. As an alternative, I tried storing the value in a hidden HTML input element, but I am unsure of how to properly do that wit ...

Targeting child elements with CSS selectors

In my ecommerce software, I have a menu that I want to customize by making the main categories bold. I have attempted various methods, including the ones shown below, but I am struggling to target the correct elements (specifically those in capital letter ...

Automatically close an element when you click on a different element

Hello everyone! I need some help again. I'm working on a script that displays an overlay when a menu item is clicked. Within this menu, there is a modal contact form with a close icon or anchor that should appear when clicked. My goal is to have the o ...

Interactive JavaScript Linkage

Recently, I came across some code that I inherited (definitely not mine!) which uses a session variable in the HTML header to link to a specific javascript file. For example: <SCRIPT language="javascript" src="../JavaScript/<%=Session("jsFileName") ...

How to Handle Empty Input Data in JQuery Serialization

Having an issue with a form that triggers a modal window containing another form when a button is clicked. The second form includes an input field and send/cancel buttons. The goal is to serialize the data from the modal form and send it to a server using ...

Gif stubbornly refusing to fade out even after the .fadeOut command is called

Having trouble making a gif fade out after the page loads? Here's my attempt so far: I want the overlay, which includes a white background and the gif, to gradually become transparent once the rest of the page is fully loaded. Take a look at the fol ...

Tips for converting multiple arrays of objects into a single array set

Here is an example of an array: $scope.array1=[[Name:'Madhu'],[Name:'Vijay'],[Name:'Srinu']] I need to convert this array into a different format. I want to pass this array in the columns option of a dx datagrid. So the desi ...

Problem encountered in Firefox using Selenium: Invalid expression SyntaxError when dealing with Div tags in XPath

I encountered an error while attempting to automate a sample Qlikview web report using Selenium Browser: Firefox Xpath returned by FirePath: .//*[@id='58']/div[2]/div/div[1]/div[4]/div[1] Exception: **Exception**: Exception in thread "main ...

pull information from mongodb into angular

I am attempting to retrieve data from MongoDB, but I keep seeing [object] [object]. How can I transfer array data from MongoDB to Angular? Here is the code snippet: import { Component, OnInit } from '@angular/core'; import {HttpClient} from &quo ...

IE Flash overlay is causing compatibility issues with the website

I'm working on a website that has a flash player embedded, and I'm trying to add an overlay that can display HTML content. The plan is to have the flash element fade out to 0.5 opacity before showing the HTML text. It works perfectly in Google Ch ...

Having trouble getting ASPJAX to function properly

I'm looking to create a demo showcasing the combination of ASP and AJAX. I came across some code snippets from http://www.aspjax.com that I've incorporated into my project. However, I'm having trouble displaying the expected text. Here is t ...

Show the Table and Conceal the Overflow

Currently, I am experimenting with creating an Img hover for entertainment purposes. However, I have added some text to my div. In order to center the text beautifully within my div, I utilized the following CSS code: display: table-cell; vertical-align: ...

Why are my div elements mysteriously adding bottom margin?

I've encountered an unexpected margin bottom issue while working on some HTML and Bootstrap code. No matter how I try to set the div margin to 0 in a separate stylesheet, like this: body { margin: 0; } div { margin-bottom: 0; } The problem persi ...

I am looking for a way to access the currentTime property of a FlowPlayer object in HTML5, similar to the "timeupdate" event. Can anyone help me find an equivalent method?

$("video").on('timeupdate', function() { console.log(this.currentTime); }); Is there a way to display the currentTime of a flowPlayer object using JavaScript? ...

Can we relocate the captions in colorbox to the top of the box?

Currently, my project utilizes colorbox for opening modal windows. There are 5 different styles available for colorbox, and I have chosen to implement Example 5, which can be viewed at this URL: I am looking to customize the layout of colorbox.js's ...

What is the best way to vertically align text that is positioned absolutely in the center?

I'm looking to implement a hover hide effect. Check out my inspiration on CodePen * { box-sizing: border-box; margin: 0; padding: 0; } body { background-color: #123456; } #object { background-color: cornsilk; border: #333 3px solid; ...

Guide on how to apply an image map within a specific area of a background image

I have experience setting image maps for foreground images, but this time I need to set an image map for a specific area of an image that is used as the background image of a div. I have searched extensively online for a solution but have come up empty-han ...

Having trouble integrating Stratus 2 Beta with the HTML code of a website

My task was to incorporate Stratus 2 Beta into our website for music streaming. Although the Stratus website makes it appear simple to add their code to the HTML, I have been facing difficulties in getting it to function properly. Here is the code I have ...

What is the easiest method to stop text from wrapping around an icon within a bulleted list?

Imagine having rows filled with various icons, each one being quite large. <li><i class="bi bi-patch-check-fill icon-green" style="font-size:40px;"></I>Some text about whatever</li> <li><i class="b ...

A PHP function with multiple parameters

I am currently in the process of updating a row on Parse using PHP and have created the following function: if (isset($_GET['updateHistory'])) { updateHistory($_GET['updateHistory']); } if (isset($_GET['ye ...