-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(select): pre-selected option correctly floats label #2283
fix(select): pre-selected option correctly floats label #2283
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2283 +/- ##
==========================================
- Coverage 99.21% 98.96% -0.26%
==========================================
Files 99 93 -6
Lines 3967 3856 -111
Branches 510 500 -10
==========================================
- Hits 3936 3816 -120
- Misses 31 40 +9
Continue to review full report at Codecov.
|
Thanks for submitting this PR. The label should float when the menu is opened, and not only when an item is selected. |
@@ -105,9 +105,6 @@ export default class MDCSelectFoundation extends MDCFoundation { | |||
}; | |||
this.cancelHandler_ = () => { | |||
this.close_(); | |||
if (this.selectedIndex_ === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to have the floating label class removed when the menu is closed.
@@ -212,7 +212,6 @@ export default class MDCSelectFoundation extends MDCFoundation { | |||
const focusIndex = this.selectedIndex_ < 0 ? 0 : this.selectedIndex_; | |||
|
|||
this.setMenuStylesForOpenAtIndex_(focusIndex); | |||
this.adapter_.floatLabel(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to ensure the label floats when the menu is opened.
@@ -155,6 +152,9 @@ export default class MDCSelectFoundation extends MDCFoundation { | |||
if (this.selectedIndex_ >= 0) { | |||
selectedTextContent = this.adapter_.getTextForOptionAtIndex(this.selectedIndex_).trim(); | |||
this.adapter_.setAttrForOptionAtIndex(this.selectedIndex_, 'aria-selected', 'true'); | |||
this.adapter_.floatLabel(true); | |||
} else { | |||
this.adapter_.floatLabel(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only called if the menu is not opened, so that the label is always floating if the menu is opened.
if (this.adapter_.isMenuOpen()) {
this.adapter_.floatLabel(false);
}
Closes #2282, fixing regression from #2244