Skip to content

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

Merged
merged 6 commits into from
Feb 18, 2018
Merged
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
8 changes: 8 additions & 0 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
this._multiple = coerceBooleanProperty(value);
}

/** Whether the user wants to disable the offset. */
Copy link
Member

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?

Copy link
Contributor Author

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:

  • changed type to boolean
  • changed name of the variable
  • changed the if statement check

Copy link
Member

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.

@Input () disableOffset: string = '';
Copy link
Member

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

The 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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After changing it to a boolean, this should be if (this.disableOffset).

return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new option still needs unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a unit test with option centering disabled along with a component for testing it. I was thinking of adding it to the 'positioning' tests, but didn't do so to make it easier to add other cases.
I've run gulp test after adding it and the headless chrome returns all successful, but I'm not sure if there is a better way to test it.

}

if (this._scrollTop === 0) {
optionOffsetFromPanelTop = selectedIndex * itemHeight;
} else if (this._scrollTop === maxScroll) {
Expand Down