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: Modal ocasionally not focusing properly making input unusable #34853

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/moody-foxes-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixes an issue where opening a modal for the first times renders it's inputs unusable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fixes an issue where opening a modal for the first times renders it's inputs unusable
Fixes an issue where opening a modal for the first times renders it's inputs unusable

15 changes: 13 additions & 2 deletions apps/meteor/client/views/root/MainLayout/LayoutWithSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Box } from '@rocket.chat/fuselage';
import { useLayout, useSetting, useCurrentModal, useRoute, useCurrentRoutePath } from '@rocket.chat/ui-contexts';
import type { ReactElement, ReactNode } from 'react';
import { useEffect, useRef } from 'react';
import { useEffect, useRef, version } from 'react';

import AccessibilityShortcut from './AccessibilityShortcut';
import { MainLayoutStyleTags } from './MainLayoutStyleTags';
import Sidebar from '../../../sidebar';

const inertBooleanSupported = Number(version.split('.')[0]) >= 19;

/**
* Before version 19, react JSX treats empty string "" as truthy for inert prop.
* @see {@link https://stackoverflow.com/questions/72720469}
* */
const isInert = inertBooleanSupported ? (x: boolean) => x : (x: boolean) => (x ? '' : undefined);

Comment on lines +10 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will need to be replicated to LayoutSidebarV2. It might be a good idea to have this as an util and use it in both files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that guy 😬

const LayoutWithSidebar = ({ children }: { children: ReactNode }): ReactElement => {
const { isEmbedded: embeddedLayout } = useLayout();

Expand Down Expand Up @@ -44,7 +52,10 @@ const LayoutWithSidebar = ({ children }: { children: ReactNode }): ReactElement
bg='surface-light'
id='rocket-chat'
className={[embeddedLayout ? 'embedded-view' : undefined, 'menu-nav'].filter(Boolean).join(' ')}
aria-hidden={Boolean(modal)}
// @types/react does not recognize the "inert" prop as of now
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
inert={isInert(Boolean(modal))}
>
<AccessibilityShortcut />
<MainLayoutStyleTags />
Expand Down
Loading