Skip to content

Commit

Permalink
feat: clicking on tag sets it as active
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonella Sgarlatta committed May 31, 2021
1 parent 6038f3e commit bf1fba9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/assets/javascripts/components/NoteTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const NoteTags = observer(({ application, appState }: Props) => {
}
};

const onTagClick = (clickedTag: SNTag) => {
const tagIndex = tags.findIndex(tag => tag.uuid === clickedTag.uuid);
if (tagsRef.current[tagIndex] === document.activeElement) {
appState.setSelectedTag(clickedTag);
}
};

const isTagOverflowed = useCallback(
(tagElement?: HTMLButtonElement): boolean | undefined => {
if (!tagElement) {
Expand Down Expand Up @@ -99,8 +106,8 @@ const NoteTags = observer(({ application, appState }: Props) => {
appState.activeNote.setOverflowedTagsCount(count);
}, [appState.activeNote, isTagOverflowed]);

const setTagsContainerExpanded = (expanded: boolean) => {
appState.activeNote.setTagsContainerExpanded(expanded);
const expandTags = () => {
appState.activeNote.setTagsContainerExpanded(true);
};

useEffect(() => {
Expand Down Expand Up @@ -144,6 +151,7 @@ const NoteTags = observer(({ application, appState }: Props) => {
tagsRef.current[index] = element;
}
}}
onClick={() => onTagClick(tag)}
onKeyUp={(event) => {
if (event.key === 'Backspace') {
onTagBackspacePress(tag);
Expand Down Expand Up @@ -173,9 +181,7 @@ const NoteTags = observer(({ application, appState }: Props) => {
type="button"
className={`${tagClass} pl-2 absolute`}
style={{ left: overflowCountPosition }}
onClick={() => {
setTagsContainerExpanded(true);
}}
onClick={expandTags}
>
+{overflowedTagsCount}
</button>
Expand Down

0 comments on commit bf1fba9

Please sign in to comment.