Skip to content

Commit 71a61d4

Browse files
AntonioABLimaCristhianzlcarlosrcoelhoautofix-ci[bot]
authored
fix: modal autofocus close button (#11425)
* fix: improve focus behavior in FlowLogsModal * fix: improve focus behavior in SaveChangesModal * refactor: extract onOpenAutoFocus handlers * check if element exists before prevent * [autofix.ci] apply automated fixes --------- Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com> Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 52479fb commit 71a61d4

6 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/frontend/src/modals/baseModal/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ interface BaseModalProps {
217217
type?: "modal" | "dialog" | "full-screen";
218218
onSubmit?: () => void;
219219
onEscapeKeyDown?: (e: KeyboardEvent) => void;
220+
onOpenAutoFocus?: (e: Event) => void;
220221
closeButtonClassName?: string;
221222
dialogContentWithouFixed?: boolean;
222223
}
@@ -230,6 +231,7 @@ function BaseModal({
230231
type = "dialog",
231232
onSubmit,
232233
onEscapeKeyDown,
234+
onOpenAutoFocus,
233235
closeButtonClassName,
234236
dialogContentWithouFixed = false,
235237
}: BaseModalProps) {
@@ -290,6 +292,7 @@ function BaseModal({
290292
<DialogContentWithouFixed
291293
onClick={(e) => e.stopPropagation()}
292294
onEscapeKeyDown={onEscapeKeyDown}
295+
onOpenAutoFocus={onOpenAutoFocus}
293296
className={contentClasses}
294297
closeButtonClassName={closeButtonClassName}
295298
>
@@ -311,6 +314,7 @@ function BaseModal({
311314
<DialogContent
312315
onClick={(e) => e.stopPropagation()}
313316
onEscapeKeyDown={onEscapeKeyDown}
317+
onOpenAutoFocus={onOpenAutoFocus}
314318
className={contentClasses}
315319
closeButtonClassName={closeButtonClassName}
316320
>

src/frontend/src/modals/confirmationModal/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function ConfirmationModal({
4141
index,
4242
onConfirm,
4343
open,
44+
onOpenAutoFocus,
4445
onClose,
4546
onCancel,
4647
...props
@@ -78,7 +79,12 @@ function ConfirmationModal({
7879
};
7980

8081
return (
81-
<BaseModal {...props} open={open} setOpen={setModalOpen}>
82+
<BaseModal
83+
{...props}
84+
open={open}
85+
setOpen={setModalOpen}
86+
onOpenAutoFocus={onOpenAutoFocus}
87+
>
8288
<BaseModal.Trigger>{triggerChild}</BaseModal.Trigger>
8389
<BaseModal.Header description={titleHeader ?? null}>
8490
<span className="pr-2">{title}</span>

src/frontend/src/modals/flowLogsModal/index.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,25 @@ export default function FlowLogsModal({
9090
}
9191
}, []);
9292

93+
const handleOpenAutoFocus = useCallback((e: Event) => {
94+
const viewport = document.querySelector(
95+
".ag-body-viewport",
96+
) as HTMLElement | null;
97+
if (viewport) {
98+
e.preventDefault();
99+
viewport.focus();
100+
}
101+
// If viewport doesn't exist (empty table), let default focus behavior happen
102+
}, []);
103+
93104
return (
94105
<>
95-
<BaseModal open={open} setOpen={setOpen} size="x-large">
106+
<BaseModal
107+
open={open}
108+
setOpen={setOpen}
109+
size="x-large"
110+
onOpenAutoFocus={handleOpenAutoFocus}
111+
>
96112
<BaseModal.Trigger asChild>{children}</BaseModal.Trigger>
97113
<BaseModal.Header description="Inspect component executions.">
98114
<div className="flex w-full justify-between">

src/frontend/src/modals/saveChangesModal/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { truncate } from "lodash";
2-
import { useState } from "react";
2+
import { useCallback, useState } from "react";
33
import ForwardedIconComponent from "@/components/common/genericIconComponent";
44
import Loading from "@/components/ui/loading";
55
import ConfirmationModal from "../confirmationModal";
@@ -20,6 +20,14 @@ export function SaveChangesModal({
2020
autoSave: boolean;
2121
}): JSX.Element {
2222
const [saving, setSaving] = useState(false);
23+
24+
const handleOpenAutoFocus = useCallback((e: Event) => {
25+
e.preventDefault();
26+
(
27+
document.querySelector('[data-testid="replace-button"]') as HTMLElement
28+
)?.focus();
29+
}, []);
30+
2331
return (
2432
<ConfirmationModal
2533
open={true}
@@ -42,6 +50,7 @@ export function SaveChangesModal({
4250
onCancel={onProceed}
4351
loading={autoSave ? true : saving}
4452
size="x-small"
53+
onOpenAutoFocus={handleOpenAutoFocus}
4554
>
4655
<ConfirmationModal.Content>
4756
{autoSave ? (

src/frontend/src/types/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ export type ConfirmationModalType = {
407407
| "small-h-full"
408408
| "medium-h-full";
409409
onEscapeKeyDown?: (e: KeyboardEvent) => void;
410+
onOpenAutoFocus?: (e: Event) => void;
410411
};
411412

412413
export type UserManagementType = {

src/frontend/tests/core/features/logs.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ test(
8989
await expect(
9090
page.getByText("timestamp", { exact: true }).last(),
9191
).toBeAttached();
92-
await expect(page.getByText("text", { exact: true }).last()).toBeAttached();
92+
await expect(
93+
page.getByText("files", { exact: true }).last(),
94+
).toBeAttached();
9395
await expect(
9496
page.getByText("sender", { exact: true }).last(),
9597
).toBeAttached();

0 commit comments

Comments
 (0)