-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(select):change calculateOverlayOffsetY to address offset for small lists #9885
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
Changes from 3 commits
1bf5415
c25862a
d87b1d7
b1d2ada
95c0dad
4b63d1a
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 |
---|---|---|
|
@@ -360,6 +360,9 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, | |
this._multiple = coerceBooleanProperty(value); | ||
} | ||
|
||
/** Whether the user wants to disable the offset. */ | ||
@Input () disableOffset: string = ''; | ||
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. Should be a boolean. |
||
|
||
/** | ||
* A function to compare the option values with the selected values. The first argument | ||
* is a value from an option. The second is a value from the selection. A boolean | ||
|
@@ -1119,6 +1122,11 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, | |
const maxOptionsDisplayed = Math.floor(SELECT_PANEL_MAX_HEIGHT / itemHeight); | ||
let optionOffsetFromPanelTop: number; | ||
|
||
// Disable offset for smaller lists by returning 0 as value to offset | ||
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. I think this comment is out of date now ("smaller lists") |
||
if (this.disableOffset == '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. After changing it to a boolean, this should be |
||
return 0; | ||
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. The new option still needs unit tests. 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. I've added a unit test |
||
} | ||
|
||
if (this._scrollTop === 0) { | ||
optionOffsetFromPanelTop = selectedIndex * itemHeight; | ||
} else if (this._scrollTop === maxScroll) { | ||
|
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.
I'm not sure whether people looking at the documentation would know what offset this is referring to. What about calling it something like
disableOptionCentering
?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.
I've made the changes you requested for the input:
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.
Note that this comment will end up on the docs site. Something along the lines of "Whether to center the active option over the trigger" would be clearer.