From 467ab193d3e8bbb0476ea8648c96950a1a1f584e Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 23 Jan 2024 13:41:16 -0700 Subject: [PATCH] MM-51463 Only use RhsSuggestionList for RHS advanced text editor (#24175) * Only use RhsSuggestionList for RHS advanced text editor - Prevents issues with suggestion list growing downwards on the post editor on small screen sizes * Makes RhsSuggestionList grow using different breakpoints for mobile - Allows RhsSuggestionList to flip directions at smaller breakpoints than desktop - Adds new Constant MOBILE_SUGGESTION_LIST_SPACE_RHS --------- Co-authored-by: Nathan Geist Co-authored-by: M-ZubairAhmed Co-authored-by: Mattermost Build --- .../advanced_text_editor/advanced_text_editor.tsx | 3 ++- .../src/components/suggestion/rhs_suggestion_list.tsx | 10 +++++++--- webapp/channels/src/utils/constants.tsx | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx index 27a635f3da..d080b50a0e 100644 --- a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx +++ b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx @@ -26,6 +26,7 @@ import MessageSubmitError from 'components/message_submit_error'; import MsgTyping from 'components/msg_typing'; import OverlayTrigger from 'components/overlay_trigger'; import RhsSuggestionList from 'components/suggestion/rhs_suggestion_list'; +import SuggestionList from 'components/suggestion/suggestion_list'; import Textbox from 'components/textbox'; import type {TextboxElement} from 'components/textbox'; import type TextboxClass from 'components/textbox/textbox'; @@ -684,7 +685,7 @@ const AdvanceTextEditor = ({ {labels} & { export default function RhsSuggestionList(props: Props): JSX.Element { const [position, setPosition] = useState('top'); + const isMobile = useSelector(getIsMobileView); useEffect(() => { const input = props.inputRef.current; - if (input && props.open) { const inputTop = input.getBoundingClientRect().top ?? 0; - const newPosition = (inputTop < Constants.SUGGESTION_LIST_SPACE_RHS) ? 'bottom' : 'top'; + const requiredSpace = isMobile ? Constants.MOBILE_SUGGESTION_LIST_SPACE_RHS : Constants.SUGGESTION_LIST_SPACE_RHS; + const newPosition = (inputTop < requiredSpace) ? 'bottom' : 'top'; if (newPosition !== position) { // This potentially causes a second render when the list position changes, but that's better @@ -28,7 +32,7 @@ export default function RhsSuggestionList(props: Props): JSX.Element { setPosition(newPosition); } } - }, [position, props.inputRef, props.open]); + }, [position, props.inputRef, props.open, isMobile]); return (