Scrolls a particular option into the view.
(index: number)
| 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() { |
no test coverage detected