fix(presentation): localize default fallbacks and keep SearchField focus (Q-6.8-13c)
The render boundary's default fallback reads the current locale instead of formatting ko-KR, and resolveMessage's "message unavailable" fallback comes from the requested locale's catalog (ko-KR only as a last resort). SearchField's clear button moves focus to the input before it unmounts, so focus no longer drops to the body. tests/unit/i18n-contract.test.ts expected the Korean fallback for en-US, which encoded the bug; it now expects the English copy and keeps a ko-KR case. New component cases for the boundary fallback and SearchField (RED: 3 failed before the change); lane gates pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
cc1c7d879c
commit
72b1a72c81
@@ -1,7 +1,7 @@
|
||||
import { Component, type ReactNode } from "react";
|
||||
|
||||
import type { RenderFailureReport } from "../../application/ports/in/application-api.ts";
|
||||
import { formatMessage } from "../i18n/index.ts";
|
||||
import { useLocale } from "../i18n/index.ts";
|
||||
|
||||
export type RenderBoundaryProps = Readonly<{
|
||||
children: ReactNode;
|
||||
@@ -50,20 +50,26 @@ export class RenderErrorBoundary extends Component<
|
||||
render(): ReactNode {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
this.props.fallback ?? (
|
||||
<section role="alert">
|
||||
<p>{formatMessage("ko-KR", "error.render_failure")}</p>
|
||||
<button type="button" onClick={this.reset}>
|
||||
{formatMessage("ko-KR", "action.retry")}
|
||||
</button>
|
||||
</section>
|
||||
)
|
||||
this.props.fallback ?? <DefaultRenderFailure onRetry={this.reset} />
|
||||
);
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
/** The default fallback, in the current locale. */
|
||||
function DefaultRenderFailure({ onRetry }: Readonly<{ onRetry(): void }>) {
|
||||
const { message } = useLocale();
|
||||
return (
|
||||
<section role="alert">
|
||||
<p>{message("error.render_failure")}</p>
|
||||
<button type="button" onClick={onRetry}>
|
||||
{message("action.retry")}
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function RouteBoundary(
|
||||
props: Omit<RenderBoundaryProps, "boundaryName">,
|
||||
) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
forwardRef,
|
||||
useEffect,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
@@ -373,6 +374,8 @@ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
useImperativeHandle(ref, () => inputRef.current as HTMLInputElement);
|
||||
return (
|
||||
<div className={`ui-search-field ${className}`.trim()}>
|
||||
<SearchIcon />
|
||||
@@ -390,7 +393,7 @@ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
|
||||
aria-invalid={invalid || undefined}
|
||||
className="ui-field__input"
|
||||
id={controlId}
|
||||
ref={ref}
|
||||
ref={inputRef}
|
||||
type="search"
|
||||
value={value}
|
||||
/>
|
||||
@@ -399,7 +402,12 @@ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
|
||||
{String(value ?? "").length > 0 ? (
|
||||
<IconButton
|
||||
accessibleName={clearLabel}
|
||||
onClick={onClear}
|
||||
onClick={() => {
|
||||
onClear();
|
||||
// The button unmounts once the value is empty; keep focus in
|
||||
// the field instead of dropping it to the body.
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
variant="ghost"
|
||||
>
|
||||
<CloseIcon />
|
||||
|
||||
@@ -72,7 +72,8 @@ export function resolveMessage(
|
||||
const catalog =
|
||||
MESSAGE_CATALOGS[sourceLocale] ??
|
||||
MESSAGE_CATALOGS[FALLBACK_LOCALE];
|
||||
const fallback = KO_MESSAGES["common.unavailable"];
|
||||
const fallback =
|
||||
catalog["common.unavailable"] ?? KO_MESSAGES["common.unavailable"];
|
||||
const canonicalKey =
|
||||
MESSAGE_KEY_ALIASES[key as keyof typeof MESSAGE_KEY_ALIASES] ?? key;
|
||||
const template = catalog[canonicalKey as MessageKey] ?? fallback;
|
||||
|
||||
Reference in New Issue
Block a user