Skip to content

fix: user mention item focused class #1360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 35 additions & 18 deletions src/ui/MentionLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Label, { LabelTypography, LabelColors } from '../Label';
import UserProfile from '../UserProfile';
import { classnames } from '../../utils/utils';
import useSendbird from '../../lib/Sendbird/context/hooks/useSendbird';
import { useUserProfileContext } from '../../lib/UserProfileContext';

interface MentionLabelProps {
mentionTemplate: string;
Expand All @@ -29,6 +30,7 @@ export default function MentionLabel(props: MentionLabelProps): JSX.Element {
isByMe,
} = props;

const { disableUserProfile, renderUserProfile } = useUserProfileContext();
const mentionRef = useRef<HTMLAnchorElement>();

const { state } = useSendbird();
Expand Down Expand Up @@ -62,7 +64,11 @@ export default function MentionLabel(props: MentionLabelProps): JSX.Element {
'sendbird-word__mention',
amIBeingMentioned && 'sendbird-word__mention--me',
)}
onClick={() => fetchUser(toggleDropdown)}
onClick={() => {
if (!disableUserProfile) {
fetchUser(toggleDropdown);
}
}}
ref={mentionRef}
data-userid={mentionedUserId}
data-nickname={mentionedUserNickname}
Expand All @@ -76,23 +82,34 @@ export default function MentionLabel(props: MentionLabelProps): JSX.Element {
</Label>
</a>
)}
menuItems={(closeDropdown: () => void): ReactElement => (
<MenuItems
/**
* parentRef: For catching location(x, y) of MenuItems
* parentContainRef: For toggling more options(menus & reactions)
*/
parentRef={mentionRef}
parentContainRef={mentionRef}
closeDropdown={closeDropdown}
style={{ paddingTop: '0px', paddingBottom: '0px' }}
>
<UserProfile
user={user}
onSuccess={closeDropdown}
currentUserId={userId}
/>
</MenuItems>
menuItems={(closeDropdown) => (
renderUserProfile
? (
renderUserProfile({
user,
close: closeDropdown,
currentUserId: userId,
avatarRef: mentionRef,
})
)
: (
<MenuItems
/**
* parentRef: For catching location(x, y) of MenuItems
* parentContainRef: For toggling more options(menus & reactions)
*/
parentRef={mentionRef}
parentContainRef={mentionRef}
closeDropdown={closeDropdown}
style={{ paddingTop: '0px', paddingBottom: '0px' }}
>
<UserProfile
user={user}
onSuccess={closeDropdown}
currentUserId={userId}
/>
</MenuItems>
)
)}
/>
);
Expand Down