2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
12 * @group Paper Elements
14 * paper-focusable is a base class for paper elements that can be focused.
16 * @element paper-focusable
22 <link href="../polymer/polymer.html" rel="import">
24 <polymer-element name="paper-focusable" attributes="active focused disabled isToggle" tabindex="0" on-down="{{downAction}}" on-up="{{upAction}}" on-focus="{{focusAction}}" on-blur="{{blurAction}}" on-contextmenu="{{contextMenuAction}}">
36 Polymer('paper-focusable', {
41 * If true, the button is currently active either because the
42 * user is holding down the button, or the button is a toggle
43 * and is currently in the active state.
49 active: {value: false, reflect: true},
52 * If true, the element currently has focus due to keyboard
59 focused: {value: false, reflect: true},
62 * If true, the user is currently holding down the button.
68 pressed: {value: false, reflect: true},
71 * If true, the user cannot interact with this element.
77 disabled: {value: false, reflect: true},
80 * If true, the button toggles the active state with each tap.
81 * Otherwise, the button becomes active when the user is holding
88 isToggle: {value: false, reflect: false}
92 disabledChanged: function() {
94 this.removeAttribute('tabindex');
96 this.setAttribute('tabindex', 0);
100 downAction: function() {
102 this.focused = false;
105 this.active = !this.active;
111 // Pulling up the context menu for an item should focus it; but we need to
112 // be careful about how we deal with down/up events surrounding context
113 // menus. The up event typically does not fire until the context menu
114 // closes: so we focus immediately.
116 // This fires _after_ downAction.
117 contextMenuAction: function(e) {
118 // Note that upAction may fire _again_ on the actual up event.
123 upAction: function() {
124 this.pressed = false;
126 if (!this.isToggle) {
131 focusAction: function() {
133 // Only render the "focused" state if the element gains focus due to
134 // keyboard navigation.
139 blurAction: function() {
140 this.focused = false;