-
Notifications
You must be signed in to change notification settings - Fork 5
/
px-tabs.html
131 lines (111 loc) · 3.69 KB
/
px-tabs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!--
Copyright (c) 2018, General Electric
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.
-->
<link rel="import" href="../polymer/polymer.html"/>
<link rel="import" href="../iron-selector/iron-selectable.html"/>
<link rel="import" href="../iron-a11y-keys/iron-a11y-keys.html"/>
<link rel="import" href="px-tab.html"/>
<link rel="import" href="css/px-tabs-styles.html"/>
<!--
The px-tabs and px-tab components together provide the tabbed interface. The tabbed content is expected to be contained in a separate iron-pages component.
Note: There is no limit on the number of tabs in a set, but there is no support for scrolling or wrapping.
### Usage
```
<px-tabs selected="{{selected}}">
<px-tab>Tab 1</px-tab>
<px-tab>Tab 2</px-tab>
<px-tab>Tab 3</px-tab>
</px-tabs>
<iron-pages selected="{{selected}}">
<div>Tab 1 content</div>
<div>Tab 2 content</div>
<div>Tab 3 content</div>
</iron-pages>
```
### Styling
The following custom properties are available for styling:
Custom property | Description
----------------|-------------
`--px-tab-color` | Text color for unselected tabs
`--px-tab-color--hover` | Text color for unselected tabs on hover
`--px-tab-color--active` | Text color for unselected tabs on press
`--px-tab-color--selected` | Text and border color for selected tab
`--px-tab-border-color` | Border color for unselected tabs
|
`--px-tabs-container` | Mixin for the tab container (e.g. to add flex-wrap)
@element px-tabs
@blurb Container for px-tab elements
@homepage index.html
@demo index.html
-->
<dom-module id="px-tabs">
<template>
<style include="px-tabs-styles"></style>
<div id="container" class="tabs-container" tabindex="0">
<div class="tabs-container__nav flex">
<slot id="tabdefs"></slot>
</div>
</div>
<iron-a11y-keys target="[[_target]]" keys="right up" on-keys-pressed="_increment"></iron-a11y-keys>
<iron-a11y-keys target="[[_target]]" keys="left down" on-keys-pressed="_decrement"></iron-a11y-keys>
</template>
</dom-module>
<script>
Polymer({
is: 'px-tabs',
behaviors: [
Polymer.IronSelectableBehavior
],
listeners: {
'iron-select' : '_onIronSelect'
},
properties: {
_target: {
type: Object,
value: function() {
return '';
}
}
},
attached: function() {
this.setAttribute('role','tablist');
this._target = this.$.container;
},
/**
* Move forward by one tab, with wraparound from last to first.
*/
_increment: function(evt) {
evt.detail.keyboardEvent.preventDefault();
this.selectNext();
},
/**
* Move backward by one tab, with wraparound from first to last.
*/
_decrement: function(evt) {
evt.detail.keyboardEvent.preventDefault();
this.selectPrevious();
},
/**
* Fires an event when the tab is changed.
*/
_onIronSelect: function(evt) {
this.fire('px-tab-changed', {
tabID: Polymer.dom(evt).event.detail.item.id
}, {bubbles: true, cancelable: false});
}
/**
* Event fired when the selected tab is changed.
* evt.detail will contain the ID of the newly selected tab.
* @event px-tab-changed
*/
});
</script>