This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
/
paper-radio-button.html
166 lines (127 loc) · 4.08 KB
/
paper-radio-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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!--
`paper-radio-button` is a button that can be either checked or unchecked.
User can tap the radio button to check it. But it cannot be unchecked by
tapping once checked.
Use `paper-radio-group` to group a set of radio buttons. When radio buttons
are inside a radio group, only one radio button in the group can be checked.
Example:
<paper-radio-button></paper-radio-button>
Styling radio button:
To change the ink color for checked state:
paper-radio-button::shadow #ink[checked] {
color: #4285f4;
}
To change the radio checked color:
paper-radio-button::shadow #onRadio {
background-color: #4285f4;
}
paper-radio-button[checked]::shadow #offRadio {
border-color: #4285f4;
}
To change the ink color for unchecked state:
paper-radio-button::shadow #ink {
color: #b5b5b5;
}
To change the radio unchecked color:
paper-radio-button::shadow #offRadio {
border-color: #b5b5b5;
}
@group Paper Elements
@element paper-radio-button
@homepage github.io
-->
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="../core-a11y-keys/core-a11y-keys.html">
<polymer-element name="paper-radio-button" role="radio" tabindex="0" aria-checked="false">
<template>
<link rel="stylesheet" href="paper-radio-button.css">
<core-a11y-keys target="{{}}" keys="space" on-keys-pressed="{{tap}}"></core-a11y-keys>
<div id="radioContainer" class="{{ {labeled: label} | tokenList }}">
<div id="offRadio"></div>
<div id="onRadio"></div>
<paper-ripple id="ink" class="circle recenteringTouch" checked?="{{!checked}}"></paper-ripple>
</div>
<div id="radioLabel" aria-hidden="true" hidden?="{{!label}}">{{label}}<content></content></div>
</template>
<script>
Polymer('paper-radio-button', {
/**
* Fired when the checked state changes due to user interaction.
*
* @event change
*/
/**
* Fired when the checked state changes.
*
* @event core-change
*/
publish: {
/**
* Gets or sets the state, `true` is checked and `false` is unchecked.
*
* @attribute checked
* @type boolean
* @default false
*/
checked: {value: false, reflect: true},
/**
* The label for the radio button.
*
* @attribute label
* @type string
* @default ''
*/
label: '',
/**
* Normally the user cannot uncheck the radio button by tapping once
* checked. Setting this property to `true` makes the radio button
* toggleable from checked to unchecked.
*
* @attribute toggles
* @type boolean
* @default false
*/
toggles: false,
/**
* If true, the user cannot interact with this element.
*
* @attribute disabled
* @type boolean
* @default false
*/
disabled: {value: false, reflect: true}
},
eventDelegates: {
tap: 'tap'
},
tap: function() {
if (this.disabled) {
return;
}
var old = this.checked;
this.toggle();
if (this.checked !== old) {
this.fire('change');
}
},
toggle: function() {
this.checked = !this.toggles || !this.checked;
},
checkedChanged: function() {
this.setAttribute('aria-checked', this.checked ? 'true' : 'false');
this.fire('core-change');
},
labelChanged: function() {
this.setAttribute('aria-label', this.label);
}
});
</script>
</polymer-element>