mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 13:20:19 +03:00
Always use alternate implementation of scrollIntoViewIfNeeded
Refs #1714 Refs #1742
This commit is contained in:
parent
86cef81e9c
commit
546e7a768a
|
@ -7,6 +7,7 @@ import { shortenHTTPVerb } from '../../utils/openapi';
|
|||
import { MenuItems } from './MenuItems';
|
||||
import { MenuItemLabel, MenuItemLi, MenuItemTitle, OperationBadge } from './styled.elements';
|
||||
import { l } from '../../services/Labels';
|
||||
import { scrollIntoViewIfNeeded } from '../../utils';
|
||||
|
||||
export interface MenuItemProps {
|
||||
item: IMenuItem;
|
||||
|
@ -33,7 +34,7 @@ export class MenuItem extends React.Component<MenuItemProps> {
|
|||
|
||||
scrollIntoViewIfActive() {
|
||||
if (this.props.item.active && this.ref.current) {
|
||||
this.ref.current.scrollIntoViewIfNeeded();
|
||||
scrollIntoViewIfNeeded(this.ref.current);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,7 @@ export class OperationMenuItemContent extends React.Component<OperationMenuItemC
|
|||
|
||||
componentDidUpdate() {
|
||||
if (this.props.item.active && this.ref.current) {
|
||||
this.ref.current.scrollIntoViewIfNeeded();
|
||||
scrollIntoViewIfNeeded(this.ref.current);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ export class SideMenu extends React.Component<{ menu: MenuStore; className?: str
|
|||
if (item && item.active && this.context.menuToggle) {
|
||||
return item.expanded ? item.collapse() : item.expand();
|
||||
}
|
||||
|
||||
this.props.menu.activateAndScroll(item, true);
|
||||
setTimeout(() => {
|
||||
if (this._updateScroll) {
|
||||
|
|
|
@ -24,7 +24,10 @@ export function html2Str(html: string): string {
|
|||
.join(' ');
|
||||
}
|
||||
|
||||
// scrollIntoViewIfNeeded polyfill
|
||||
// Alternate scrollIntoViewIfNeeded implementation.
|
||||
// Used in all cases, since it seems Chrome's implementation is buggy
|
||||
// when "Experimental Web Platform Features" is enabled (at least of version 96).
|
||||
// See #1714, #1742
|
||||
|
||||
export function scrollIntoViewIfNeeded(el: HTMLElement, centerIfNeeded = true) {
|
||||
const parent = el.parentNode as HTMLElement | null;
|
||||
|
@ -72,9 +75,3 @@ export function scrollIntoViewIfNeeded(el: HTMLElement, centerIfNeeded = true) {
|
|||
el.scrollIntoView(alignWithTop);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof Element !== 'undefined' && !(Element as any).prototype.scrollIntoViewIfNeeded) {
|
||||
(Element as any).prototype.scrollIntoViewIfNeeded = function (centerIfNeeded = true) {
|
||||
scrollIntoViewIfNeeded(this, centerIfNeeded);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user