fix: check if ref is present before setting overflow position

This commit is contained in:
Antonella Sgarlatta
2021-06-01 19:50:03 -03:00
parent af3bed850e
commit a071d4c9d0
2 changed files with 6 additions and 4 deletions

View File

@@ -97,9 +97,11 @@ const NoteTags = observer(({ application, appState }: Props) => {
if (tagsContainerExpanded || !lastVisibleTagIndex) {
return;
}
const { offsetLeft: lastVisibleTagLeft, clientWidth: lastVisibleTagWidth } =
if (tagsRef.current[lastVisibleTagIndex]) {
const { offsetLeft: lastVisibleTagLeft, clientWidth: lastVisibleTagWidth } =
tagsRef.current[lastVisibleTagIndex];
setOverflowCountPosition(lastVisibleTagLeft + lastVisibleTagWidth);
setOverflowCountPosition(lastVisibleTagLeft + lastVisibleTagWidth);
}
}, [lastVisibleTagIndex, tagsContainerExpanded]);
const expandTags = () => {
@@ -142,7 +144,7 @@ const NoteTags = observer(({ application, appState }: Props) => {
tagResizeObserver.disconnect();
}
};
}, [reloadTagsContainerLayout]);
}, [reloadTagsContainerLayout, tags]);
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`;

View File

@@ -14,7 +14,7 @@ import { AppState } from './app_state';
export class ActiveNoteState {
tags: SNTag[] = [];
tagsContainerMaxWidth: number | 'auto' = 'auto';
tagsContainerMaxWidth: number | 'auto' = 0;
tagsContainerExpanded = false;
overflowedTagsCount = 0;