Message List: Fix incorrect focus position when containing blockquotes (#5363)

This commit is contained in:
zubiden 2024-12-29 11:59:12 +01:00 committed by Alexander Zinchuk
parent a9649de412
commit 8a8aea1b4d
6 changed files with 46 additions and 21 deletions

View File

@ -5,14 +5,18 @@
width: 100%; width: 100%;
} }
.collapsed { .collapsed .blockquote {
@include mixins.gradient-border-bottom(1rem); max-height: 4lh;
} }
.gradientContainer { .gradientContainer {
margin-top: 0.125rem; margin-top: 0.125rem;
margin-bottom: 0.125rem; margin-bottom: 0.125rem;
max-height: inherit; max-height: inherit;
.collapsed & {
@include mixins.gradient-border-bottom(1rem);
}
} }
.collapseIcon { .collapseIcon {

View File

@ -40,12 +40,16 @@ const Blockquote = ({ canBeCollapsible, isToggleDisabled, children }: OwnProps)
}); });
return ( return (
<span className={styles.root} onClick={canExpand ? handleExpand : undefined}> <span
className={buildClassName(styles.root, isCollapsed && styles.collapsed)}
onClick={canExpand ? handleExpand : undefined}
>
<blockquote <blockquote
className={styles.blockquote}
ref={ref} ref={ref}
data-entity-type={ApiMessageEntityTypes.Blockquote} data-entity-type={ApiMessageEntityTypes.Blockquote}
> >
<div className={buildClassName(styles.gradientContainer, isCollapsed && styles.collapsed)}> <div className={styles.gradientContainer}>
{children} {children}
</div> </div>
{isCollapsible && ( {isCollapsible && (

View File

@ -136,7 +136,14 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
message.replyInfo?.type === 'message' ? message.replyInfo.replyToMsgId : undefined, message.replyInfo?.type === 'message' ? message.replyInfo.replyToMsgId : undefined,
targetMessage, targetMessage,
); );
useFocusMessage(ref, message.chatId, isFocused, focusDirection, noFocusHighlight, isJustAdded); useFocusMessage({
elementRef: ref,
chatId: message.chatId,
isFocused,
focusDirection,
noFocusHighlight,
isJustAdded,
});
useUnmountCleanup(() => { useUnmountCleanup(() => {
if (message.isPinned) { if (message.isPinned) {

View File

@ -832,17 +832,17 @@ const Message: FC<OwnProps & StateProps> = ({
replyStory, replyStory,
); );
useFocusMessage( useFocusMessage({
ref, elementRef: ref,
chatId, chatId,
isFocused, isFocused,
focusDirection, focusDirection,
noFocusHighlight, noFocusHighlight,
isResizingContainer, isResizingContainer,
isJustAdded, isJustAdded,
Boolean(focusedQuote), isQuote: Boolean(focusedQuote),
scrollTargetPosition, scrollTargetPosition,
); });
const viaBusinessBotTitle = viaBusinessBot ? getPeerTitle(lang, viaBusinessBot) : undefined; const viaBusinessBotTitle = viaBusinessBot ? getPeerTitle(lang, viaBusinessBot) : undefined;

View File

@ -14,17 +14,27 @@ const BOTTOM_FOCUS_OFFSET = 500;
const RELOCATED_FOCUS_OFFSET = SCROLL_MAX_DISTANCE; const RELOCATED_FOCUS_OFFSET = SCROLL_MAX_DISTANCE;
const FOCUS_MARGIN = 20; const FOCUS_MARGIN = 20;
export default function useFocusMessage( export default function useFocusMessage({
elementRef: { current: HTMLDivElement | null }, elementRef,
chatId: string, chatId,
isFocused?: boolean, isFocused,
focusDirection?: FocusDirection, focusDirection,
noFocusHighlight?: boolean, noFocusHighlight,
isResizingContainer?: boolean, isResizingContainer,
isJustAdded?: boolean, isJustAdded,
isQuote?: boolean, isQuote,
scrollTargetPosition?: ScrollTargetPosition, scrollTargetPosition,
) { }: {
elementRef: { current: HTMLDivElement | null };
chatId: string;
isFocused?: boolean;
focusDirection?: FocusDirection;
noFocusHighlight?: boolean;
isResizingContainer?: boolean;
isJustAdded?: boolean;
isQuote?: boolean;
scrollTargetPosition?: ScrollTargetPosition;
}) {
const isRelocatedRef = useRef(!isJustAdded); const isRelocatedRef = useRef(!isJustAdded);
useLayoutEffect(() => { useLayoutEffect(() => {

View File

@ -24,7 +24,7 @@ export default function useCollapsibleLines<T extends HTMLElement, C extends HTM
useLayoutEffect(() => { useLayoutEffect(() => {
const element = (cutoutRef || ref).current; const element = (cutoutRef || ref).current;
if (isDisabled || !element) return; if (isDisabled || !element || isFirstRenderRef.current) return;
requestMutation(() => { requestMutation(() => {
element.style.maxHeight = isCollapsed ? `${cutoutHeightRef.current}px` : ''; element.style.maxHeight = isCollapsed ? `${cutoutHeightRef.current}px` : '';