Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 30f4760

Browse files
owi92Amy Walker
authored andcommitted
Limit formatting bar offset to top of composer (#9365)
* Limit formatting bar offset to top of composer When highlighting larger sections in the composer, the formatting bar would scroll up and cover a previous post. This commit makes sure the bar's offset will be limited to the top of the composer. It should also make the code slightly more maintainable by getting the bar height from the DOMrect and basing the offset on that height instead of hardcoding it. Resolves: #12359
1 parent b2fa2cf commit 30f4760

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/views/rooms/MessageComposerFormatBar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ export default class MessageComposerFormatBar extends React.PureComponent<IProps
6666
this.setState({ visible: true });
6767
const parentRect = this.formatBarRef.current.parentElement.getBoundingClientRect();
6868
this.formatBarRef.current.style.left = `${selectionRect.left - parentRect.left}px`;
69-
// 16 is half the height of the bar (e.g. to center it) and 18 is an offset that felt ok.
70-
this.formatBarRef.current.style.top = `${selectionRect.top - parentRect.top - 16 - 18}px`;
69+
const halfBarHeight = this.formatBarRef.current.clientHeight / 2; // used to center the bar
70+
const offset = halfBarHeight + 2; // makes sure the bar won't cover selected text
71+
const offsetLimit = halfBarHeight + offset;
72+
const position = Math.max(selectionRect.top - parentRect.top - offsetLimit, -offsetLimit);
73+
this.formatBarRef.current.style.top = `${position}px`;
7174
}
7275

7376
public hide(): void {

0 commit comments

Comments
 (0)