fix(forms): 필드 오류가 아닌 저장 실패 뒤 키보드 포커스를 실패 상태로 옮긴다 (1103/08-02)
문제 참조 폼 페이지는 저장 중과 결과 불명 동안 저장 버튼에 disabled를 준다. 포커스가 있던 버튼이 꺼지면 브라우저가 포커스를 body로 내려놓는다. 폼은 필드 오류일 때만 포커스를 옮겼으므로, 키보드로 저장했다가 결과 불명(500)이나 429를 받으면 세 엔진 모두 포커스가 body로 떨어졌다. 복구 버튼은 폼 위 feedback 자리에 있어 셸 머리말부터 다시 지나야 닿았다. 고른 방법 - useAppForm이 feedbackId를 내고, 필드 오류·성공이 아닌 결과(결과 불명, 재인증, 권한 없음, 다시 시도, 사용 불가, 충돌)로 끝나면 렌더 뒤 그 요소에 포커스를 준다. FormPage(StandardPage)는 feedbackId를 받으면 feedback 자리를 id + tabIndex=-1인 포커스 대상으로 만든다. 페이지마다 포커스 코드를 복사하지 않게 하려고 hook과 템플릿에 두었다. - 참조 폼의 저장 버튼은 저장 중에 disabled 대신 Button의 pending(aria-busy)을 쓴다. 중복 제출은 지금처럼 폼(submitForm)과 onSubmit 가드가 막는다. 결과 불명 동안에는 여전히 꺼진다(08-01 범위). 그때는 위의 포커스 이동이 받는다. - 첫 행동 버튼 대신 feedback 자리 전체를 포커스한 이유: 실패 종류마다 버튼 구성이 다르고, Tab 한 번에 첫 복구 버튼에 닿는다. 매뉴얼 02 6절 FormPage에 feedbackId와 pending을 적었다. 위험·한계 - 스크린 리더가 포커스된 feedback 자리를 어떻게 읽는지는 확인하지 않았다. - 파생 폼 페이지는 feedbackId를 넘겨야 이 동작을 얻는다. - "deduplicates create" 테스트의 저장 중 단언을 disabled에서 aria-busy와 포커스 유지로 바꿨다. 한 번만 호출되는 단언은 그대로다. 검증 - RED: reference-page.test.tsx 새 2행(결과 불명, 429)이 수정 전 실패. e2e reference-save.spec.ts 새 2건이 수정 전 소스에서 chromium·firefox·webkit 6건 모두 실패(feedback 자리 focused 아님). - 수정 후 reference-save·reference-form e2e 3엔진 45건 통과(heavy lock, CHOKIDAR_USEPOLLING=1). tests/component·tests/features 60 files / 368 tests 통과. check:types, eslint, check:design-system, check:i18n, verify:documentation 통과. Refs: docs/reviews/2026-11-03-maturity-review/08-presentation.md 08-02
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useId,
|
||||
useMemo,
|
||||
useRef,
|
||||
@@ -54,6 +55,7 @@ export function useAppForm<
|
||||
} = options;
|
||||
const generatedId = useId().replaceAll(":", "");
|
||||
const formId = `app-form-${generatedId}`;
|
||||
const feedbackId = `${formId}-feedback`;
|
||||
const [values, setValues] = useState<Values>(defaultValues);
|
||||
const [initialValues, setInitialValues] = useState<Values>(defaultValues);
|
||||
const [touched, setTouched] = useState<ReadonlySet<FieldName<Values>>>(
|
||||
@@ -86,6 +88,17 @@ export function useAppForm<
|
||||
const [statusFailure, setStatusFailure] = useState<AppFailure | null>(null);
|
||||
const pendingRef = useRef<Promise<FormResult<Output> | null> | null>(null);
|
||||
const unknownSubmissionRef = useRef<Values | null>(null);
|
||||
// 1103/08-02. A save that ends in neither a field error nor success shows
|
||||
// its status above the form while the page disables the button that had
|
||||
// focus, so the browser drops focus to the body. The status takes focus
|
||||
// once it has rendered (`feedbackId`).
|
||||
const focusFeedbackRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (!focusFeedbackRef.current) return;
|
||||
focusFeedbackRef.current = false;
|
||||
const feedback = document.getElementById(feedbackId);
|
||||
if (feedback instanceof HTMLElement) feedback.focus();
|
||||
});
|
||||
|
||||
const dirty = useMemo(
|
||||
() => JSON.stringify(values) !== JSON.stringify(initialValues),
|
||||
@@ -214,11 +227,13 @@ export function useAppForm<
|
||||
focusFirstError(mapped.fieldErrors);
|
||||
} else if (outcome.error.action === "reauth") {
|
||||
// D-2. Signing in again comes first, whatever the effect.
|
||||
focusFeedbackRef.current = true;
|
||||
unknownSubmissionRef.current = null;
|
||||
setFormErrors([]);
|
||||
setStatusFailure(outcome.error);
|
||||
setResult("reauth-required");
|
||||
} else if (outcome.error.effect === "MAYBE_APPLIED") {
|
||||
focusFeedbackRef.current = true;
|
||||
unknownSubmissionRef.current = submittedValues;
|
||||
setFormErrors([]);
|
||||
// 0929/08-04. Kept for its request id, not shown as a status.
|
||||
@@ -227,6 +242,7 @@ export function useAppForm<
|
||||
} else if (outcome.error.effect === "APPLIED_CONFIRMED") {
|
||||
settleSuccessfulValues(submittedValues);
|
||||
} else if (outcome.error.kind === "CONFLICT") {
|
||||
focusFeedbackRef.current = true;
|
||||
unknownSubmissionRef.current = null;
|
||||
setFormErrors(["form.conflict"]);
|
||||
setResult("conflict");
|
||||
@@ -234,6 +250,7 @@ export function useAppForm<
|
||||
outcome.error.kind === "FORBIDDEN" ||
|
||||
outcome.error.action === "retry"
|
||||
) {
|
||||
focusFeedbackRef.current = true;
|
||||
unknownSubmissionRef.current = null;
|
||||
setFormErrors([]);
|
||||
setStatusFailure(outcome.error);
|
||||
@@ -242,6 +259,7 @@ export function useAppForm<
|
||||
);
|
||||
} else {
|
||||
// F-10. Not an input error either: shown by FormFailureStatus.
|
||||
focusFeedbackRef.current = true;
|
||||
unknownSubmissionRef.current = null;
|
||||
setFormErrors([]);
|
||||
setStatusFailure(outcome.error);
|
||||
@@ -347,6 +365,12 @@ export function useAppForm<
|
||||
|
||||
return Object.freeze({
|
||||
formId,
|
||||
/**
|
||||
* 1103/08-02. Give it to the page template (`FormPage` `feedbackId`): the
|
||||
* feedback area takes focus when a save ends in a status instead of a
|
||||
* field error.
|
||||
*/
|
||||
feedbackId,
|
||||
values,
|
||||
dirty,
|
||||
touched,
|
||||
|
||||
@@ -39,6 +39,11 @@ export type PageTemplateSlots = Readonly<{
|
||||
children?: ReactNode;
|
||||
aside?: ReactNode;
|
||||
feedback?: ReactNode;
|
||||
/**
|
||||
* 1103/08-02. Makes the feedback area a focus target under this id
|
||||
* (`useAppForm` `feedbackId`), so a form can move focus there.
|
||||
*/
|
||||
feedbackId?: string;
|
||||
}>;
|
||||
|
||||
export function StandardPage(props: PageTemplateSlots) {
|
||||
@@ -66,7 +71,14 @@ export function StandardPage(props: PageTemplateSlots) {
|
||||
<div className="page-template__notices">{props.notices}</div>
|
||||
) : null}
|
||||
{props.feedback ? (
|
||||
<div className="page-template__feedback">{props.feedback}</div>
|
||||
<div
|
||||
className="page-template__feedback"
|
||||
{...(props.feedbackId === undefined
|
||||
? {}
|
||||
: { id: props.feedbackId, tabIndex: -1 })}
|
||||
>
|
||||
{props.feedback}
|
||||
</div>
|
||||
) : null}
|
||||
<div
|
||||
className="page-template__layout"
|
||||
|
||||
Reference in New Issue
Block a user