|
34 | 34 | You can use a custom input element in a `<paper-input-container>`, for example to implement a |
35 | 35 | compound input field like a social security number input. The custom input element should have the |
36 | 36 | `paper-input-input` class, have a `notify:true` value property and optionally implements |
37 | | -`Polymer.IronValidatableBehavior` if it is validatble. |
| 37 | +`Polymer.IronValidatableBehavior` if it is validatable. |
38 | 38 |
|
39 | 39 | <paper-input-container attr-for-value="ssn-value"> |
40 | 40 | <label>Social security number</label> |
|
53 | 53 | or validity changes, and may implement functionality such as error messages or character counters. |
54 | 54 | They appear at the bottom of the input. |
55 | 55 |
|
| 56 | +### Prefixes and suffixes |
| 57 | +These are child elements of a `<paper-input-container>` with the `prefix` |
| 58 | +or `suffix` attribute, and are displayed inline with the input, before or after. |
| 59 | +
|
| 60 | + <paper-input-container> |
| 61 | + <div prefix>$</div> |
| 62 | + <label>Total</label> |
| 63 | + <input is="iron-input"> |
| 64 | + <paper-icon-button suffix icon="clear"></paper-icon-button> |
| 65 | + </paper-input-container> |
| 66 | +
|
56 | 67 | ### Styling |
57 | 68 |
|
58 | 69 | The following custom properties and mixins are available for styling: |
|
150 | 161 | @apply(--paper-input-container-underline-disabled); |
151 | 162 | } |
152 | 163 |
|
| 164 | + .label-and-input-container { |
| 165 | + @apply(--layout-flex); |
| 166 | + @apply(--layout-relative); |
| 167 | + } |
| 168 | + |
153 | 169 | .input-content { |
154 | 170 | position: relative; |
| 171 | + @apply(--layout-horizontal); |
155 | 172 | } |
156 | 173 |
|
157 | 174 | .input-content ::content label, |
|
213 | 230 | @apply(--paper-input-container-input); |
214 | 231 | } |
215 | 232 |
|
| 233 | + ::content [prefix], |
| 234 | + ::content [suffix] { |
| 235 | + @apply(--paper-font-subhead); |
| 236 | + @apply(--paper-input-container-input); |
| 237 | + } |
| 238 | + |
216 | 239 | /* Firefox sets a min-width on the input, which can cause layout issues */ |
217 | 240 | .input-content ::content input { |
218 | 241 | min-width: 0; |
|
239 | 262 | </template> |
240 | 263 |
|
241 | 264 | <div class$="[[_computeInputContentClass(noLabelFloat,alwaysFloatLabel,focused,invalid,_inputHasContent)]]"> |
242 | | - <content select=":not([add-on])"></content> |
| 265 | + <content select="[prefix]" id="prefix"></content> |
| 266 | + <div class="label-and-input-container"> |
| 267 | + <content select=":not([add-on]):not([prefix]):not([suffix])"></content> |
| 268 | + </div> |
| 269 | + <content select="[suffix]"></content> |
243 | 270 | </div> |
244 | 271 |
|
245 | 272 | <div class$="[[_computeUnderlineClass(focused,invalid)]]"> |
|
476 | 503 | _computeInputContentClass: function(noLabelFloat, alwaysFloatLabel, focused, invalid, _inputHasContent) { |
477 | 504 | var cls = 'input-content'; |
478 | 505 | if (!noLabelFloat) { |
| 506 | + var label = this.querySelector('label'); |
| 507 | + |
479 | 508 | if (alwaysFloatLabel || _inputHasContent) { |
480 | 509 | cls += ' label-is-floating'; |
481 | 510 | if (invalid) { |
482 | 511 | cls += ' is-invalid'; |
483 | 512 | } else if (focused) { |
484 | 513 | cls += " label-is-highlighted"; |
485 | 514 | } |
| 515 | + // The label might have a horizontal offset if a prefix element exists |
| 516 | + // which needs to be undone when displayed as a floating label. |
| 517 | + if (this.$.prefix && label && label.offsetParent) { |
| 518 | + label.style.left = -label.offsetParent.offsetLeft + 'px'; |
| 519 | + } |
| 520 | + } else { |
| 521 | + // When the label is not floating, it should overlap the input element. |
| 522 | + if (label) { |
| 523 | + label.style.left = 0; |
| 524 | + } |
486 | 525 | } |
487 | 526 | } else { |
488 | 527 | if (_inputHasContent) { |
|
0 commit comments