-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(select): pre-selected option correctly floats label #2283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,9 +105,6 @@ export default class MDCSelectFoundation extends MDCFoundation { | |
}; | ||
this.cancelHandler_ = () => { | ||
this.close_(); | ||
if (this.selectedIndex_ === -1) { | ||
this.adapter_.floatLabel(false); | ||
} | ||
}; | ||
} | ||
|
||
|
@@ -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 commentThe 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.
|
||
} | ||
this.adapter_.setSelectedTextContent(selectedTextContent); | ||
} | ||
|
@@ -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 commentThe 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. |
||
this.adapter_.addClassToBottomLine(cssClasses.BOTTOM_LINE_ACTIVE); | ||
this.adapter_.addClass(OPEN); | ||
this.animationRequestId_ = requestAnimationFrame(() => { | ||
|
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.