npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ngheadlessui/tabs

v0.0.3

Published

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

Downloads

4

Readme

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.

| Props | Default | Description | | ------------ | ------- | -------------------------------------------------------------------------------- | | defaultIndex | 0 | Number The default selected index | | (changeTab) | | EventEmitter This is fired when there is a change in selected tab |

headless-tab

The Tab component.

| Props | Default | Description | | -------- | ------- | ------------------------------------------------------------- | | disabled | false | Boolean Whether or not the Tab is currently disabled. |

headlessTabPanel

The Tab component.

| Props | Default | Description | | ----- | --------- | ----------------------------------------------------- | | id | undefined | String unique identifier of the tab component |