Skip to content

Commit

Permalink
fix(frontend): click on mention list on search bar in modal bug (#2098)
Browse files Browse the repository at this point in the history
# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
  • Loading branch information
Zewed authored Jan 27, 2024
1 parent 9fd56b5 commit 7a66af5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ export const MentionList = forwardRef<MentionListRef, MentionListProps>(
const { suggestionsRef, shouldShowScrollToBottomIcon, scrollToBottom } =
useSuggestionsOverflowHandler();

const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
event.stopPropagation();
};

return (
<div className="items flex flex-1 flex-col p-2 px-4 bg-gray-50 rounded-md shadow-md z-40 max-h-[200px]">
<div
className="items flex flex-1 flex-col p-2 px-4 bg-gray-50 rounded-md shadow-md z-40 max-h-[200px]"
onClick={handleClick}
>
<div
className="flex flex-1 flex-col overflow-y-auto"
ref={suggestionsRef}
Expand Down
3 changes: 1 addition & 2 deletions frontend/lib/components/SearchModal/SearchModal.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

.search_modal_wrapper {
display: flex;
background-color: Colors.$dark-black;
background-color: rgba(Colors.$dark-black, 0.94);
height: 100%;
width: 100%;
position: absolute;
z-index: ZIndexes.$modal;
opacity: 0.94;
align-items: center;
justify-content: center;

Expand Down
14 changes: 5 additions & 9 deletions frontend/lib/components/SearchModal/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ export const SearchModal = (): JSX.Element => {
const { isVisible, setIsVisible } = useSearchModalContext();
const searchBarRef = useRef(null);

useEffect(() => {
console.log(`isVisible has changed to: ${isVisible}`);
}, [isVisible]);

const keydownHandler = ({
key,
metaKey,
Expand All @@ -28,7 +24,7 @@ export const SearchModal = (): JSX.Element => {
}
};

const mousedownHandler = (event: MouseEvent) => {
const clickHandler = (event: MouseEvent) => {
if (
!(searchBarRef.current as HTMLElement | null)?.contains(
event.target as Node
Expand All @@ -43,12 +39,12 @@ export const SearchModal = (): JSX.Element => {
};

useEffect(() => {
document.addEventListener("keydown", keydownHandler);
window.addEventListener("click", mousedownHandler);
window.addEventListener("keydown", keydownHandler);
window.addEventListener("click", clickHandler);

return () => {
document.removeEventListener("keydown", keydownHandler);
window.removeEventListener("click", mousedownHandler);
window.removeEventListener("keydown", keydownHandler);
window.removeEventListener("click", clickHandler);
};
}, []);

Expand Down

0 comments on commit 7a66af5

Please sign in to comment.