# @material/tab-scroller

> The Material Components for the web tab scroller component

Latest version **14.0.0** (published 2022-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @material/tab-scroller
pnpm add @material/tab-scroller
yarn add @material/tab-scroller
bun add @material/tab-scroller
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities; popular repo.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 14.0.0 |
| Published | 2022-04-28 |
| First published | 2018-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 319.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17051 |
| Maintainers | yefim, abhiomkar, azakus, bicknellr, material-admin, aprigogin, patrickrodee, aomarks, emarquez, allanchen, esgonzalez, asyncliz, candysonya, ssuarez, taylorv |
| Keywords | material components, material design, tab, scroller |

## Links

- npm: https://www.npmjs.com/package/@material/tab-scroller
- Repository: https://github.com/material-components/material-components-web
- Homepage: https://github.com/material-components/material-components-web#readme
- Issues: https://github.com/material-components/material-components-web/issues
- npm.io page: https://npm.io/package/@material/tab-scroller

## Dependencies (6)

- [tslib](https://npm.io/package/tslib.md) ^2.1.0
- [@material/dom](https://npm.io/package/@material/dom.md) ^14.0.0
- [@material/tab](https://npm.io/package/@material/tab.md) ^14.0.0
- [@material/base](https://npm.io/package/@material/base.md) ^14.0.0
- [@material/animation](https://npm.io/package/@material/animation.md) ^14.0.0
- [@material/feature-targeting](https://npm.io/package/@material/feature-targeting.md) ^14.0.0

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 14.0.0 (latest) — 2022-04-28
- 15.0.0-canary.423edc3dc.0 (canary) — 2024-06-26
- 12.0.0-nightly.778a0e8a.0 (nightly) — 2021-07-20
- 4.0.0-alpha.0 (next) — 2019-08-07
- 15.0.0-canary.cfec83c74.0 — 2024-05-20
- 15.0.0-canary.2f5b899bc.0 — 2024-05-20
- 15.0.0-canary.f80ac92b0.0 — 2024-05-02
- 15.0.0-canary.4b35cb7d0.0 — 2024-05-02
- 15.0.0-canary.65c10a622.0 — 2024-04-25
- 15.0.0-canary.311f29a60.0 — 2024-04-23
- 15.0.0-canary.5bebc0064.0 — 2024-04-11
- 15.0.0-canary.68edc03c6.0 — 2024-04-08
- 15.0.0-canary.453a6248a.0 — 2024-03-25
- 15.0.0-canary.819498d8c.0 — 2024-03-15
- 15.0.0-canary.c43b3438b.0 — 2024-02-23
- … 1639 more at https://npm.io/package/@material/tab-scroller/versions

## README

<!--docs:
title: "Tab Scroller"
layout: detail
section: components
excerpt: "Allows for smooth native and animated scrolling of tabs."
iconId: tabs
path: /catalog/tabs/scroller/
-->

# Tab Scroller

A Tab Scroller allows for smooth native and animated scrolling of tabs.

## Design & API Documentation

<ul class="icon-list">
  <li class="icon-list-item icon-list-item--spec">
    <a href="https://material.io/go/design-tabs#scrollable-tabs">Material Design guidelines: Scrollable Tabs</a>
  </li>
  <li class="icon-list-item icon-list-item--link">
    <a href="https://material-components.github.io/material-components-web-catalog/#/component/tabs">Demo</a>
  </li>
</ul>

## Installation

```
npm install @material/tab-scroller
```

## Basic Usage

### HTML Structure

```html
<div class="mdc-tab-scroller">
  <div class="mdc-tab-scroller__scroll-area">
    <div class="mdc-tab-scroller__scroll-content"></div>
  </div>
</div>
```

### Styles

```scss
@use "@material/tab-scroller/mdc-tab-scroller";
```

### JavaScript Instantiation

```js
import {MDCTabScroller} from '@material/tab-scroller';

const tabScroller = new MDCTabScroller(document.querySelector('.mdc-tab-scroller'));
```

> See [Importing the JS component](../../docs/importing-js.md) for more information on how to import JavaScript.

## Style Customization

### CSS Classes

CSS Class | Description
--- | ---
`mdc-tab-scroller` | Mandatory. Contains the tab scroller content.
`mdc-tab-scroller__scroll-area` | Mandatory. Denotes the scrolling area.
`mdc-tab-scroller__scroll-content` | Mandatory. Denotes the scrolling content.
`mdc-tab-scroller--align-start` | Optional. Sets the elements inside the scroll content element to be aligned to the start of the scroll content element.
`mdc-tab-scroller--align-end` | Optional. Sets the elements inside the scroll content element to be aligned to the end of the scroll content element.
`mdc-tab-scroller--align-center` | Optional. Sets the elements inside the scroll content element to be aligned to the center of the scroll content element.

> _NOTE_: The `align` modifier classes are only applicable when the contents do not meet or exceed the width of the Tab Scroller and Tab Bar (i.e., most commonly, when `mdc-tab--min-width` is used on each tab).

### Sass Mixins

Mixin | Description
--- | ---
`transition($duration-ms, $timing-function)` | Sets the scroll animation duration and, optionally, the timing function.

## `MDCTabScroller` Methods

Method Signature | Description
--- | ---
`scrollTo(scrollX: number) => void` | Scrolls to the scrollX value.
`incrementScroll(scrollX: number) => void` | Increments the current scroll value by the scrollX value using animation.
`incrementScrollImmediate(scrollX: number) => void` | Increments the current scroll value by the scrollX value without animation.
`getScrollPosition() => number` | Returns the current visual scroll position.
`getScrollContentWidth() => number` | Returns the width of the scroll content element.

## Usage within Web Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Tab Scroller for your framework. Depending on your needs, you can use the _Simple Approach: Wrapping MDC Web Vanilla Components_, or the _Advanced Approach: Using Foundations and Adapters_. Please follow the instructions [here](../../docs/integrating-into-frameworks.md).

### `MDCTabScrollerAdapter`

Method Signature | Description
--- | ---
`eventTargetMatchesSelector(eventTarget: EventTarget, selector: string) => boolean` | Returns `true` if the given event target satisfies the given CSS selector.
`addClass(className: string) => void` | Adds a class to the root element.
`addScrollAreaClass(className: string) => void` | Adds a class to the scroll area element.
`removeClass(className: string) => void` | Removes a class from the root element.
`setScrollAreaStyleProperty(property: string, value: string) => void` | Sets the given style property on the scroll area element.
`setScrollContentStyleProperty(property: string, value: string) => void` | Sets the given style property on the scroll content element.
`getScrollContentStyleValue(property: string) => string` | Returns the given style property value on the scroll content element.
`setScrollAreaScrollLeft(scrollLeft: number) => void` | Sets the scroll area element's `scrollLeft`.
`getScrollAreaScrollLeft() => number` | Returns the scroll area element's `scrollLeft`.
`getScrollContentOffsetWidth() => number` | Returns the scroll content element's `offsetWidth`.
`getScrollAreaOffsetWidth() => number` | Returns the scroll area element's `offsetWidth`.
`computeScrollAreaClientRect() => ClientRect` | Returns the bounding client rect of the scroll area element.
`computeScrollContentClientRect() => ClientRect` | Returns the bounding client rect of the scroll content element.
`computeHorizontalScrollbarHeight() => number` | Returns the height of the browser's horizontal scrollbars (in px).

#### `util` Functions

MDC Tab Scroller provides a `util` module with functions to help implement adapter methods.

Function Signature | Description
--- | ---
`computeHorizontalScrollbarHeight(document: Document) => number` | Returns the height of the browser's horizontal scrollbars (in px).

### `MDCTabScrollerFoundation`

Method Signature | Description
--- | ---
`getRTLScroller() => MDCTabScrollerRTL` | Creates an RTL Scroller instance for the current browser.
`getScrollPosition() => number` | Returns the current visual scroll position.
`handleInteraction() => void` | Responds to mouse, pointer, touch, and keyboard events.
`handleTransitionEnd(evt: Event) => void` | Responds to a `transitionend` event on the `mdc-tab-scroller__scroll-content` element.
`incrementScroll(scrollX: number) => void` | Increments the current scroll value by the `scrollX` value.
`scrollTo(scrollX: number) => void` | Scrolls to the `scrollX` value.

### `MDCTabScrollerRTL`

Abstract class with three concrete implementations depending on the browser:

* `MDCTabScrollerRTLDefault`
* `MDCTabScrollerRTLNegative`
* `MDCTabScrollerRTLReverse`

Method Signature | Description
--- | ---
`getAnimatingScrollPosition(scrollX: number, translateX: number) => number` | Returns the current scroll position during animation.
`getScrollPositionRTL(translateX: number) => number` | Returns the number of px the user has scrolled horizontally, relative to the leading edge.
`incrementScrollRTL(scrollX: number) => MDCTabScrollerAnimation` | Returns an object containing the values required to animate from the current scroll position to a new scroll position.
`scrollToRTL(scrollX: number) => MDCTabScrollerAnimation` | Scrolls content horizontally to the given position in an RTL-friendly way.

---
_Source: https://npm.io/package/@material/tab-scroller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
