diff --git a/src/common/utility.js b/src/common/utility.js index d9107cb68c3..4531dd9963f 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -347,3 +347,10 @@ export const slugify = (text) => .replace(/\s+/g, '-') // Replace spaces with - .replace(/[^\w-]+/g, '') // Remove all non-word chars .replace(/--+/g, '-') // Replace multiple - with single - + +export const getBaseRef = (ref) => { + // this is intended to solve a problem of preact that + // in some cases element api's are in the ref.current.base and + // in other cases they are in ref.current + return ref?.current?.base?.style ? ref?.current?.base : ref?.current +} diff --git a/src/components/layout/nav.js b/src/components/layout/nav.js index b6dcc925095..cc140578941 100644 --- a/src/components/layout/nav.js +++ b/src/components/layout/nav.js @@ -25,6 +25,7 @@ import { getLanguage, getDerivAppLocalizedURL, redirectToTradingPlatform, + getBaseRef, } from 'common/utility' // Icons import Logo from 'images/svg/layout/logo-deriv.svg' @@ -213,18 +214,20 @@ const NavRight = styled.div` }}; transform: translateX( ${(props) => { + const ref_base = getBaseRef(props.button_ref) + if (props.hide_signup_login) { return 0 } else if (props.move && !props.hide_signup_login) { - if (props.button_ref.current && props.mounted) { - props.button_ref.current.style.opacity = 1 + if (ref_base && props.mounted) { + ref_base.style.opacity = 1 } return 0 } else { - if (props.button_ref.current && props.mounted) { - props.button_ref.current.style.opacity = 0 + if (ref_base && props.mounted) { + ref_base.style.opacity = 0 - const calculation = props.button_ref.current.offsetWidth + 2 + const calculation = ref_base.offsetWidth + 2 return `${calculation}px` } return '300px' @@ -843,16 +846,17 @@ const StyledNavRight = styled(NavRight)` margin-left: auto; transform: translateX( ${(props) => { + const ref_base = getBaseRef(props.button_ref) if (props.move) { - if (props.button_ref.current && props.mounted) { - props.button_ref.current.style.opacity = 1 + if (ref_base && props.mounted) { + ref_base.style.opacity = 1 } return '50px' } else { - if (props.button_ref.current && props.mounted) { - props.button_ref.current.style.opacity = 0 + if (ref_base && props.mounted) { + ref_base.style.opacity = 0 - const calculation = props.button_ref.current.offsetWidth + 50 + const calculation = ref_base.offsetWidth + 50 return `${calculation}px` } return '225px'