LogoLogo
Enterprise GuideCommunity Edition GuideDeveloper Guide
  • Using The Polarity Developer Guide
  • Quick Start
    • What's New
    • Installing Integrations
    • Quick Start Guide
    • Learning Resources
  • Building an Integration
    • Directory Layout
    • package.json
    • Configuration File
    • Integration Main Module
      • startup
      • doLookup
        • Entity Objects
        • Result Objects
        • Error Objects
      • onDetails
      • onMessage
      • validateOptions
    • Customizing the Overlay Window
      • Templates
        • Conditionals
        • Displaying a List of Items
        • Display Object Properties
        • Built-in Helpers
        • Displaying Icons
      • Component File
        • Aliased Properties
        • Computed Properties
        • Event Hooks
      • CSS Styles
    • Vendor Javascript
      • Inserting Javascript into DOM
    • README Guide
    • Debugging Integrations
      • Web Inspector
      • Using Integration Logs
      • Testing Main Module
  • Recipes
    • Enabling User Actions
    • Throttling Lookups
    • Using Custom Entity Types
    • Custom Summary Tags
    • Creating a Tabbed Interface
    • Accessing Username of Requestor
    • Updating Options
Powered by GitBook
On this page
  1. Recipes

Creating a Tabbed Interface

Quickly setup a tabbed interface within your integration

PreviousCustom Summary TagsNextAccessing Username of Requestor

Last updated 5 years ago

You can implement a tabbed interface within the details block of your integration to better organize information. To start, you will setup the tab structure in your handlebars template. For this example we will create two tabs called Info and Comments.

template.hbs
<ul class="nav nav-tabs">
    <li class="nav-item">
        <a class="nav-link href="#">
            Info
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link href="#">
            Comments
        </a>
    </li>
</ul>

The HTML structure for the tabs makes use of Bootstrap tabs. You can find more information here

Now that our tabs are in place we will need to trigger an action when the tab is clicked. We will trigger an action called changeTab and pass the name of the tab that we want to change to.

template.hbs
<ul class="nav nav-tabs">
    <li class="nav-item">
        <a {{action "changeTab" "info"}} class="nav-link" href="#">
            Info
        </a>
    </li>
    <li class="nav-item">
        <a {{action "changeTab" "comments"}} class="nav-link" href="#">
            Comments
        </a>
    </li>
</ul>

The action itself will be implemented in the actions hash of our component file. The action when called will set a variable called activeTab to the tab that was clicked on. We also initialize the activeTab variable to the name of the tab we want to start as active.

polarity.export = PolarityComponent.extend({
    activeTab: 'info',
    actions: {
        changeTab: function(tabName) {
          this.set('activeTab', tabName);
        }
    }
})

We can now use the activeTab variable in our handlebars template to set the active class on the tab that is currently active.

template.hbs
<ul class="nav nav-tabs">
    <li class="nav-item">
        <a {{action "changeTab" "info"}} class="nav-link {{if (eq activeTab "info") "active"}}" href="#">
            Info
        </a>
    </li>
    <li class="nav-item">
        <a {{action "changeTab" "comments"}} class="nav-link {{if (eq activeTab "comments") "active"}}" href="#">
            Comments
        </a>
    </li>
</ul>

Finally, we use conditionals to only show content when the appropriate tab is active.

template.hbs
{{#if (eq activeTab "info")}}
    <h1>Info</h1>
{{/if}}
{{#if (eq activeTab "comments")}}
    <h1>Comments</h1>
{{/if}}

When the user clicks on the "Info" tab, it triggers the changeTab action which will set the activeTab to the value info. This in turn will show the content within the "Info" conditional block. Likewise, when the user clicks on the "Comments" tab the activeTab value will be set to comments and the "Comments" tab content will be shown.

We're making use of the eq to set the active class when the activeTab variable is equal to our tab name.

https://getbootstrap.com/docs/4.1/components/navs/#tabs
truth helper