Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(floating label): focus blur float label #2560

Merged
merged 4 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/mdc-select/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export default class MDCSelectFoundation extends MDCFoundation {

this.adapter_.setSelectedIndex(index);
this.adapter_.addClass(IS_CHANGING);
const optionHasValue = this.adapter_.getValue().length > 0;

this.adapter_.floatLabel(optionHasValue);
this.floatLabelWithValue_();

setTimeout(() => {
this.adapter_.removeClass(IS_CHANGING);
Expand All @@ -97,11 +95,18 @@ export default class MDCSelectFoundation extends MDCFoundation {
}
}

floatLabelWithValue_() {
const optionHasValue = this.adapter_.getValue().length > 0;
this.adapter_.floatLabel(optionHasValue);
}

handleFocus_() {
this.adapter_.floatLabel(true);
this.adapter_.activateBottomLine();
}

handleBlur_() {
this.floatLabelWithValue_();
this.adapter_.deactivateBottomLine();
}

Expand Down
18 changes: 17 additions & 1 deletion test/unit/mdc-select/foundation-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,34 @@ function setupTest() {

suite('MDCSelectFoundation - Events');

test('on focus activates bottom line', () => {
test('on focus activates bottom line and floats label', () => {
const {mockAdapter, handlers} = setupTest();
handlers.focus();
td.verify(mockAdapter.activateBottomLine(), {times: 1});
td.verify(mockAdapter.floatLabel(true), {times: 1});
});

test('on blur deactivates bottom line', () => {
const {mockAdapter, handlers} = setupTest();
td.when(mockAdapter.getValue()).thenReturn('');
handlers.blur();
td.verify(mockAdapter.deactivateBottomLine(), {times: 1});
});

test('on blur with no value defloats label', () => {
const {mockAdapter, handlers} = setupTest();
td.when(mockAdapter.getValue()).thenReturn('');
handlers.blur();
td.verify(mockAdapter.floatLabel(false), {times: 1});
});

test('on blur with value floats label', () => {
const {mockAdapter, handlers} = setupTest();
td.when(mockAdapter.getValue()).thenReturn('some value');
handlers.blur();
td.verify(mockAdapter.floatLabel(true), {times: 1});
});

test('on select value change with option value', () => {
const clock = lolex.install();
const {mockAdapter, handlers} = setupTest();
Expand Down