Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Ref, useEffect, useRef, useState } from 'react'
import { EuiFlexGroup, EuiFlexItem, keys } from '@elastic/eui'
import { useDispatch, useSelector } from 'react-redux'

import { Nullable } from 'uiSrc/utils'
import { Nullable, scrollIntoView } from 'uiSrc/utils'
import { isModifiedEvent } from 'uiSrc/services'
import { ClearCommand } from 'uiSrc/constants/cliOutput'
import { outputSelector } from 'uiSrc/slices/cli/cli-output'
Expand Down Expand Up @@ -41,7 +41,7 @@ const CliBody = (props: Props) => {

useEffect(() => {
inputEl?.focus()
scrollDivRef?.current?.scrollIntoView({
scrollIntoView(scrollDivRef?.current, {
behavior: 'smooth',
block: 'nearest',
inline: 'end',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Ref, useEffect, useRef } from 'react'
import cx from 'classnames'
import { EuiIcon, EuiTextColor } from '@elastic/eui'

import { scrollIntoView } from 'uiSrc/utils'
import styles from './styles.module.scss'

type Colors = 'default' | 'secondary' | 'accent' | 'warning' | 'danger' | 'subdued' | 'ghost'
Expand All @@ -19,7 +20,7 @@ const FieldMessage = ({ children, color, testID, icon, scrollViewOnAppear }: Pro
useEffect(() => {
// componentDidMount
if (scrollViewOnAppear) {
divRef?.current?.scrollIntoView({
scrollIntoView(divRef?.current, {
behavior: 'smooth',
block: 'nearest',
inline: 'end',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
removeMonacoComments,
splitMonacoValuePerLines,
getMultiCommands,
scrollIntoView,
} from 'uiSrc/utils'
import {
sendWBCommandAction,
Expand Down Expand Up @@ -165,7 +166,7 @@ const WBViewWrapper = () => {
}

const scrollResults = (inline: ScrollLogicalPosition = 'start') => {
scrollDivRef?.current?.scrollIntoView({
scrollIntoView(scrollDivRef?.current, {
behavior: 'smooth',
block: 'nearest',
inline,
Expand Down
1 change: 1 addition & 0 deletions redisinsight/ui/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from './monitorUtils'
export * from './handlePlatforms'
export * from './plugins'
export * from './redistack'
export * from './polyfills'

export {
Maybe,
Expand Down
12 changes: 12 additions & 0 deletions redisinsight/ui/src/utils/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Nullable } from './types'

const isScrollBehaviorSupported = (): boolean =>
'scrollBehavior' in globalThis.document.documentElement.style

export const scrollIntoView = (el: Nullable<HTMLDivElement>, opts?: ScrollIntoViewOptions) => {
if (el && isScrollBehaviorSupported()) {
el?.scrollIntoView(opts)
} else {
el?.scrollIntoView(true)
}
}
31 changes: 31 additions & 0 deletions redisinsight/ui/src/utils/tests/polyfills.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { scrollIntoView } from 'uiSrc/utils'

describe('scrollIntoView', () => {
it('should called with options for all browser except Safari', () => {
const mockScrollIntoView = jest.fn()
const opts: ScrollIntoViewOptions = {
behavior: 'smooth',
inline: 'end',
block: 'nearest',
}
const newDiv = document.createElement('div')
newDiv.scrollIntoView = mockScrollIntoView
scrollIntoView(newDiv, opts)
expect(mockScrollIntoView).toBeCalledWith(opts)
})

it('should called with "true" instead of options for Safari', () => {
const mockScrollIntoView = jest.fn()
const opts: ScrollIntoViewOptions = {
behavior: 'smooth',
inline: 'end',
block: 'nearest',
}

Object.defineProperty(global.document.documentElement, 'style', { value: {} })
const newDiv = document.createElement('div')
newDiv.scrollIntoView = mockScrollIntoView
scrollIntoView(newDiv, opts)
expect(mockScrollIntoView).toBeCalledWith(true)
})
})