MCPcopy Create free account
hub / github.com/angular/components / _scrollOptionIntoView

Method _scrollOptionIntoView

src/material/select/select.ts:258–280  ·  view source on GitHub ↗

Scrolls a particular option into the view.

(index: number)

Source from the content-addressed store, hash-verified

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

Callers 2

_positioningSettledMethod · 0.95
_initKeyManagerMethod · 0.95

Calls 3

_getOptionScrollPositionFunction · 0.90
_getHostElementMethod · 0.45

Tested by

no test coverage detected