diff --git a/src/components/SelectV2.tsx b/src/components/SelectV2.tsx index 60e8d4ae92..ea18a5b388 100644 --- a/src/components/SelectV2.tsx +++ b/src/components/SelectV2.tsx @@ -22,7 +22,6 @@ const SelectWrapper = styled.div` padding: 12px; :hover { filter: brightness(1.2); - z-index: 10; } ` @@ -57,6 +56,7 @@ const SelectedWrap = styled.div` overflow: hidden; text-overflow: ellipsis; flex: 1; + user-select: none; ` export type SelectOption = { value?: string | number; label: ReactNode; onSelect?: () => void } @@ -88,6 +88,7 @@ function Select({ forceMenuPlacementTop = false, arrowColor, dropdownRender, + onHideMenu, }: { value?: string | number className?: string @@ -101,6 +102,7 @@ function Select({ onChange?: (value: any) => void forceMenuPlacementTop?: boolean arrowColor?: string + onHideMenu?: () => void // hide without changes }) { const [selected, setSelected] = useState(getOptionValue(options?.[0])) const [showMenu, setShowMenu] = useState(false) @@ -119,6 +121,7 @@ function Select({ useOnClickOutside(referenceElement as any, () => { setShowMenu(false) + onHideMenu?.() }) const selectedInfo = options.find(item => getOptionValue(item) === selected) const refMenu = useRef(null) @@ -159,7 +162,7 @@ function Select({ }) const updateCallback = useCallback(() => { - update && update() + update?.() }, [update]) useInterval(updateCallback, showMenu ? 100 : null) diff --git a/src/hooks/useOnClickOutside.tsx b/src/hooks/useOnClickOutside.tsx index c2e36f9218..e11b3985f2 100644 --- a/src/hooks/useOnClickOutside.tsx +++ b/src/hooks/useOnClickOutside.tsx @@ -19,7 +19,7 @@ export function useOnClickOutside( if (nodes.some(node => node.current?.contains(e.target as Node) ?? false)) { return } - if (handlerRef.current) handlerRef.current() + handlerRef.current?.() } document.addEventListener(isMobile ? 'touchstart' : 'mousedown', handleClickOutside) diff --git a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx b/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx index 3b9b3f6bc9..6be07bb188 100644 --- a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx +++ b/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx @@ -1,8 +1,8 @@ import { ChainId } from '@kyberswap/ks-sdk-core' import { Trans } from '@lingui/macro' import { rgba } from 'polished' -import { ReactNode, useState } from 'react' -import { Box, Flex, Text } from 'rebass' +import { ReactNode, useCallback, useEffect, useRef, useState } from 'react' +import { Box, Flex } from 'rebass' import styled, { CSSProperties } from 'styled-components' import { ReactComponent as LogoKyber } from 'assets/svg/logo_kyber.svg' @@ -57,6 +57,16 @@ const ChainWrapper = styled.div` border-radius: 999px; } ` + +const Label = styled.span` + font-weight: 500; + font-size: 14px; + line-height: 20x; + color: ${({ theme }) => theme.text}; + cursor: pointer; + user-select: none; +` + const MultipleChainSelect: React.FC = ({ className, style, ...props }) => { const { comingSoonList = [], selectedChainIds = [], handleChangeChains, chainIds = [], onTracking } = props const options = chainIds.map(id => ({ value: id, label: id })) @@ -78,20 +88,40 @@ const MultipleChainSelect: React.FC = ({ className, st } } + useEffect(() => { + setLocalSelectedChains(selectedChains) + // eslint-disable-next-line + }, [selectedChains.length]) + + const selectAllRef = useRef(null) + useEffect(() => { + if (!selectAllRef.current) { + return + } + selectAllRef.current.indeterminate = + 0 < localSelectedChains.length && localSelectedChains.length < networkList.length + }, [localSelectedChains, networkList.length]) + + const onHideMenu = useCallback(() => { + setLocalSelectedChains(selectedChains) + }, [selectedChains]) + return (