From 4308f4e656d51e517a389aea5c6d6a6f6275c4cc Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Wed, 5 May 2021 15:31:34 -0300 Subject: [PATCH] fix: hide add tag options if no tags available --- .../javascripts/components/NotesOptions.tsx | 118 +++++++++--------- .../ui_models/app_state/tags_state.ts | 9 +- 2 files changed, 68 insertions(+), 59 deletions(-) diff --git a/app/assets/javascripts/components/NotesOptions.tsx b/app/assets/javascripts/components/NotesOptions.tsx index 67c5eb17d..6caa20412 100644 --- a/app/assets/javascripts/components/NotesOptions.tsx +++ b/app/assets/javascripts/components/NotesOptions.tsx @@ -68,66 +68,68 @@ export const NotesOptions = observer(
- { - const buttonRect = tagsButtonRef.current.getBoundingClientRect(); - const { offsetTop, offsetWidth } = tagsButtonRef.current; - setTagsMenuPosition({ - top: offsetTop, - right: - buttonRect.right + 265 > document.body.clientWidth - ? offsetWidth - : -offsetWidth, - }); - setTagsMenuOpen(!tagsMenuOpen); - }} - > - { - if (event.key === 'Escape') { - setTagsMenuOpen(false); - } + {appState.tags.tagsCount > 0 && ( + { + const buttonRect = tagsButtonRef.current.getBoundingClientRect(); + const { offsetTop, offsetWidth } = tagsButtonRef.current; + setTagsMenuPosition({ + top: offsetTop, + right: + buttonRect.right + 265 > document.body.clientWidth + ? offsetWidth + : -offsetWidth, + }); + setTagsMenuOpen(!tagsMenuOpen); }} - onBlur={closeOnBlur} - ref={tagsButtonRef} - className={`${buttonClass} justify-between`} > -
- - {'Add tag'} -
- -
- { - if (event.key === 'Escape') { - setTagsMenuOpen(false); - tagsButtonRef.current.focus(); - } - }} - style={{ - ...tagsMenuPosition, - }} - className="sn-dropdown sn-dropdown-anchor-right flex flex-col py-2 max-w-265px max-h-80 overflow-y-scroll" - > - {appState.tags.tags.map((tag) => ( - - ))} - -
+ { + if (event.key === 'Escape') { + setTagsMenuOpen(false); + } + }} + onBlur={closeOnBlur} + ref={tagsButtonRef} + className={`${buttonClass} justify-between`} + > +
+ + {'Add tag'} +
+ +
+ { + if (event.key === 'Escape') { + setTagsMenuOpen(false); + tagsButtonRef.current.focus(); + } + }} + style={{ + ...tagsMenuPosition, + }} + className="sn-dropdown sn-dropdown-anchor-right flex flex-col py-2 max-w-265px max-h-80 overflow-y-scroll" + > + {appState.tags.tags.map((tag) => ( + + ))} + + + )}