3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
12 `<core-label>` provides a version of the `<label>` element that works with Custom Elements as well as native elements.
14 All text in the `core-label` will be applied to the target element as a screen-reader accessible description.
16 There are two ways to use `core-label` to target an element:
18 1. place an element inside core-label with the `for` attribute:
21 Context for the Button
22 <paper-button for>button</paper-button>
25 2. Set the `for` attribute on the `core-label` element to point to a target element in the same scope with a query
28 <core-label for=".foo">
29 Context for the button witht the "foo" class"
31 <paper-button class="foo">Far away button</paper-button>
33 All taps on the `core-label` will be forwarded to the "target" element.
40 <link rel=
"import" href=
"../polymer/polymer.html">
42 <!-- Native <label> has cursor: default -->
44 html /deep/ core-label {
49 <polymer-element name=
"core-label">
54 function generate(node
) {
56 node
.id
= 'core-label-' + ID
++;
61 Polymer('core-label', {
63 * A query selector string for a "target" element not nested in the `<core-label>`
70 'for': {reflect
: true, value
: ''}
77 this._forElement
= null;
81 this._forElement
= this.querySelector('[for]');
85 tapHandler: function(ev
) {
86 if (!this._forElement
) {
89 if (ev
.target
=== this._forElement
) {
92 this._forElement
.focus();
93 this._forElement
.click();
94 this.fire('tap', null, this._forElement
);
97 if (this._forElement
) {
98 this._forElement
.setAttribute('aria-labelledby', this.id
);
101 _findScope: function() {
102 var n
= this.parentNode
;
103 while(n
&& n
.parentNode
) {
108 forChanged: function(oldFor
, newFor
) {
109 if (this._forElement
) {
110 this._forElement
.removeAttribute('aria-labelledby');
112 var scope
= this._findScope();
116 this._forElement
= scope
.querySelector(newFor
);
117 if (this._forElement
) {