MCPcopy Index your code
hub / github.com/angular/components / _scrollOptionIntoView

Method _scrollOptionIntoView

src/material/select/select.ts:257–279  ·  view source on GitHub ↗

Scrolls a particular option into the view.

(index: number)

Source from the content-addressed store, hash-verified

255
256 /** Scrolls a particular option into the view. */
257 _scrollOptionIntoView(index: number): void {
258 const option = this.options.toArray()[index];
259
260 if (option) {
261 const panel: HTMLElement = this.panel.nativeElement;
262 const labelCount = _countGroupLabelsBeforeOption(index, this.options, this.optionGroups);
263 const element = option._getHostElement();
264
265 if (index === 0 && labelCount === 1) {
266 // If we've got one group label before the option and we're at the top option,
267 // scroll the list to the top. This is better UX than scrolling the list to the
268 // top of the option, because it allows the user to read the top group's label.
269 panel.scrollTop = 0;
270 } else {
271 panel.scrollTop = _getOptionScrollPosition(
272 element.offsetTop,
273 element.offsetHeight,
274 panel.scrollTop,
275 panel.offsetHeight,
276 );
277 }
278 }
279 }
280
281 /** Called when the panel has been opened and the overlay has settled on its final position. */
282 private _positioningSettled() {

Callers 2

_positioningSettledMethod · 0.95
_initKeyManagerMethod · 0.95

Calls 3

_getOptionScrollPositionFunction · 0.90
_getHostElementMethod · 0.45

Tested by

no test coverage detected