Keep Aniimo flip controls stable during card transitions
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 17m32s
Validate and deploy Sokko G / deploy (push) Successful in 10s

This commit is contained in:
Shinuwa 2026-10-23 22:56:36 +02:00
parent 1ad26a0acd
commit 18110049f2
3 changed files with 6 additions and 20 deletions

View file

@ -101,11 +101,11 @@ test("Aniimo matches MHW card motion, surfaces and filter controls", async ({ pa
await expect(card).toBeVisible();
expect(await styles(card.locator(".aniimo-card-inner"), motionProperties)).toEqual(motion);
expect(await styles(card.locator(".aniimo-front"), faceProperties)).toEqual(face);
expect(await styles(card.locator(".aniimo-front .aniimo-flip"), indicatorProperties)).toEqual(indicator);
expect(await styles(card.locator(".aniimo-card > .aniimo-flip"), indicatorProperties)).toEqual(indicator);
expect(await styles(page.locator(".filter-logic").first(), filterProperties)).toEqual(filter);
await page.keyboard.press("Escape");
await expect(card.locator(".aniimo-face .aniimo-flip")).toHaveCount(2);
await expect(card.locator(".aniimo-card > .aniimo-flip")).toHaveCount(0);
await expect(card.locator(".aniimo-face .aniimo-flip")).toHaveCount(0);
await expect(card.locator(".aniimo-card > .aniimo-flip")).toHaveCount(1);
await card.getByRole("button", { name: /Afficher les capacités/ }).press("Enter");
await expect(card.getByRole("button", { name: /Afficher le portrait/ })).toBeFocused();
await expect(card.locator(".aniimo-front")).toHaveAttribute("inert", "");

View file

@ -1,5 +1,5 @@
// Rôle : affiche une carte Aniimo retournable et les onglets des variantes correspondantes.
import { useId, useLayoutEffect, useRef, useState } from "react";
import { useId, useState } from "react";
import { GuideChecklistCheckbox, GuideChecklistMark } from "../GuideChecklistControls.jsx";
import { Icon } from "../../../components/Icon.jsx";
import { Tooltip } from "../../../components/Tooltip.jsx";
@ -18,24 +18,11 @@ function shortForm(label) {
function CardFaces({ variant, t, content, checklist, statsMax }) {
const completed = checklist.isCompleted(variant.key);
const [flipped, setFlipped] = useState(false);
const frontButton = useRef(null);
const backButton = useRef(null);
const focusAfterFlip = useRef(false);
useLayoutEffect(() => {
if (!focusAfterFlip.current) return;
(flipped ? backButton : frontButton).current?.focus({ preventScroll: true });
focusAfterFlip.current = false;
}, [flipped]);
function flip() {
focusAfterFlip.current = true;
setFlipped((value) => !value);
}
const flipButton = (back, ref) => <button ref={ref} type="button" className="aniimo-flip nds-icon-button" aria-pressed={back} aria-label={`${back ? content.showFront : content.showBack} — ${t(variant.name)}, ${t(variant.form)}`} title={back ? content.showFront : content.showBack} onClick={flip}><Icon name="flip" /></button>;
return (
<div className={`aniimo-card ${flipped ? "is-flipped" : ""}`}>
<button type="button" className="aniimo-flip nds-icon-button" aria-pressed={flipped} aria-label={`${flipped ? content.showFront : content.showBack} — ${t(variant.name)}, ${t(variant.form)}`} title={flipped ? content.showFront : content.showBack} onClick={() => setFlipped((value) => !value)}><Icon name="flip" /></button>
<div className="aniimo-card-inner">
<div className="aniimo-face aniimo-front nds-card" aria-hidden={flipped} inert={flipped}>
{flipButton(false, frontButton)}
<div className="aniimo-portrait">
<img src={variant.image} alt={t(variant.name)} width="512" height="840" loading="lazy" />
<span className="aniimo-number">N° {variant.aniimoId}</span>
@ -48,7 +35,6 @@ function CardFaces({ variant, t, content, checklist, statsMax }) {
</div>
</div>
<div className="aniimo-face aniimo-back nds-card" aria-hidden={!flipped} inert={!flipped}>
{flipButton(true, backButton)}
<GuideChecklistMark completed={completed} label={checklist.content.completed} />
<div className="aniimo-card-body aniimo-back-heading">
<h2 title={t(variant.name)}>{t(variant.name)}</h2>

View file

@ -180,7 +180,7 @@
list-style: none;
li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 6px; font-size: var(--font-size-sm); }
}
.aniimo-face .aniimo-flip {
.aniimo-card > .aniimo-flip {
@include surfaces.flip-card-indicator;
min-width: 0;
min-height: 0;