This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a11y-collapse-icon-button.html
146 lines (134 loc) · 4.55 KB
/
a11y-collapse-icon-button.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html" />
<link rel="import" href="a11y-collapse-button-styles.html" />
<link rel="import" href="../paper-tooltip/paper-tooltip.html"/>
<!--
`a11y-collapse-icon-button`
An accessible expand collapse.
@demo demo/index.html
@microcopy - the mental model for this element
<ally-collapse-icon-button id="iconbutton"
expanded$="[[_setAriaExpanded(expanded)]]"
label="" //The expand/collapse label. Default is "expand/collapse"
icon="" //The expand/collapse icon. Default is "icons:expand-more"
tooltip="" //The expand/collapse tooltip. Default is "toggle expand/collapse"
rotated$="[[__rotateIcon]]">
</ally-collapse-icon-button>
<a11y-collapse-icon-button
accordion
disabled
icon="" //The expand/collapse icon. Default is "icons:expand-more"
icon-expanded="" //The expand/collapse icon when expanded. Default is the same as when collapsed.
label="" //The expand/collapse label. Default is "expand/collapse"
label-expanded="" //The expand/collapse label when expanded. Default is the same as when collapsed.
tooltip="" //The expand/collapse tooltip. Default is "toggle expand/collapse"
tooltip-expanded="" //The expand/collapse tooltip when expanded. Default is the same as when collapsed.
<p slot="heading">...</p> //Named slot for a heading.
... //Unnamed slot for a collapsible content.
</a11y-collapse-icon-button>
CSS Variables:
--a11y-collapse-icon-button-horizontal-padding //sets the horizontal padding (left and right) inside the a11y-collapse-icon-button
--a11y-collapse-icon-button-vertical-padding //sets the horizontal padding (top and bottom) inside the a11y-collapse-icon-button
--a11y-collapse-icon-button-border //sets the border style. Default is 0px solid black
CSS Mixins:
--a11y-collapse-icon-button-icon-focus: { ... }; //sets CSS for the a11y-collapse-icon-button icon when button is focused or hovered
-->
<dom-module id="a11y-collapse-icon-button">
<template>
<style include="a11y-collapse-button-styles">
:host #expand:focus,
:host #expand:hover {
@apply --a11y-collapse-icon-focus;
}
</style>
<div id="heading">
<div id="text"><slot></slot></div>
<paper-icon-button id="expand"
alt$="[[label]]"
aria-controls="content"
aria-expanded$="[[exanded]]"
disabled$="[[disabled]]"
label$="[[label]]"
icon$="[[icon]]"
rotated$="[[rotated]]">
</paper-icon-button>
<paper-tooltip for="expand">[[tooltip]]</paper-tooltip>
</div>
</template>
<script>
Polymer({
is: 'a11y-collapse-icon-button',
behaviors: [HAXBehaviors.PropertiesBehaviors, SchemaBehaviors.Schema],
properties: {
/**
* is disabled?
*/
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* icon when expanded
*/
expanded: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* icon for the button
*/
icon: {
type: String,
value: 'icons:expand-more'
},
/**
* label for the button
*/
label: {
type: String,
value: 'expand/collapse'
},
/**
* tooltip for the button
*/
tooltip: {
type: String,
value: 'toggle expand/collapse'
},
/**
* If no expanded icon is set, the default icon will rotate when expanded
*/
rotated: {
type: Boolean,
value: false
},
},
/**
* Attached to the DOM, now fire.
*/
ready: function() {
let root = this;
this.$.expand.addEventListener('tap',function(e){
root._onTap(e);
});
},
/**
* Remove lsitener.
*/
detached: function() {
this.$.expand.removeEventListener('tap');
},
/**
/**
* Handle tap
*/
_onTap: function(e) {
if(!this.disabled) {
this.fire('a11y-collapse-tap',this);
}
}
});
</script>
</dom-module>