14.0.0 • Published 5 months ago

@material/tab-scroller v14.0.0

Weekly downloads
36,288
License
MIT
Repository
github
Last release
5 months ago

Tab Scroller

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

Design & API Documentation

Installation

npm install @material/tab-scroller

Basic Usage

HTML Structure

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

Styles

@import "@material/tab/mdc-tab-scroller";

JavaScript Instantiation

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

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

See Importing the JS component for more information on how to import JavaScript.

Style Customization

CSS Classes

CSS ClassDescription
mdc-tab-scrollerMandatory. Contains the tab scroller content.
mdc-tab-scroller__scroll-areaMandatory. Denotes the scrolling area.
mdc-tab-scroller__scroll-contentMandatory. Denotes the scrolling content.
mdc-tab-scroller--align-startOptional. Sets the elements inside the scroll content element to be aligned to the start of the scroll content element.
mdc-tab-scroller--align-endOptional. Sets the elements inside the scroll content element to be aligned to the end of the scroll content element.
mdc-tab-scroller--align-centerOptional. Sets the elements inside the scroll content element to be aligned to the center of the scroll content element.

MDCTabScroller Methods

Method SignatureDescription
scrollTo(scrollX: number) => voidScrolls to the scrollX value.
incrementScroll(scrollX: number) => voidIncrements the current scroll value by the scrollX value.
getScrollPosition() => numberReturns the current visual scroll position.
getScrollContentWidth() => numberReturns 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.

MDCTabScrollerAdapter

Method SignatureDescription
eventTargetMatchesSelector(eventTarget: EventTarget, selector: string) => booleanReturns true if the given event target satisfies the given CSS selector.
addClass(className: string) => voidAdds a class to the root element.
addScrollAreaClass(className: string) => voidAdds a class to the scroll area element.
removeClass(className: string) => voidRemoves a class from the root element.
setScrollAreaStyleProperty(property: string, value: string) => voidSets the given style property on the scroll area element.
setScrollContentStyleProperty(property: string, value: string) => voidSets the given style property on the scroll content element.
getScrollContentStyleValue(property: string) => stringReturns the given style property value on the scroll content element.
setScrollAreaScrollLeft(scrollLeft: number) => voidSets the scroll area element's scrollLeft.
getScrollAreaScrollLeft() => numberReturns the scroll area element's scrollLeft.
getScrollContentOffsetWidth() => numberReturns the scroll content element's offsetWidth.
getScrollAreaOffsetWidth() => numberReturns the scroll area element's offsetWidth.
computeHorizontalScrollbarHeight() => numberReturns 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 SignatureDescription
computeHorizontalScrollbarHeight(document: Document) => numberReturns the height of the browser's horizontal scrollbars (in px).
getMatchesProperty(HTMLElementPrototype: Object) => stringReturns the appropriate property name for the matches API in the current browser environment.

MDCTabScrollerFoundation

Method SignatureDescription
scrollTo(scrollX: number) => voidScrolls to the scrollX value.
incrementScroll(scrollX: number) => voidIncrements the current scroll value by the scrollX value.
getScrollPosition() => numberReturns the current visual scroll position.
14.0.0

3 years ago

13.0.0

3 years ago

12.0.0

3 years ago

11.0.0

4 years ago

10.0.0

4 years ago

9.0.0

4 years ago

8.0.0

4 years ago

7.0.0

4 years ago

6.0.0

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.0.0

5 years ago

3.2.0

5 years ago

4.0.0-canary.1

5 years ago

4.0.0-canary.0

5 years ago

4.0.0-alpha.0

5 years ago

3.1.0

5 years ago

3.1.0-alpha.0

5 years ago

3.0.0

5 years ago

3.0.0-alpha.1

5 years ago

3.0.0-alpha.0

5 years ago

2.3.0

5 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-1

6 years ago

1.0.0-0

6 years ago

0.44.1

6 years ago

0.44.0

6 years ago

0.43.1

6 years ago

0.43.0

6 years ago

0.42.0

6 years ago

0.41.0

6 years ago

0.40.1

6 years ago

0.40.0

6 years ago

0.39.3

6 years ago

0.39.2

6 years ago

0.39.1

6 years ago

0.39.0

6 years ago

0.39.0-0

6 years ago

0.38.1

6 years ago

0.38.0

6 years ago