diff --git a/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx b/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx index 9e2b1f1ffcb..ac2b6a67efa 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx @@ -16,9 +16,11 @@ */ import classNames from 'classnames'; -import { isNil, lowerCase } from 'lodash'; +import { isNil, isUndefined, lowerCase } from 'lodash'; import React, { FunctionComponent, useEffect, useRef, useState } from 'react'; +import { useWindowDimensions } from '../../hooks/useWindowDimensions'; import { getCountBadge } from '../../utils/CommonUtils'; +import { getTopPosition } from '../../utils/DropDownUtils'; import { DropDownListItem, DropDownListProp } from './types'; const DropDownList: FunctionComponent = ({ @@ -30,10 +32,15 @@ const DropDownList: FunctionComponent = ({ value, onSelect, groupType = 'label', + domPosition, }: DropDownListProp) => { + const { height: windowHeight } = useWindowDimensions(); const isMounted = useRef(false); const [searchedList, setSearchedList] = useState(dropDownList); const [searchText, setSearchText] = useState(searchString); + const [dropDownPosition, setDropDownPosition] = useState< + { bottom: string } | {} + >({}); const setCurrentTabOnMount = () => { const selectedItem = dropDownList.find((l) => l.value === value); @@ -109,6 +116,14 @@ const DropDownList: FunctionComponent = ({ } }, [searchText]); + useEffect(() => { + if (!isUndefined(domPosition)) { + setDropDownPosition( + getTopPosition(windowHeight, domPosition.bottom, domPosition.height) + ); + } + }, [domPosition, searchText]); + useEffect(() => { setActiveTab(setCurrentTabOnMount()); isMounted.current = true; @@ -134,7 +149,8 @@ const DropDownList: FunctionComponent = ({ horzPosRight ? 'dd-horz-right' : 'dd-horz-left' )} data-testid="dropdown-list" - role="menu"> + role="menu" + style={dropDownPosition}> {showSearchBar && (
void; setIsOpen?: (value: boolean) => void; groupType?: GroupType; + domPosition?: DOMRect; }; export type DropDownProp = { diff --git a/catalog-rest-service/src/main/resources/ui/src/components/tags-container/tags-container.tsx b/catalog-rest-service/src/main/resources/ui/src/components/tags-container/tags-container.tsx index 421c3f0a82f..65b83ef00b4 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/tags-container/tags-container.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/tags-container/tags-container.tsx @@ -16,7 +16,7 @@ */ import classNames from 'classnames'; -import { capitalize, isEmpty } from 'lodash'; +import { capitalize, isEmpty, isNull } from 'lodash'; import { EntityTags } from 'Models'; import React, { FunctionComponent, useEffect, useRef, useState } from 'react'; import { Button } from '../buttons/Button/Button'; @@ -43,6 +43,7 @@ const TagsContainer: FunctionComponent = ({ const [hasFocus, setFocus] = useState(false); const inputRef = useRef(null); const node = useRef(null); + const [inputDomRect, setInputDomRect] = useState(); // const [inputWidth, setInputWidth] = useState(INPUT_COLLAPED); // const [inputMinWidth, setInputMinWidth] = useState(INPUT_AUTO); @@ -64,6 +65,12 @@ const TagsContainer: FunctionComponent = ({ } }; + useEffect(() => { + if (!isNull(inputRef.current)) { + setInputDomRect(inputRef.current.getBoundingClientRect()); + } + }, [newTag]); + const getTagList = () => { const newTags = tagList .filter((tag) => { @@ -227,6 +234,7 @@ const TagsContainer: FunctionComponent = ({ {newTag && ( { + function handleResize() { + setWindowDimensions(getWindowDimensions()); + } + + window.addEventListener('resize', handleResize); + + return () => window.removeEventListener('resize', handleResize); + }, []); + + return windowDimensions; +} diff --git a/catalog-rest-service/src/main/resources/ui/src/utils/DropDownUtils.ts b/catalog-rest-service/src/main/resources/ui/src/utils/DropDownUtils.ts new file mode 100644 index 00000000000..5c1c0401bcf --- /dev/null +++ b/catalog-rest-service/src/main/resources/ui/src/utils/DropDownUtils.ts @@ -0,0 +1,12 @@ +const BUFFER_VALUE = 200; +const GAP = 10; + +export const getTopPosition = ( + windowHeight: number, + bottomPosition: number, + elementHeight: number +) => { + const bottomSpace = windowHeight - (bottomPosition + BUFFER_VALUE); + + return bottomSpace < 0 ? { bottom: `${elementHeight + GAP}px` } : {}; +};