Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(tab-bar): Add tab bar #3229

Merged
merged 59 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c6076e1
feat(ripple): Call layout on each activation (#2567)
kfranqueiro Apr 16, 2018
5ba7e27
chore(dialog): Remove ripple layout & layoutFooterRipples adapter API…
kfranqueiro Apr 16, 2018
68c08f7
fix(select): Float label on focus/blur (#2560)
Apr 16, 2018
afd9e11
chore(text-field): Remove layout calls from text field (#2569)
kfranqueiro Apr 16, 2018
40c11ae
chore(package): update google-closure-compiler to version 20180402.0.…
acdvorak Apr 16, 2018
60c0204
docs(auto-init): Clarify "component's class name" (#2576)
acdvorak Apr 17, 2018
30710a4
fix(checkbox): Implement component/adapter APIs to sync aria-checked …
kfranqueiro Apr 17, 2018
6f97632
docs(button): Add aria-hidden="true" to icon elements (#2582)
kfranqueiro Apr 17, 2018
e6e05b7
docs(text-field): Add aria-describedby referencing helper text (#2581)
kfranqueiro Apr 17, 2018
099fdf8
docs(dialog): Remove mention of layoutFooterRipples adapter API (#2586)
kfranqueiro Apr 18, 2018
f71d905
fix(select): Override floating label properties in select box (#2574)
williamernest Apr 18, 2018
3d16d78
WIP start of tab bar
patrickrodee Apr 19, 2018
ef3d946
feat(tab-bar): Add tab bar
patrickrodee Apr 30, 2018
af9b0fc
feat(tab-bar): First commit
patrickrodee Jul 17, 2018
93a5bc5
feat(tab-bar): Create tab bar
patrickrodee Jul 18, 2018
8bcad80
feat(tab-bar): Basic usecase is working
patrickrodee Jul 19, 2018
5fc6332
feat(tab-bar): Basic LTR scrolling and navigation works
patrickrodee Jul 20, 2018
c9d25e8
feat(tab-bar): Re-order activateTab functions
patrickrodee Jul 21, 2018
5072399
Merge branch 'feat/tabs/tabs' into feat/tabs/tab-bar1
patrickrodee Jul 23, 2018
5d8dd7d
feat(tab-bar): RTL TAB BAR IS WORKING ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨
patrickrodee Jul 24, 2018
106ed74
feat(tab-bar): Renamed rtl keyboard navigation handler
patrickrodee Jul 24, 2018
84e5ae8
Merge feat/tabs/tabs
patrickrodee Jul 24, 2018
5505f98
feat(tab-bar): Refactored scrollIntoView logic
patrickrodee Jul 24, 2018
8cb0642
feat(tab-bar): Progress on tests
patrickrodee Jul 25, 2018
e0401f5
feat(tab-bar): Finished tests; updated tab and tab scroller styles
patrickrodee Jul 25, 2018
afe5938
feat(tab-bar): Update scroller tests
patrickrodee Jul 25, 2018
376ae15
Merge branch 'feat/tabs/tabs' into feat/tabs/tab-bar1
patrickrodee Jul 25, 2018
b70fb62
Merge branch 'feat/tabs/tabs' into feat/tabs/tab-bar1
patrickrodee Jul 26, 2018
0f1030b
fix(tab): Clean up duplicate rules
patrickrodee Jul 26, 2018
26e6fee
fix(tab-bar): Clean-up unnecessary changes
patrickrodee Jul 26, 2018
f4e9e00
feat(tab-bar): Add readme
patrickrodee Jul 26, 2018
6153d62
feat(tab-bar): Added annotations
patrickrodee Jul 26, 2018
84af175
fix(tab-bar): Fix keyboard navigation for keyCode browsers
patrickrodee Jul 26, 2018
2067704
Merge branch 'feat/tabs/tabs' into feat/tabs/tab-bar1
patrickrodee Jul 26, 2018
2a84535
feat(tab-bar): Update from feedback
patrickrodee Jul 26, 2018
a0cd324
fix(tab-bar): Update tests to pass
patrickrodee Jul 26, 2018
74c0c8a
fix(tab-bar): Manually initialize ACCEPTABLE_KEYS and KEYCODE_MAP
patrickrodee Jul 26, 2018
87925f6
feat(tab-bar): Emit event when a tab is activated
patrickrodee Jul 26, 2018
7ee952e
Merge branch 'feat/tabs/tabs' into feat/tabs/tab-bar1
patrickrodee Jul 26, 2018
f121fa6
Merge branch 'feat/tabs/tab-bar1' of github.com:material-components/m…
patrickrodee Jul 26, 2018
ea11d8f
feat(tab-bar): Emit event when tab is activated
patrickrodee Jul 26, 2018
1a98d7c
Merge branch 'feat/tabs/tabs' into feat/tabs/tab-bar1
patrickrodee Jul 26, 2018
d1857c6
Merge feat/tabs/tabs
patrickrodee Jul 26, 2018
f769977
feat(tab-bar): Add mixin; FInalize demo; Update readme
patrickrodee Jul 27, 2018
1edecd0
fix(tab-bar): Update autoinit names from review
patrickrodee Jul 27, 2018
8cbcfc7
WIP
patrickrodee Jul 27, 2018
da10d84
feat(tab-bar): Debugging failing iOS test
patrickrodee Jul 27, 2018
9bf7b60
fix(tab-bar): Hacking on iOS
patrickrodee Jul 27, 2018
1f016cd
WIP
patrickrodee Jul 27, 2018
0e23d78
WIP remove debugger
patrickrodee Jul 27, 2018
5975ae9
WIP
patrickrodee Jul 27, 2018
f3174f1
WIP remove clock cleanup from other tests
patrickrodee Jul 27, 2018
b933372
WIP test loosening
patrickrodee Jul 27, 2018
5fe2fbd
WIP README fixes
Jul 27, 2018
8d15570
feat(tab-bar): Remove active check in activateTab
patrickrodee Jul 27, 2018
cb25074
WIP Release preparations
Jul 27, 2018
26eab8e
feat(tab-bar): Update tab activation notification logic; Add a test
patrickrodee Jul 27, 2018
7869fdd
fix(tab-scroller): Update tests
patrickrodee Jul 27, 2018
0c7f132
WIP super minor demo fixes
Jul 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
320 changes: 320 additions & 0 deletions demos/tab-bar.html

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions demos/tab-bar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// Copyright 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@import "./common";
@import "../packages/mdc-tab/mdc-tab";
@import "../packages/mdc-tab/mixins";
@import "../packages/mdc-tab-indicator/mdc-tab-indicator";
@import "../packages/mdc-tab-indicator/mixins";
@import "../packages/mdc-tab-scroller/mdc-tab-scroller";
@import "../packages/mdc-tab-bar/mdc-tab-bar";
@import "../packages/mdc-tab-bar/mixins";
@import "../packages/mdc-elevation/mixins";
@import "../packages/mdc-ripple/mixins";
@import "../packages/mdc-theme/color-palette";

.demo {
display: flex;
align-items: center;
}

.hero-demo-tab-bar {
@include mdc-tab-bar-width(420px);
}

.custom-demo-tab-bar {
.mdc-tab {
@include mdc-typography(subtitle1);
@include mdc-tab-fixed-width(120px);
@include mdc-tab-text-label-color($material-color-blue-600);
@include mdc-tab-icon-color($material-color-blue-600);
}

.mdc-tab__ripple {
@include mdc-states($material-color-yellow-700);
}

.mdc-tab--active {
@include mdc-tab-text-label-color($material-color-blue-900);
@include mdc-tab-icon-color($material-color-blue-900);
}

.mdc-tab-indicator {
@include mdc-tab-indicator-underline-height(5px);
@include mdc-tab-indicator-underline-color($material-color-yellow-700);
}
}

.demo-controls {
padding: 0 16px;
}

.rtl-container {
margin: 24px;
padding: 24px;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"switch",
"tabs",
"tab",
"tab-bar",
"tab-indicator",
"tab-scroller",
"text-field",
Expand Down Expand Up @@ -230,6 +231,7 @@
"mdc-tab",
"mdc-tab-indicator",
"mdc-tab-scroller",
"mdc-tab-bar",
"mdc-textfield",
"mdc-top-app-bar"
]
Expand Down
10 changes: 3 additions & 7 deletions packages/material-components-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import * as selectionControl from '@material/selection-control/index';
import * as slider from '@material/slider/index';
import * as snackbar from '@material/snackbar/index';
import * as tab from '@material/tab/index';
import * as tabBar from '@material/tab-bar/index';
import * as tabIndicator from '@material/tab-indicator/index';
import * as tabScroller from '@material/tab-scroller/index';
import * as tabs from '@material/tabs/index';
import * as textField from '@material/textfield/index';
import * as toolbar from '@material/toolbar/index';
import * as topAppBar from '@material/top-app-bar/index';
Expand All @@ -63,11 +63,7 @@ autoInit.register('MDCList', list.MDCList);
autoInit.register('MDCNotchedOutline', notchedOutline.MDCNotchedOutline);
autoInit.register('MDCRadio', radio.MDCRadio);
autoInit.register('MDCSnackbar', snackbar.MDCSnackbar);
autoInit.register('MDCTab_', tab.MDCTab);
autoInit.register('MDCTabIndicator', tabIndicator.MDCTabIndicator);
autoInit.register('MDCTabScroller', tabScroller.MDCTabScroller);
autoInit.register('MDCTab', tabs.MDCTab);
autoInit.register('MDCTabBar', tabs.MDCTabBar);
autoInit.register('MDCTabBar', tabBar.MDCTabBar);
autoInit.register('MDCTextField', textField.MDCTextField);
autoInit.register('MDCMenu', menu.MDCMenu);
autoInit.register('MDCSelect', select.MDCSelect);
Expand Down Expand Up @@ -100,9 +96,9 @@ export {
slider,
snackbar,
tab,
tabBar,
tabIndicator,
tabScroller,
tabs,
textField,
toolbar,
topAppBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
@import "@material/snackbar/mdc-snackbar";
@import "@material/switch/mdc-switch";
@import "@material/tab/mdc-tab";
@import "@material/tab-bar/mdc-tab-bar";
@import "@material/tab-indicator/mdc-tab-indicator";
@import "@material/tab-scroller/mdc-tab-scroller";
@import "@material/tabs/mdc-tabs";
@import "@material/textfield/mdc-text-field";
@import "@material/theme/mdc-theme";
@import "@material/toolbar/mdc-toolbar";
Expand Down
2 changes: 1 addition & 1 deletion packages/material-components-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"@material/snackbar": "^0.37.1",
"@material/switch": "^0.36.1",
"@material/tab": "^0.37.0",
"@material/tab-bar": "^0.0.0",
"@material/tab-indicator": "^0.0.0",
"@material/tabs": "^0.37.1",
"@material/tab-scroller": "^0.0.0",
"@material/textfield": "^0.37.1",
"@material/theme": "^0.35.0",
Expand Down
133 changes: 133 additions & 0 deletions packages/mdc-tab-bar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!--docs:
title: "Tab Bar"
layout: detail
section: components
excerpt: "Manages a set of Tabs."
iconId: tabs
path: /catalog/tabs/tab-bar/
-->

# Tab Bar

Tabs organize and allow navigation between groups of content that are related and at the same level of hierarchy.
The Tab Bar contains the Tab Scroller and Tab components.

## Design & API Documentation

<ul class="icon-list">
<li class="icon-list-item icon-list-item--spec">
<a href="https://material.io/go/design-tabs">Material Design guidelines: 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-bar
```

## Basic Usage

### HTML Structure

```html
<div class="mdc-tab-bar" role="tablist">
<div class="mdc-tab-scroller">
<div class="mdc-tab-scroller__scroll-area">
<div class="mdc-tab-scroller__scroll-content">
<button class="mdc-tab mdc-tab--active" role="tab" aria-selected="true" tabindex="0">
<div class="mdc-tab__content">
<span class="mdc-tab__icon">heart</div>
<span class="mdc-tab__text-label">Favorites</div>
</div>
<span class="mdc-tab-indicator mdc-tab-indicator--active">
<span class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
</span>
<div class="mdc-tab__ripple"></div>
</button>
</div>
</div>
</div>
</button>
```

### Styles

```scss
@import "@material/tab-bar/mdc-tab-bar";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include the other 3 tab component imports here

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

### JavaScript Instantiation

```js
import {MDCTabBar} from '@material/tab-bar';

const tabBar = new MDCTabBar(document.querySelector('.mdc-tab-bar'));
```

> 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-bar` | Mandatory.

### Sass Mixins

To customize the width of the tab bar, use the following mixin.

Mixin | Description
--- | ---
`mdc-tab-bar-width($width)` | Customizes the width of the tab bar.

## `MDCTabBar` Properties and Methods

Method Signature | Description
--- | ---
`activateTab(index: number) => void` | Activates the tab at the given index.
`scrollIntoView(index: number) => void` | Scrolls the tab at the given index into view.

Event Name | Event Data Structure | Description
--- | --- | ---
`MDCTabBar:activated` | `{"detail": {"index": number}}` | Emitted when a Tab is activated with the index of the activated Tab. Listen for this to update content when a Tab becomes active.

## Usage within Web Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Tab Bar 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).

### `MDCTabBarAdapter`

Method Signature | Description
--- | ---
`scrollTo(scrollX: number) => void` | Scrolls the Tab Scroller to the given position.
`incrementScroll(scrollXIncrement: number) => void` | Increments the Tab Scroller by the given value.
`getScrollPosition() => number` | Returns the scroll position of the Tab Scroller.
`getScrollContentWidth() => number` | Returns the width of the Tab Scroller's scroll content element.
`getOffsetWidth() => number` | Returns the offsetWidth of the root element.
`isRTL() => boolean` | Returns if the text direction is RTL.
`activateTabAtIndex(index: number, clientRect: ClientRect) => void` | Activates the Tab at the given index with the given clientRect.
`deactivateTabAtIndex(index) => void` | Deactivates the Tab at the given index.
`getTabIndicatorClientRectAtIndex(index: number) => ClientRect` | Returns the client rect of the Tab at the given index.
`getTabDimensionsAtIndex(index) => MDCTabDimensions` | Returns the dimensions of the Tab at the given index.
`getTabListLength() => number` | Returns the number of child Tab components.
`getActiveTabIndex() => number` | Returns the index of the active Tab.
`getIndexOfTab(tab: MDCTab) => number` | Returns the index of the given Tab instance.
`notifyTabActivated(index: number) => void` | Emits the `MDCTabBar:activated` event.

### `MDCTabBarFoundation`

Method Signature | Description
--- | ---
`activateTab(index: number) => void` | Activates the Tab at the given index.
`handleKeyDown(evt: Event) => void` | Handles the logic for the `"keydown"` event.
`handleTabInteraction(evt: Event) => void` | Handles the logic for the `"MDCTab:interacted"` event.
`scrollIntoView(index: number) => void` | Scrolls the Tab at the given index into view.
20 changes: 20 additions & 0 deletions packages/mdc-tab-bar/_mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2018 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@mixin mdc-tab-bar-width($width) {
width: $width;
}
Loading