Skip to content

Commit 34867c1

Browse files
committed
fix: restore focus for the audit drawer and the reset dialog after its trigger unmounts
A successful base reset clears the last database override, which unmounts the header Reset button before the dialog closes, so the reset dialog now receives the same page container fallback ConfirmSaveDialog already uses. The audit detail drawer's four raw Radix content branches had neither a trigger nor onCloseAutoFocus and now share one useReturnFocus wiring, and the hook test moves under __tests__ per the repo convention.
1 parent ffde702 commit 34867c1

5 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/components/configuration/ConfigPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ export function ConfigPage({ initialTab, highlightField, initialScope }: t.Confi
10681068
open={resetBaseOpen}
10691069
resetting={resettingBase}
10701070
error={resetBaseError}
1071+
fallbackRef={saveFallbackRef}
10711072
onConfirm={handleResetBaseConfig}
10721073
onCancel={() => {
10731074
if (resettingBase) return;

src/components/configuration/ResetBaseConfigDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ export function ResetBaseConfigDialog({
66
open,
77
resetting,
88
error,
9+
fallbackRef,
910
onConfirm,
1011
onCancel,
1112
}: t.ResetBaseConfigDialogProps) {
1213
const localize = useLocalize();
13-
const returnFocus = useReturnFocus(open);
14+
const returnFocus = useReturnFocus(open, fallbackRef);
1415

1516
return (
1617
<Dialog

src/components/grants/AuditLogDetailDrawer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from './auditLogUtils';
1414
import { LoadingState } from '@/components/shared';
1515
import { getScopeTypeConfig } from '@/constants';
16-
import { useLocalize } from '@/hooks';
16+
import { useLocalize, useReturnFocus } from '@/hooks';
1717
import { cn } from '@/utils';
1818

1919
interface AuditLogDetailDrawerProps {
@@ -135,6 +135,7 @@ export function AuditLogDetailDrawer({
135135
loadError = false,
136136
}: AuditLogDetailDrawerProps): ReactElement | null {
137137
const localize = useLocalize();
138+
const returnFocus = useReturnFocus(open);
138139

139140
// Keep the last non-null entry so the close animation has content to render
140141
// while Radix Dialog slides the panel out. Without this, unmounting on
@@ -225,6 +226,7 @@ export function AuditLogDetailDrawer({
225226
<Dialog.Content
226227
aria-label={localize('com_audit_detail_title')}
227228
onEscapeKeyDown={() => onClose()}
229+
onCloseAutoFocus={returnFocus}
228230
className={cn(
229231
'fixed top-0 right-0 z-(--z-overlay) flex h-full w-full flex-col bg-(--cui-color-background-panel) shadow-xl sm:w-120',
230232
'border-l border-(--cui-color-stroke-default)',
@@ -272,6 +274,7 @@ export function AuditLogDetailDrawer({
272274
<Dialog.Content
273275
aria-label={localize('com_audit_detail_title')}
274276
onEscapeKeyDown={() => onClose()}
277+
onCloseAutoFocus={returnFocus}
275278
className={cn(
276279
'fixed top-0 right-0 z-(--z-overlay) flex h-full w-full flex-col bg-(--cui-color-background-panel) shadow-xl sm:w-120',
277280
'border-l border-(--cui-color-stroke-default)',
@@ -324,6 +327,7 @@ export function AuditLogDetailDrawer({
324327
<Dialog.Content
325328
aria-label={localize('com_audit_detail_title')}
326329
onEscapeKeyDown={() => onClose()}
330+
onCloseAutoFocus={returnFocus}
327331
className={cn(
328332
'fixed top-0 right-0 z-(--z-overlay) flex h-full w-full flex-col bg-(--cui-color-background-panel) shadow-xl sm:w-120',
329333
'border-l border-(--cui-color-stroke-default)',
@@ -389,6 +393,7 @@ export function AuditLogDetailDrawer({
389393
<Dialog.Content
390394
aria-label={localize('com_audit_detail_title')}
391395
onEscapeKeyDown={() => onClose()}
396+
onCloseAutoFocus={returnFocus}
392397
className={cn(
393398
'fixed top-0 right-0 z-(--z-overlay) flex h-full w-full flex-col bg-(--cui-color-background-panel) shadow-xl sm:w-120',
394399
'border-l border-(--cui-color-stroke-default)',

src/hooks/useReturnFocus.test.tsx renamed to src/hooks/__tests__/useReturnFocus.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
22
import { useRef, useState } from 'react';
33
import { Dialog } from '@clickhouse/click-ui';
44
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
5-
import { useReturnFocus } from './useReturnFocus';
5+
import { useReturnFocus } from '../useReturnFocus';
66

77
function Harness({ showTrigger }: { showTrigger: boolean }) {
88
const [open, setOpen] = useState(false);

src/types/config-ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export interface ResetBaseConfigDialogProps {
165165
open: boolean;
166166
resetting: boolean;
167167
error?: string | null;
168+
fallbackRef?: RefObject<HTMLElement | null>;
168169
onConfirm: () => void;
169170
onCancel: () => void;
170171
}

0 commit comments

Comments
 (0)