diff --git a/datahub-web-react/src/app/search/filters/MoreFilterOption.tsx b/datahub-web-react/src/app/search/filters/MoreFilterOption.tsx index 9c04137444038..5012f8c645d17 100644 --- a/datahub-web-react/src/app/search/filters/MoreFilterOption.tsx +++ b/datahub-web-react/src/app/search/filters/MoreFilterOption.tsx @@ -1,13 +1,13 @@ import { RightOutlined } from '@ant-design/icons'; import { Dropdown } from 'antd'; import styled from 'styled-components'; -import React from 'react'; +import React, { useRef } from 'react'; import { FacetFilterInput, FacetMetadata } from '../../../types.generated'; import { capitalizeFirstLetterOnly } from '../../shared/textUtil'; import OptionsDropdownMenu from './OptionsDropdownMenu'; import useSearchFilterDropdown from './useSearchFilterDropdown'; import { IconWrapper } from './SearchFilterView'; -import { getFilterDropdownIcon } from './utils'; +import { getFilterDropdownIcon, useElementDimensions } from './utils'; import { MoreFilterOptionLabel } from './styledComponents'; const IconNameWrapper = styled.span` @@ -22,6 +22,9 @@ interface Props { } export default function MoreFilterOption({ filter, activeFilters, onChangeFilters }: Props) { + const labelRef = useRef(null); + const { width, height } = useElementDimensions(labelRef); + const { isMenuOpen, updateIsMenuOpen, @@ -46,17 +49,18 @@ export default function MoreFilterOption({ filter, activeFilters, onChangeFilter onOpenChange={(open) => updateIsMenuOpen(open)} dropdownRender={(menu) => ( )} > updateIsMenuOpen(!isMenuOpen)} isActive={!!numActiveFilters} isOpen={isMenuOpen} diff --git a/datahub-web-react/src/app/search/filters/OptionsDropdownMenu.tsx b/datahub-web-react/src/app/search/filters/OptionsDropdownMenu.tsx index 9302b908d8a1b..13196af5ef85b 100644 --- a/datahub-web-react/src/app/search/filters/OptionsDropdownMenu.tsx +++ b/datahub-web-react/src/app/search/filters/OptionsDropdownMenu.tsx @@ -1,6 +1,6 @@ import { LoadingOutlined } from '@ant-design/icons'; import { Button } from 'antd'; -import React from 'react'; +import React, { CSSProperties } from 'react'; import styled from 'styled-components/macro'; import { useEntityRegistry } from '../../useEntityRegistry'; import { SearchBar } from '../SearchBar'; @@ -14,21 +14,13 @@ const StyledButton = styled(Button)` border-radius: 0; `; -export const DropdownMenu = styled.div<{ alignRight?: boolean }>` +export const DropdownMenu = styled.div` background-color: white; border-radius: 5px; box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 9px 28px 8px rgba(0, 0, 0, 0.05); overflow: hidden; min-width: 200px; - ${(props) => - props.alignRight && - ` - position: absolute; - left: 205px; - top: -34px; - `} - .ant-dropdown-menu-title-content { background-color: white; &:hover { @@ -59,8 +51,8 @@ interface Props { isLoading: boolean; searchQuery: string; updateSearchQuery: (query: string) => void; - alignRight?: boolean; searchPlaceholder?: string; + style?: CSSProperties; } export default function OptionsDropdownMenu({ @@ -69,15 +61,15 @@ export default function OptionsDropdownMenu({ isLoading, searchQuery, updateSearchQuery, - alignRight, searchPlaceholder, + style, }: Props) { const entityRegistry = useEntityRegistry(); useEnterKeyListener({ querySelectorToExecuteClick: '#updateFiltersButton' }); return ( - + (initialSelected); + const labelRef = useRef(null); + const { width, height } = useElementDimensions(labelRef); function updateSelected() { onUpdate(isSelected); @@ -56,10 +59,15 @@ export default function BooleanMoreFilter({ icon, title, option, count, initialS open={isMenuOpen} onOpenChange={(open) => setIsMenuOpen(open)} dropdownRender={(menuOption) => ( - + )} > setIsMenuOpen(!isMenuOpen)} isOpen={isMenuOpen} isActive={isSelected} diff --git a/datahub-web-react/src/app/search/filters/render/shared/BooleanMoreFilterMenu.tsx b/datahub-web-react/src/app/search/filters/render/shared/BooleanMoreFilterMenu.tsx index acab6af06074c..72309cecdc2c0 100644 --- a/datahub-web-react/src/app/search/filters/render/shared/BooleanMoreFilterMenu.tsx +++ b/datahub-web-react/src/app/search/filters/render/shared/BooleanMoreFilterMenu.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { CSSProperties } from 'react'; import { Button } from 'antd'; import styled from 'styled-components/macro'; @@ -10,21 +10,13 @@ const StyledButton = styled(Button)` border-radius: 0; `; -export const DropdownMenu = styled.div<{ alignRight?: boolean }>` +export const DropdownMenu = styled.div` background-color: white; border-radius: 5px; box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 9px 28px 8px rgba(0, 0, 0, 0.05); overflow: hidden; min-width: 200px; - ${(props) => - props.alignRight && - ` - position: absolute; - left: 205px; - top: -34px; - `} - .ant-dropdown-menu-title-content { background-color: white; &:hover { @@ -41,12 +33,12 @@ const ScrollableContent = styled.div` interface Props { menuOption: React.ReactNode; onUpdate: () => void; - alignRight?: boolean; + style?: CSSProperties; } -export default function BooleanMoreFilterMenu({ menuOption, onUpdate, alignRight }: Props) { +export default function BooleanMoreFilterMenu({ menuOption, onUpdate, style }: Props) { return ( - + {React.cloneElement(menuOption as React.ReactElement, { style: { boxShadow: 'none' } })} diff --git a/datahub-web-react/src/app/search/filters/utils.tsx b/datahub-web-react/src/app/search/filters/utils.tsx index 998357836d12b..401b685732667 100644 --- a/datahub-web-react/src/app/search/filters/utils.tsx +++ b/datahub-web-react/src/app/search/filters/utils.tsx @@ -8,7 +8,7 @@ import { TagOutlined, UserOutlined, } from '@ant-design/icons'; -import React from 'react'; +import React, { useLayoutEffect, useState } from 'react'; import styled from 'styled-components'; import { AggregationMetadata, @@ -346,3 +346,27 @@ export function getParentEntities(entity: Entity): Entity[] | null { } return null; } + +/** + * Utility function to get the dimensions of a DOM element. + * @param {React.MutableRefObject} ref - Reference to the DOM element. + * @returns {Object} - Object containing width and height of the element. + */ +export function useElementDimensions(ref) { + const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); + + useLayoutEffect(() => { + const updateDimensions = () => { + if (ref.current) { + setDimensions({ + width: ref.current.offsetWidth, + height: ref.current.offsetHeight, + }); + } + }; + + updateDimensions(); + }, [ref]); + + return dimensions; +} \ No newline at end of file