Skip to content

Commit

Permalink
feat(md-select): add floating label, ref #243
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanood committed Sep 1, 2016
1 parent beb322c commit 6aaa610
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/colors/md-colors.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@
/* text input aurelia-validation messages */
.md-input-validation {
left: 0;
color:#f44336;
font-size:0.8rem;
color: #f44336;
font-size: 0.8rem;
transition: opacity .2s ease-out;
margin-top: -4px;
margin-bottom: 0;
Expand Down Expand Up @@ -230,7 +230,7 @@
background: ${mdAccentColor};
}
md-range input[type="range"] + .thumb {
background-color: ${mdAccentColor}!important;
background-color: ${mdAccentColor} !important;
}

/* select */
Expand Down Expand Up @@ -278,5 +278,39 @@
footer.page-footer {
background-color: ${mdPrimaryColor};
}

/* md-select label */
.select-wrapper input {
// make input fit in div
display: inline-block !important;
// fix validation border thickness
border-bottom: 1px solid #4CAF50;
}

.select-wrapper input.invalid {
border-bottom: 1px solid #F44336;
}

.select-wrapper + label {
color: ${mdAccentColor};
width: 100%;
}
/* position validation label */
.select-wrapper + label:after {
display: block;
content: "";
position: absolute;
top: 60px;
opacity: 0;
transition: .2s opacity ease-out, .2s color ease-out;
transform: translateY(0) !important;
}
/* set validation text */
.select-wrapper.invalid + label:after {
content: attr(data-error);
color: #F44336;
opacity: 1;
}

</style>
</template>
12 changes: 12 additions & 0 deletions src/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {fireEvent} from '../common/events';
@customAttribute('md-select')
export class MdSelect {
@bindable() disabled = false;
@bindable() label = '';
_suspendUpdate = false;
subscriptions = [];
Expand All @@ -29,6 +30,17 @@ export class MdSelect {
// this.handleChangeFromNativeSelect();
// });
this.createMaterialSelect(false);
if (this.label) {
let wrapper = $(this.element).parent('.select-wrapper');
let div = $('<div class="input-field"></div>');
let va = this.element.attributes.getNamedItem('validate');
if (va) {
div.attr(va.name, va.label);
}
wrapper.wrap(div);
$(`<label>${this.label}</label>`).insertAfter(wrapper);
}
$(this.element).on('change', this.handleChangeFromNativeSelect);
}
Expand Down

0 comments on commit 6aaa610

Please sign in to comment.