Blame view

bower_components/paper-radio-group/paper-radio-group.html 4.98 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
  <!--
  @license
  Copyright (c) 2015 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
  -->
  
  <link rel="import" href="../polymer/polymer.html">
eb240478   Luigi Serra   public room cards...
12
  <link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
73bcce88   luigser   COMPONENTS
13
14
  <link rel="import" href="../iron-selector/iron-selectable.html">
  <link rel="import" href="../paper-radio-button/paper-radio-button.html">
73bcce88   luigser   COMPONENTS
15
16
  
  <!--
eb240478   Luigi Serra   public room cards...
17
18
19
  Material design: [Radio button](https://www.google.com/design/spec/components/selection-controls.html#selection-controls-radio-button)
  
  `paper-radio-group` allows user to select at most one radio button from a set.
73bcce88   luigser   COMPONENTS
20
21
22
23
  Checking one radio button that belongs to a radio group unchecks any
  previously checked radio button within the same group. Use
  `selected` to get or set the selected radio button.
  
eb240478   Luigi Serra   public room cards...
24
25
26
  The <paper-radio-buttons> inside the group must have the `name` attribute
  set.
  
73bcce88   luigser   COMPONENTS
27
28
29
30
31
32
33
34
  Example:
  
      <paper-radio-group selected="small">
        <paper-radio-button name="small">Small</paper-radio-button>
        <paper-radio-button name="medium">Medium</paper-radio-button>
        <paper-radio-button name="large">Large</paper-radio-button>
      </paper-radio-group>
  
eb240478   Luigi Serra   public room cards...
35
36
37
38
39
40
41
42
43
  Radio-button-groups can be made optional, and allow zero buttons to be selected:
  
      <paper-radio-group selected="small" allow-empty-selection>
        <paper-radio-button name="small">Small</paper-radio-button>
        <paper-radio-button name="medium">Medium</paper-radio-button>
        <paper-radio-button name="large">Large</paper-radio-button>
      </paper-radio-group>
  
  See <a href="paper-radio-button">paper-radio-button</a> for more
73bcce88   luigser   COMPONENTS
44
45
46
47
48
49
50
51
  information about `paper-radio-button`.
  
  @group Paper Elements
  @element paper-radio-group
  @hero hero.svg
  @demo demo/index.html
  -->
  
eb240478   Luigi Serra   public room cards...
52
  <dom-module id="paper-radio-group">
c5169e0e   Renato De Donato   a new hope
53
54
55
56
    <style>
      :host {
        display: inline-block;
      }
73bcce88   luigser   COMPONENTS
57
  
c5169e0e   Renato De Donato   a new hope
58
59
60
61
      :host ::content > * {
        padding: 12px;
      }
    </style>
73bcce88   luigser   COMPONENTS
62
  
c5169e0e   Renato De Donato   a new hope
63
64
    <template>
        <content id="items" select="*"></content>
73bcce88   luigser   COMPONENTS
65
    </template>
c5169e0e   Renato De Donato   a new hope
66
  
73bcce88   luigser   COMPONENTS
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  </dom-module>
  
  <script>
    Polymer({
      is: 'paper-radio-group',
  
      behaviors: [
        Polymer.IronA11yKeysBehavior,
        Polymer.IronSelectableBehavior
      ],
  
      hostAttributes: {
        role: 'radiogroup',
        tabindex: 0
      },
  
      properties: {
        /**
eb240478   Luigi Serra   public room cards...
85
86
87
88
89
90
         * Fired when the radio group selection changes.
         *
         * @event paper-radio-group-changed
         */
  
        /**
73bcce88   luigser   COMPONENTS
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
         * Overriden from Polymer.IronSelectableBehavior
         */
        attrForSelected: {
          type: String,
          value: 'name'
        },
  
        /**
         * Overriden from Polymer.IronSelectableBehavior
         */
        selectedAttribute: {
          type: String,
          value: 'checked'
        },
  
        /**
         * Overriden from Polymer.IronSelectableBehavior
         */
        selectable: {
          type: String,
          value: 'paper-radio-button'
eb240478   Luigi Serra   public room cards...
112
113
114
115
116
117
118
119
        },
  
        /**
         * If true, radio-buttons can be deselected
         */
        allowEmptySelection: {
          type: Boolean,
          value: false
73bcce88   luigser   COMPONENTS
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
        }
      },
  
      keyBindings: {
        'left up': 'selectPrevious',
        'right down': 'selectNext',
      },
  
      /**
       * Selects the given value.
       */
       select: function(value) {
        if (this.selected) {
          var oldItem = this._valueToItem(this.selected);
  
73bcce88   luigser   COMPONENTS
135
          if (this.selected == value) {
eb240478   Luigi Serra   public room cards...
136
137
138
139
140
141
            // If deselecting is allowed we'll have to apply an empty selection.
            // Otherwise, we should force the selection to stay and make this
            // action a no-op.
            if (this.allowEmptySelection) {
              value = '';
            } else {
c5169e0e   Renato De Donato   a new hope
142
              oldItem.checked = true;
eb240478   Luigi Serra   public room cards...
143
144
              return;
            }
73bcce88   luigser   COMPONENTS
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
          }
  
          if (oldItem)
            oldItem.checked = false;
        }
  
        Polymer.IronSelectableBehavior.select.apply(this, [value]);
        this.fire('paper-radio-group-changed');
      },
  
      /**
       * Selects the previous item. If the previous item is disabled, then it is
       * skipped, and its previous item is selected
       */
      selectPrevious: function() {
        var length = this.items.length;
        var newIndex = Number(this._valueToIndex(this.selected));
  
        do {
          newIndex = (newIndex - 1 + length) % length;
        } while (this.items[newIndex].disabled)
  
c5169e0e   Renato De Donato   a new hope
167
        this.select(this._indexToValue(newIndex));
73bcce88   luigser   COMPONENTS
168
169
170
171
172
173
174
175
176
177
178
179
180
181
      },
  
      /**
       * Selects the next item. If the next item is disabled, then it is
       * skipped, and the next item after it is selected.
       */
      selectNext: function() {
        var length = this.items.length;
        var newIndex = Number(this._valueToIndex(this.selected));
  
        do {
          newIndex = (newIndex + 1 + length) % length;
        } while (this.items[newIndex].disabled)
  
c5169e0e   Renato De Donato   a new hope
182
        this.select(this._indexToValue(newIndex));
73bcce88   luigser   COMPONENTS
183
184
185
      },
    });
  </script>