fix: tags menu not opening

This commit is contained in:
Antonella Sgarlatta
2021-05-20 15:36:58 -03:00
parent 0b2665a01b
commit d826af7b55
4 changed files with 12 additions and 40 deletions

View File

@@ -31,8 +31,8 @@ const NotesContextMenu = observer(({ appState }: Props) => {
return appState.notes.contextMenuOpen ? (
<div
ref={contextMenuRef}
className="sn-dropdown max-w-80 flex flex-col py-2 overflow-y-scroll absolute"
style={{ ...appState.notes.contextMenuPosition, maxHeight: appState.notes.contextMenuMaxHeight }}
className="sn-dropdown max-w-80 flex flex-col py-2 absolute"
style={{ ...appState.notes.contextMenuPosition }}
>
<NotesOptions
appState={appState}

View File

@@ -161,7 +161,7 @@ export const NotesOptions = observer(
...tagsMenuPosition,
maxHeight: tagsMenuMaxHeight,
}}
className="sn-dropdown sn-dropdown-anchor-right flex flex-col py-2 max-h-80 overflow-y-scroll"
className="sn-dropdown sn-dropdown-anchor-right flex flex-col py-2 max-h-80 absolute overflow-y-scroll"
>
{appState.tags.tags.map((tag) => (
<button

View File

@@ -27,7 +27,6 @@ export class NotesState {
top: 0,
left: 0,
};
contextMenuMaxHeight: number | 'auto' = 'auto';
showProtectedWarning = false;
constructor(
@@ -46,7 +45,6 @@ export class NotesState {
setContextMenuOpen: action,
setContextMenuPosition: action,
setContextMenuMaxHeight: action,
setShowProtectedWarning: action,
unselectNotes: action,
});
@@ -183,10 +181,6 @@ export class NotesState {
this.contextMenuPosition = position;
}
setContextMenuMaxHeight(height: number | 'auto'): void {
this.contextMenuMaxHeight = height;
}
async changeSelectedNotes(
mutate: (mutator: NoteMutator) => void
): Promise<void> {

View File

@@ -314,10 +314,6 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
).fontSize;
const maxContextMenuHeight = parseFloat(defaultFontSize) * 20;
const footerHeight = 32;
// Open up-bottom is default behavior
let openUpBottom = true;
const bottomSpace = clientHeight - footerHeight - e.clientY;
const upSpace = e.clientY;
@@ -325,41 +321,23 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
if (maxContextMenuHeight > bottomSpace) {
// If there's enough space, open bottom-up
if (upSpace > maxContextMenuHeight) {
openUpBottom = false;
this.appState.notes.setContextMenuMaxHeight(
'auto'
);
// Else, reduce max height (menu will be scrollable) and open in whichever direction there's more space
this.appState.notes.setContextMenuPosition({
bottom: clientHeight - e.clientY,
left: e.clientX,
});
// Else, open on top of screen
} else {
if (upSpace > bottomSpace) {
this.appState.notes.setContextMenuMaxHeight(
upSpace - 2
);
openUpBottom = false;
} else {
this.appState.notes.setContextMenuMaxHeight(
bottomSpace - 2
);
}
this.appState.notes.setContextMenuPosition({
top: 2,
left: e.clientX,
});
}
} else {
this.appState.notes.setContextMenuMaxHeight(
'auto'
);
}
if (openUpBottom) {
this.appState.notes.setContextMenuPosition({
top: e.clientY,
left: e.clientX,
});
} else {
this.appState.notes.setContextMenuPosition({
bottom: clientHeight - e.clientY,
left: e.clientX,
});
}
this.appState.notes.setContextMenuOpen(true);
}
}