| OLD | NEW |
| (Empty) |
| 1 | |
| 2 | |
| 3 /** @polymerBehavior */ | |
| 4 | |
| 5 Polymer.IronControlState = { | |
| 6 | |
| 7 properties: { | |
| 8 | |
| 9 /** | |
| 10 * If true, the element currently has focus. | |
| 11 * | |
| 12 * @attribute focused | |
| 13 * @type boolean | |
| 14 * @default false | |
| 15 */ | |
| 16 focused: { | |
| 17 type: Boolean, | |
| 18 value: false, | |
| 19 notify: true, | |
| 20 readOnly: true, | |
| 21 reflectToAttribute: true | |
| 22 }, | |
| 23 | |
| 24 /** | |
| 25 * If true, the user cannot interact with this element. | |
| 26 * | |
| 27 * @attribute disabled | |
| 28 * @type boolean | |
| 29 * @default false | |
| 30 */ | |
| 31 disabled: { | |
| 32 type: Boolean, | |
| 33 value: false, | |
| 34 notify: true, | |
| 35 observer: '_disabledChanged', | |
| 36 reflectToAttribute: true | |
| 37 }, | |
| 38 | |
| 39 _oldTabIndex: { | |
| 40 type: Number | |
| 41 } | |
| 42 }, | |
| 43 | |
| 44 observers: [ | |
| 45 '_changedControlState(focused, disabled)' | |
| 46 ], | |
| 47 | |
| 48 listeners: { | |
| 49 focus: '_focusHandler', | |
| 50 blur: '_blurHandler' | |
| 51 }, | |
| 52 | |
| 53 ready: function() { | |
| 54 // TODO(sjmiles): ensure read-only property is valued so the compound | |
| 55 // observer will fire | |
| 56 if (this.focused === undefined) { | |
| 57 this._setFocused(false); | |
| 58 } | |
| 59 }, | |
| 60 | |
| 61 _focusHandler: function() { | |
| 62 this._setFocused(true); | |
| 63 }, | |
| 64 | |
| 65 _blurHandler: function() { | |
| 66 this._setFocused(false); | |
| 67 }, | |
| 68 | |
| 69 _disabledChanged: function(disabled, old) { | |
| 70 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | |
| 71 this.style.pointerEvents = disabled ? 'none' : ''; | |
| 72 if (disabled) { | |
| 73 this._oldTabIndex = this.tabIndex; | |
| 74 this.focused = false; | |
| 75 this.tabIndex = -1; | |
| 76 } else if (this._oldTabIndex !== undefined) { | |
| 77 this.tabIndex = this._oldTabIndex; | |
| 78 } | |
| 79 }, | |
| 80 | |
| 81 _changedControlState: function() { | |
| 82 // _controlStateChanged is abstract, follow-on behaviors may implement it | |
| 83 if (this._controlStateChanged) { | |
| 84 this._controlStateChanged(); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 }; | |
| 89 | |
| OLD | NEW |