Skip to content
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

Closed
Changes from all 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
7 changes: 3 additions & 4 deletions packages/mdc-select/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ export default class MDCSelectFoundation extends MDCFoundation {
};
this.cancelHandler_ = () => {
this.close_();
if (this.selectedIndex_ === -1) {
Copy link
Contributor

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.

this.adapter_.floatLabel(false);
}
};
}

Expand Down Expand Up @@ -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);
Copy link
Contributor

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);
}

}
this.adapter_.setSelectedTextContent(selectedTextContent);
}
Expand Down Expand Up @@ -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);
Copy link
Contributor

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.

this.adapter_.addClassToBottomLine(cssClasses.BOTTOM_LINE_ACTIVE);
this.adapter_.addClass(OPEN);
this.animationRequestId_ = requestAnimationFrame(() => {
Expand Down