Skip to content

Commit

Permalink
[FIX] toolbox menu behind thread component (#25925)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->

Add a container component to usePosition hook to prevent the menu be rendering outside the container.


Before:
<img width="686" alt="Screen Shot 2022-06-20 at 08 19 08" src="https://user-images.githubusercontent.com/9275105/174591999-15ef8f79-1064-4dd6-b9b1-acf9964b01c2.png">


After:
<img width="657" alt="Screen Shot 2022-06-22 at 10 56 19" src="https://user-images.githubusercontent.com/9275105/175048367-a45443de-9d83-40f8-a4b8-7f2c8be748c2.png">
  • Loading branch information
Filipe Marins authored Jun 23, 2022
1 parent 6b5b01a commit 25a04f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const MessageActionMenu: FC<{
[key: string]: MessageActionConfigOption[];
};

const messagesContainer = document.querySelector('.messages-container') || document.body;

return (
<MessageToolboxItem
ref={ref}
Expand All @@ -38,7 +40,7 @@ export const MessageActionMenu: FC<{
data-qa-type='message-action-menu'
>
{visible && (
<ToolboxDropdown reference={ref} {...rest}>
<ToolboxDropdown reference={ref} container={messagesContainer} {...rest}>
{Object.entries(groupOptions).map(([, options], index, arr) => (
<Fragment key={index}>
{options.map((option) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const style = css`
`;
export const ToolboxDropdown = <R extends HTMLElement>({
reference,
container,
children,
...rest
}: {
reference: React.RefObject<R>;
container: Element;
children: ReactNode;
}): ReactElement => {
const { isMobile } = useLayout();
Expand All @@ -27,7 +29,7 @@ export const ToolboxDropdown = <R extends HTMLElement>({
return (
<>
<Box className={style} position='fixed' />
<DropdownTemplate ref={target} reference={reference} {...rest}>
<DropdownTemplate ref={target} reference={reference} container={container} {...rest}>
{children}
</DropdownTemplate>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export const ToolboxDropdownDesktop = forwardRef<
{
reference: RefObject<HTMLElement>;
children: ReactNode;
container: Element;
}
>(function ToolboxDropdownDesktop({ reference, children, ...rest }, ref) {
>(function ToolboxDropdownDesktop({ reference, container, children, ...rest }, ref) {
const { style: s } = usePosition(reference, ref as RefObject<HTMLElement>, {
watch: true,
placement: 'bottom-end',
container,
});

return (
Expand Down

0 comments on commit 25a04f9

Please sign in to comment.