Skip to content
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

fix(web): scroll to current selected item in mention list #711

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ReactRendererOptions } from '@tiptap/react'
import { clsx } from 'clsx'
import {
forwardRef, useEffect, useImperativeHandle,
useRef,
useState,
} from 'react'

Expand Down Expand Up @@ -81,10 +82,16 @@ export default forwardRef((props: ReactRendererOptions['props'], ref) => {

const MentionItem = ({ item, index, selectItem, selectedIndex, itemsLength }: { itemsLength: number, selectedIndex: number, index: number, item: ChannelListItem, selectItem: (index: number) => void }) => {

const ref = useRef<HTMLDivElement>(null)

useEffect(() => {
if (index === selectedIndex) ref.current?.scrollIntoView({ block: 'nearest' })
}, [selectedIndex, index])

return <Flex
role='button'
align='center'
ref={ref}
title={item.channel_name}
aria-label={`Mention channel ${item.channel_name}`}
className={clsx('px-3 py-2 gap-2 rounded-md',
Expand Down
10 changes: 9 additions & 1 deletion raven-app/src/components/feature/chat/ChatInput/MentionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ReactRendererOptions } from '@tiptap/react'
import { clsx } from 'clsx'
import {
forwardRef, useEffect, useImperativeHandle,
useRef,
useState,
} from 'react'

Expand Down Expand Up @@ -61,7 +62,7 @@ export default forwardRef((props: ReactRendererOptions['props'], ref) => {
<Flex
direction='column'
gap='0'
className='shadow-lg dark:backdrop-blur-[8px] dark:bg-panel-translucent bg-white overflow-y-scroll max-h-64 rounded-md'
className='shadow-lg dark:backdrop-blur-[8px] dark:bg-panel-translucent bg-white overflow-y-scroll max-h-96 rounded-md'
>
{props?.items.length
? props.items.map((item: UserFields, index: number) => (
Expand All @@ -85,9 +86,16 @@ const MentionItem = ({ item, index, selectItem, selectedIndex, itemsLength }: {

const isActive = useIsUserActive(item.name)

const ref = useRef<HTMLDivElement>(null)

useEffect(() => {
if (index === selectedIndex) ref.current?.scrollIntoView({ block: 'nearest' })
}, [selectedIndex, index])


return <Flex
role='button'
ref={ref}
align='center'
title={item.full_name}
aria-label={`Mention ${item.full_name}`}
Expand Down
Loading