Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ngheadlessui/tabs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngheadlessui/tabs

Easily create accessible, fully customizable tab interfaces, with robust focus management and coming keyboard navigation support.

  • 0.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ui-tabs

Easily create accessible, fully customizable tab interfaces, with robust focus management and coming keyboard navigation support.

Demo


Installation

# npm
npm install @ngheadlessui/tabs

# Yarn
yarn add @ngheadlessui/tabs

# import the lib into module you want to use it in
import { UiTabsModule } from '@ngheadlessui/tabs';

Basic Example

Tabs are built using the headless-tab-group, headless-tab, and headlessTabPanel components. By default the first tab is selected, and clicking on any tab will activate the corresponding panel.

<headless-tab-group>
  <div>
    <headless-tab>Tab 1</headless-tab>
    <headless-tab>Tab 2</headless-tab>
    <headless-tab>Tab 3</headless-tab>
  </div>

  <!-- You can use the headlessTabPanel as a component -->
  <headlessTabPanel>Content 1</headlessTabPanel>
  <headlessTabPanel>Content 2</headlessTabPanel>
  <headlessTabPanel>Content 3</headlessTabPanel>

  <!--or as a directive
    <div headlessTabPanel>Content 1</div>
    <div headlessTabPanel>Content 2</div>
    <div headlessTabPanel>Content 3</div>
  -->
</headless-tab-group>

Styling the selected tab

This is a headless component so there are no styles included by default. Instead, the components expose useful information via bound classes that you can use to apply styles yourself.

To style the selected Tab, use the selected class selected-headless-tab, which tells you whether or not that tab is currently selected. For flexiblity, the clas unselected-headless-tab is also available for use.

.selected-headless-tab {
  @apply bg-white shadow;
}
.unselected-headless-tab {
  @apply text-blue-100 hover:bg-white/[0.12] hover:text-white;
}

Disabling a tab

To disable a tab, use the disabled input property on the headlessTabPanel component. Disabled tabs cannot be selected with the mouse.

<headless-tab-group>
  <div>
    <headless-tab [disabled]="true">Tab 1</headless-tab>
    <headless-tab>Tab 2</headless-tab>
    <headless-tab>Tab 3</headless-tab>
  </div>

  <headlessTabPanel>Content 1</headlessTabPanel>
  <headlessTabPanel>Content 2</headlessTabPanel>
  <headlessTabPanel>Content 3</headlessTabPanel>
</headless-tab-group>

<!-- If you are creating tabs from component data  -->
<headless-tab-group>
  <div>
    <headless-tab
      *ngFor="let tabName of ['Recent', 'Popular', 'Trending']"
      [disabled]="tabName === 'Recent'"
    >
      {{ tabName }}
    </headless-tab>
  </div>

  <headlessTabPanel>Content 1</headlessTabPanel>
  <headlessTabPanel>Content 2</headlessTabPanel>
  <headlessTabPanel>Content 3</headlessTabPanel>
</headless-tab-group>

To style disabled tabs, use the disabled class disabled-headless-tab, which tells you whether or not that tab is currently disabled.

.disabled-headless-tab {
  @apply text-red-300 bg-yellow-700 hover:bg-white/[0.12] hover:text-white;
}

Specifying the default tab

To change which tab is selected by default, use the defaultTabIndex="number" property on the TabGroup component.

<headless-tab-group [defaultTabIndex]="2">
  <div>
    <headless-tab>Tab 1</headless-tab>
    <headless-tab>Tab 2</headless-tab>
    <headless-tab>Tab 3</headless-tab>
  </div>

  <headlessTabPanel>Content 1</headlessTabPanel>
  <headlessTabPanel>Content 2</headlessTabPanel>
  <headlessTabPanel>Content 3</headlessTabPanel>
</headless-tab-group>

Listening for changes

To run a function whenever the selected tab changes, listen to emissions from the (changeTab) EventEmitter on the TabGroup component. (changeTab) emits the index ($event) of the active tab.

<headless-tab-group (changeTab)="listenToChangeInTabs($event)">
  <div>
    <headless-tab>Tab 1</headless-tab>
    <headless-tab>Tab 2</headless-tab>
    <headless-tab>Tab 3</headless-tab>
  </div>

  <headlessTabPanel>Content 1</headlessTabPanel>
  <headlessTabPanel>Content 2</headlessTabPanel>
  <headlessTabPanel>Content 3</headlessTabPanel>
</headless-tab-group>

Component APIs

headless-tab-group

The main TabGroup component.

PropsDefaultDescription
defaultIndex0Number
The default selected index
(changeTab)EventEmitter
This is fired when there is a change in selected tab

headless-tab

The Tab component.

PropsDefaultDescription
disabledfalseBoolean
Whether or not the Tab is currently disabled.

headlessTabPanel

The Tab component.

PropsDefaultDescription
idundefinedString
unique identifier of the tab component

FAQs

Package last updated on 28 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc