From 31fbf2ce35f860050fb95f595d290e491ecf1263 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Mon, 31 May 2021 19:26:26 -0300 Subject: [PATCH] fix: fix tags dropdown width and tags container height --- .../components/AutocompleteTagInput.tsx | 4 +-- .../javascripts/components/NoteTags.tsx | 27 +++++++++++++------ app/assets/stylesheets/_sn.scss | 8 ++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/components/AutocompleteTagInput.tsx b/app/assets/javascripts/components/AutocompleteTagInput.tsx index 413b85c42..0ae19226a 100644 --- a/app/assets/javascripts/components/AutocompleteTagInput.tsx +++ b/app/assets/javascripts/components/AutocompleteTagInput.tsx @@ -99,7 +99,7 @@ export const AutocompleteTagInput: FunctionalComponent = ({ = ({ {dropdownVisible && (
diff --git a/app/assets/javascripts/components/NoteTags.tsx b/app/assets/javascripts/components/NoteTags.tsx index ce9ad8de1..6a071eb5d 100644 --- a/app/assets/javascripts/components/NoteTags.tsx +++ b/app/assets/javascripts/components/NoteTags.tsx @@ -26,6 +26,8 @@ const NoteTags = observer(({ application, appState }: Props) => { tagsOverflowed, } = appState.activeNote; + const [containerHeight, setContainerHeight] = + useState(TAGS_ROW_HEIGHT); const [tagsContainerHeight, setTagsContainerHeight] = useState(TAGS_ROW_HEIGHT); const [overflowCountPosition, setOverflowCountPosition] = useState(0); @@ -76,11 +78,18 @@ const NoteTags = observer(({ application, appState }: Props) => { setOverflowCountPosition(position); }, [isTagOverflowed, tagsContainerExpanded, tagsContainerPosition]); - const reloadTagsContainerHeight = useCallback(() => { - const height = tagsContainerExpanded + const reloadContainersHeight = useCallback(() => { + const containerHeight = tagsContainerExpanded ? tagsContainerRef.current.scrollHeight : TAGS_ROW_HEIGHT; - setTagsContainerHeight(height); + setContainerHeight(containerHeight); + + const firstTagTop = tagsRef.current[0].getBoundingClientRect().top; + const lastTagBottom = tagsRef.current[tagsRef.current.length - 1].getBoundingClientRect().bottom; + const tagsContainerHeight = tagsContainerExpanded + ? lastTagBottom - firstTagTop + : TAGS_ROW_HEIGHT; + setTagsContainerHeight(tagsContainerHeight); }, [tagsContainerExpanded]); const reloadOverflowCount = useCallback(() => { @@ -97,28 +106,30 @@ const NoteTags = observer(({ application, appState }: Props) => { useEffect(() => { appState.activeNote.reloadTagsContainerLayout(); reloadOverflowCountPosition(); - reloadTagsContainerHeight(); + reloadContainersHeight(); reloadOverflowCount(); }, [ appState.activeNote, reloadOverflowCountPosition, - reloadTagsContainerHeight, + reloadContainersHeight, reloadOverflowCount, tags, ]); - const tagClass = `bg-contrast border-0 rounded text-xs color-text py-1 pr-2 flex items-center + const tagClass = `h-6 bg-contrast border-0 rounded text-xs color-text py-1 pr-2 flex items-center mt-2 cursor-pointer hover:bg-secondary-contrast focus:bg-secondary-contrast`; return (