fix: 调试发布run
This commit is contained in:
@@ -8,12 +8,13 @@ interface ConfirmDialogProps {
|
||||
confirmLabel: string;
|
||||
danger?: boolean;
|
||||
busy?: boolean;
|
||||
confirmDisabled?: boolean;
|
||||
onConfirm: () => void;
|
||||
onCancel: () => void;
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
export function ConfirmDialog({ open, title, description, confirmLabel, danger, busy, onConfirm, onCancel, children }: ConfirmDialogProps) {
|
||||
export function ConfirmDialog({ open, title, description, confirmLabel, danger, busy, confirmDisabled, onConfirm, onCancel, children }: ConfirmDialogProps) {
|
||||
const titleId = useId();
|
||||
const descriptionId = useId();
|
||||
const panelRef = useDialogLifecycle(open, onCancel, !busy);
|
||||
@@ -45,7 +46,7 @@ export function ConfirmDialog({ open, title, description, confirmLabel, danger,
|
||||
<button type="button" onClick={onCancel} disabled={busy}>
|
||||
取消
|
||||
</button>
|
||||
<button type="button" className={danger ? "confirm-danger" : "confirm-primary"} onClick={onConfirm} disabled={busy}>
|
||||
<button type="button" className={danger ? "confirm-danger" : "confirm-primary"} onClick={onConfirm} disabled={busy || confirmDisabled}>
|
||||
{busy ? "提交中…" : confirmLabel}
|
||||
</button>
|
||||
</div>
|
||||
@@ -97,6 +98,13 @@ export function ManagementDialog({ open, title, description, wide, onClose, chil
|
||||
|
||||
function useDialogLifecycle(open: boolean, onClose: () => void, canClose: boolean) {
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const onCloseRef = useRef(onClose);
|
||||
const canCloseRef = useRef(canClose);
|
||||
|
||||
useEffect(() => {
|
||||
onCloseRef.current = onClose;
|
||||
canCloseRef.current = canClose;
|
||||
}, [canClose, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
@@ -104,13 +112,15 @@ function useDialogLifecycle(open: boolean, onClose: () => void, canClose: boolea
|
||||
}
|
||||
const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
const panel = panelRef.current;
|
||||
const focusTarget = panel?.querySelector<HTMLElement>("button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])");
|
||||
const focusTarget =
|
||||
panel?.querySelector<HTMLElement>("input:not([disabled]), select:not([disabled]), textarea:not([disabled])") ??
|
||||
panel?.querySelector<HTMLElement>("button:not([disabled])");
|
||||
focusTarget?.focus();
|
||||
|
||||
function handleKeyDown(event: KeyboardEvent) {
|
||||
if (event.key === "Escape" && canClose) {
|
||||
if (event.key === "Escape" && canCloseRef.current) {
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
onCloseRef.current();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +132,7 @@ function useDialogLifecycle(open: boolean, onClose: () => void, canClose: boolea
|
||||
document.body.style.overflow = previousBodyOverflow;
|
||||
previousFocus?.focus();
|
||||
};
|
||||
}, [canClose, onClose, open]);
|
||||
}, [open]);
|
||||
|
||||
return panelRef;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user