Selectable Form UI — Radio Cards That Rewrite the Request and the CTA (React · Tailwind CSS)
A selectable form where native radio inputs are visually hidden and each whole label becomes a radio card (React + Tailwind CSS, no next/font, so it runs in any React app, not just Next.js). Three things change when you choose: the blanks in the sentence "I want to move ahead with (what) (when)", the submit label ("pick two to send" → "one more to send" → "send the rebuild enquiry"), and a collapsible "after you send" panel with the first three questions and the reply window. A switcher under the heading jumps between empty / one chosen / complete so the states can be compared, and the block opens in the complete state. Cards are at least 44px tall and show selection with a dot inside a round mark plus a heavier border, not colour alone; the card, the mark and the sentence blank all change over the same 180–200ms so the pressed spot and the result read together. Hover or keyboard focus previews the wording before committing. At 375px a condensed sentence and the submit button stick to the bottom edge, so the result stays in view while you pick; on wider screens the submit row sits right under the sentence. Arrow-key movement is left to native radios; the visible sentence is aria-hidden and only committed choices reach an aria-live region. The sizing and keyboard rationale (WCAG 2.2 SC 2.5.5 / 2.5.8 / 1.4.1, WAI-ARIA APG Radio Group) is cited inside the block. Options and reply windows are display samples.
Preview
相談したいことを1文にする
いまのサイトのリニューアルを3か月以内に進めたい。送信できます。
送信後の段取り初回の返信 1営業日以内・最初に伺うこと3点
最初に伺うこと
- 01現在のサイトのURLと、公開した時期
- 02作り直したい理由(見た目・更新性・集客)
- 03引き継ぐページと、やめるページの見当
送信後のこと
初回の返信は1営業日以内
概算と進行スケジュールをまとめてお送りします
2/2選択済み
表示している選択肢・返信の目安はサンプルです。実際の内容は案件に合わせて差し替えてください。
寸法と操作の根拠(2026-11-13 確認)
- 選択行の高さ44px以上: WCAG 2.2 達成基準 2.5.5 Target Size (Enhanced)(AAA)は 44×44 CSS px、2.5.8 Target Size (Minimum)(AA)は 24×24 CSS px。 W3C 2.5.5 / W3C 2.5.8
- 選択を丸の中の点と太い枠でも示す: 達成基準 1.4.1 Use of Color(A)「色だけを唯一の視覚的手段にしない」。 W3C 1.4.1
- 矢印キーで隣の選択肢へ移り、そのまま選択される: WAI-ARIA Authoring Practices の Radio Group パターン。ネイティブの radio はこの動きを持つ。 W3C APG Radio Group
Read the full description
A selectable form where native radio inputs are visually hidden and each whole label becomes a radio card (React + Tailwind CSS, no next/font, so it runs in any React app, not just Next.js). Three things change when you choose: the blanks in the sentence "I want to move ahead with (what) (when)", the submit label ("pick two to send" → "one more to send" → "send the rebuild enquiry"), and a collapsible "after you send" panel with the first three questions and the reply window. A switcher under the heading jumps between empty / one chosen / complete so the states can be compared, and the block opens in the complete state. Cards are at least 44px tall and show selection with a dot inside a round mark plus a heavier border, not colour alone; the card, the mark and the sentence blank all change over the same 180–200ms so the pressed spot and the result read together. Hover or keyboard focus previews the wording before committing. At 375px a condensed sentence and the submit button stick to the bottom edge, so the result stays in view while you pick; on wider screens the submit row sits right under the sentence. Arrow-key movement is left to native radios; the visible sentence is aria-hidden and only committed choices reach an aria-live region. The sizing and keyboard rationale (WCAG 2.2 SC 2.5.5 / 2.5.8 / 1.4.1, WAI-ARIA APG Radio Group) is cited inside the block. Options and reply windows are display samples.
- Added:
- 2026-09-08
- Updated:
- 2026-11-13
- Dependencies:
- None
- tags
- #form #radio #radio-card #selectable-form #form-ui #cta #two-step #microcopy #sentence #sticky #accessibility #keyboard #react #tailwind #no-dependency #no-image
"use client";
import { useId, useState } from "react";
/**
* 選択式フォームUI|ラジオカードで依頼文が変わる2段階CTA / Radio-Card Sentence CTA
* ネイティブの <input type="radio"> を sr-only にし、ラベル全体を押せるラジオカードにした選択式フォーム。
* 選ぶと上段の穴埋め文の空欄が埋まり、送信ボタンの文言も「◯◯の相談を送る」に変わる(1段目=選ぶ、2段目=送る)。
* 候補にホバー/フォーカスすると文が先に書き換わって見え、押す前に出来上がりが読める。
*
* 依存: React 18 以上(useId)と Tailwind CSS だけ。next/font は使っていないので Next.js 以外の React
* (Vite・Remix など)でもそのまま動く。Next.js 以外では先頭の "use client" は無視されるので消しても残してもよい。
* 差し替える箇所:
* - INTENTS / TIMINGS: 選択肢・文中の言い回し・最初に伺うこと・返信の目安
* - SAMPLE_STATES: 見本の切替(未選択/片方選択/選択完了)で入れる値。不要なら StateSwitch ごと消す
* - onSubmit: いまは完了表示に切り替えるだけ。実際の送信(fetch など)はここに書く
*
* 汎用技法メモ:
* - ラジオカード: input は sr-only + peer にし、見た目は隣の label に peer-checked: / peer-focus-visible: で当てる。
* 矢印キーで選択が移る動きとグループのフォーカス管理はブラウザ任せになる(div + role="radio" で作り直さない)。
* - 選択は色だけで示さない: 丸の中に点を出し、枠を太くする。色を見分けにくくても形で読める。
* - 押せる行の高さは 44px 以上(min-h-11)。上下の余白ではなく最小の高さで確保すると、狭い幅でも間延びしない。
* - 押した場所と結果を同じ速さで結ぶ: カードの枠・丸の点・文の空欄を同じ 180〜200ms で変える。
* - 狭い幅では依頼文と送信を下端に追従させる(sticky bottom-0)。選択肢までスクロールしても結果が画面に残る。
* 広い幅では sm:order で送信行を文のすぐ下へ寄せ、結果とCTAを1か所で読ませる(DOM の順は変えない)。
* - 読み上げは見た目と分ける: 見える文はプレビューで揺れるので aria-hidden にし、確定値だけを sr-only の
* aria-live="polite" に書き出す。
* - 送信ボタンの文言は組み上がった文から作る。未完了のときは残り件数を文言にして disabled のまま置き、
* 寸法を変えないので活性化でレイアウトが動かない。
* - 掲載している内容・返信目安はすべて架空の表示サンプル。
*/
type Intent = {
key: string;
label: string;
/** 文中での言い回し(ラベルと分ける) */
sentence: string;
note: string;
/** 選択後に出す「最初に伺うこと」 */
asks: readonly string[];
reply: string;
};
const INTENTS: readonly Intent[] = [
{
key: "new",
label: "新規制作",
sentence: "サイトの新規制作",
note: "これから立ち上げる",
asks: [
"公開したい時期と、決まっている予算の幅",
"載せたい情報(会社案内・実績・採用など)",
"参考にしたいサイトが2〜3件あれば",
],
reply: "1営業日以内",
},
{
key: "renew",
label: "リニューアル",
sentence: "いまのサイトのリニューアル",
note: "作り直して整える",
asks: [
"現在のサイトのURLと、公開した時期",
"作り直したい理由(見た目・更新性・集客)",
"引き継ぐページと、やめるページの見当",
],
reply: "1営業日以内",
},
{
key: "improve",
label: "改善",
sentence: "公開中のサイトの改善",
note: "部分的に直す",
asks: [
"直したいページと、気になっている箇所",
"更新の権限(管理画面・コードの所在)",
"見ている数字があれば、その指標",
],
reply: "2営業日以内",
},
];
type Timing = {
key: string;
label: string;
sentence: string;
note: string;
/** 選択後に出す返信の中身 */
follow: string;
};
const TIMINGS: readonly Timing[] = [
{
key: "now",
label: "今すぐ",
sentence: "今すぐ",
note: "今月中に動きたい",
follow: "着手できる枠から先にお伝えします",
},
{
key: "quarter",
label: "3か月以内",
sentence: "3か月以内に",
note: "時期は決まっている",
follow: "概算と進行スケジュールをまとめてお送りします",
},
{
key: "research",
label: "検討段階",
sentence: "まずは相談から",
note: "情報を集めている",
follow: "近い事例と費用感の資料をお送りします",
},
];
/** 見本の切替で入れる値。0=未選択・1=片方選択・2=選択完了 */
const SAMPLE_STATES = [
{ label: "未選択", intent: null, timing: null },
{ label: "片方選択", intent: "renew", timing: null },
{ label: "選択完了", intent: "renew", timing: "quarter" },
] as const;
/** 今の選択と中身が一致する見本の番号。どれとも違えば -1(選択数では決めない) */
export function sampleIndexOf(intentKey: string | null, timingKey: string | null) {
return SAMPLE_STATES.findIndex((s) => s.intent === intentKey && s.timing === timingKey);
}
/** 穴埋め文の空欄1つ。確定値・プレビュー・未選択の3状態を同じ場所に描く */
function Slot({
value,
preview,
placeholder,
}: {
value: string | null;
preview: string | null;
placeholder: string;
}) {
const shown = preview ?? value;
const isPreview = preview !== null && preview !== value;
return (
<span
className={`mx-0.5 inline-block border-b-2 px-1 pb-0.5 leading-[1.6] transition-colors duration-200 motion-reduce:transition-none ${
value && !isPreview
? "border-solid border-amber-600 bg-amber-50 text-amber-800"
: isPreview
? "border-dashed border-amber-400 text-amber-700/60"
: "border-dashed border-gray-300 text-gray-400"
}`}
>
{/* 値が変わるたびに key を変えて、文字だけを持ち上げて差し替える */}
<span
key={shown ?? "empty"}
className="inline-block motion-safe:animate-[twoStepSlotIn_200ms_ease-out]"
>
{shown ?? placeholder}
</span>
</span>
);
}
/** 1つの設問。ラベル全体が押せるラジオカードを縦に3枚並べる */
function ChoiceGroup<T extends { key: string; label: string; note: string }>({
name,
number,
legend,
options,
value,
onChoose,
onPreview,
}: {
name: string;
number: string;
legend: string;
options: readonly T[];
value: T | null;
onChoose: (option: T) => void;
onPreview: (option: T | null) => void;
}) {
return (
<fieldset className="min-w-0 px-4 pt-3 pb-3.5 sm:px-6 sm:pb-5">
<legend className="float-left mb-2 flex w-full items-baseline gap-2">
<span className="text-[11px] leading-none font-bold text-amber-700 tabular-nums">
{number}
</span>
<span className="text-[12.5px] leading-none font-bold text-gray-900">{legend}</span>
</legend>
<div
className="clear-left grid gap-1.5"
onPointerLeave={() => onPreview(null)}
>
{options.map((op) => (
<div key={op.key} className="min-w-0">
<input
type="radio"
id={`${name}-${op.key}`}
name={name}
checked={value?.key === op.key}
onChange={() => onChoose(op)}
onFocus={() => onPreview(op)}
onBlur={() => onPreview(null)}
className="peer sr-only"
/>
<label
htmlFor={`${name}-${op.key}`}
onPointerEnter={() => onPreview(op)}
className="group flex min-h-11 cursor-pointer items-center gap-2.5 border border-gray-300 bg-white px-3 py-2 transition-[background-color,border-color,box-shadow] duration-[180ms] ease-out hover:border-gray-500 hover:bg-gray-50 peer-checked:border-amber-600 peer-checked:bg-amber-50 peer-checked:shadow-[inset_0_0_0_1px_var(--color-amber-600)] peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-amber-700 motion-reduce:transition-none"
>
{/* 単一選択の丸。選ぶと中に点が出る(色だけに頼らない) */}
<span
aria-hidden="true"
className={`grid size-4 shrink-0 place-items-center rounded-full border-[1.5px] bg-white transition-colors duration-[180ms] motion-reduce:transition-none ${
value?.key === op.key ? "border-amber-600" : "border-gray-400 group-hover:border-gray-600"
}`}
>
<span
className={`size-2 rounded-full bg-amber-600 transition-transform duration-[180ms] ease-out motion-reduce:transition-none ${
value?.key === op.key ? "scale-100" : "scale-0"
}`}
/>
</span>
<span className="flex min-w-0 flex-1 flex-wrap items-baseline justify-between gap-x-3">
<span className="text-[13.5px] leading-tight font-bold text-gray-900">{op.label}</span>
<span className="text-[11.5px] leading-tight text-gray-600">{op.note}</span>
</span>
</label>
</div>
))}
</div>
</fieldset>
);
}
export default function TwoStepPlanCta() {
const baseId = useId();
// 見本として最初は「選択完了」で開く(完成した文と送信ボタンが最初の画面に写る)
const [intent, setIntent] = useState<Intent | null>(INTENTS[1]);
const [timing, setTiming] = useState<Timing | null>(TIMINGS[1]);
const [intentPreview, setIntentPreview] = useState<Intent | null>(null);
const [timingPreview, setTimingPreview] = useState<Timing | null>(null);
const [sent, setSent] = useState(false);
const chosen = (intent ? 1 : 0) + (timing ? 1 : 0);
const ready = intent !== null && timing !== null;
const sampleIndex = sampleIndexOf(intent?.key ?? null, timing?.key ?? null);
const buttonLabel = ready
? `${intent.label}の相談を送る`
: chosen === 0
? "2つ選ぶと送信できます"
: "あと1つ選ぶと送信できます";
const applySample = (i: number) => {
const s = SAMPLE_STATES[i];
setIntent(INTENTS.find((x) => x.key === s.intent) ?? null);
setTiming(TIMINGS.find((x) => x.key === s.timing) ?? null);
// タッチでは pointerleave が来ないことがあるので、残ったプレビューもここで消す
setIntentPreview(null);
setTimingPreview(null);
setSent(false);
};
const onSubmit = () => setSent(true);
const intentWord = intent?.sentence ?? null;
const timingWord = timing?.sentence ?? null;
return (
<section
aria-labelledby={`${baseId}-heading`}
className="@container flex w-full max-w-3xl flex-col border border-gray-200 bg-white"
>
{/* 値の差し替えは transform と opacity だけで作る */}
<style>{`@keyframes twoStepSlotIn{from{opacity:0;transform:translateY(0.3em)}to{opacity:1;transform:translateY(0)}}`}</style>
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 border-b border-gray-200 px-4 py-2.5 sm:px-6">
<h2
id={`${baseId}-heading`}
className="flex items-center gap-2 text-[13px] leading-none font-bold tracking-tight text-gray-900 sm:text-sm"
>
<span aria-hidden="true" className="inline-block size-1 shrink-0 bg-amber-600" />
相談したいことを1文にする
</h2>
{/* 見本の切替: 3つの状態を押して見比べる */}
<div role="group" aria-label="状態の見本" className="flex items-center gap-1.5">
<span aria-hidden="true" className="text-[11px] leading-none text-gray-500">
見本
</span>
<div className="flex border border-gray-300">
{SAMPLE_STATES.map((s, i) => (
<button
key={s.label}
type="button"
aria-pressed={sampleIndex === i}
onClick={() => applySample(i)}
className="min-h-9 px-2.5 text-[11.5px] font-bold text-gray-600 transition-colors duration-[180ms] not-first:border-l not-first:border-gray-300 hover:bg-gray-50 hover:text-gray-900 focus-visible:relative focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-amber-700 aria-pressed:bg-gray-900 aria-pressed:text-white motion-reduce:transition-none"
>
{s.label}
</button>
))}
</div>
</div>
</div>
{/* 1段目の成果物: 選択が埋まっていく穴埋め文 */}
<p
aria-hidden="true"
className="px-4 pt-4 pb-3 text-[19px] leading-[2] font-bold text-gray-900 sm:px-6 sm:pt-7 sm:pb-5 sm:text-[26px]"
>
{/* 最長の文が収まる行数ぶんの高さを先に取る。プレビューで行数が変わると、
下の選択肢がポインタの下でずれて別の候補のプレビューに飛ぶため */}
<span className="block min-h-[2lh] @min-[47rem]:min-h-[1lh]">
<Slot value={intentWord} preview={intentPreview?.sentence ?? null} placeholder="(内容)" />
を
<Slot value={timingWord} preview={timingPreview?.sentence ?? null} placeholder="(時期)" />
{/* 述語は語中で折り返さない(375pxで「進/めたい。」と割れるため) */}
<span className="inline-block">進めたい。</span>
</span>
</p>
{/* 見える文はプレビューで揺れるので、確定した内容だけを読み上げに流す */}
<p aria-live="polite" className="sr-only">
{ready
? `${intent.sentence}を${timing.sentence}進めたい。送信できます。`
: chosen === 1
? "1つ選択しました。あと1つ選ぶと送信できます。"
: ""}
</p>
<div className="grid border-t border-gray-200 sm:order-2 sm:grid-cols-2 sm:divide-x sm:divide-gray-200">
<ChoiceGroup
name={`${baseId}-intent`}
number="01"
legend="相談したい内容"
options={INTENTS}
value={intent}
onChoose={(it) => {
setIntent(it);
setSent(false);
}}
onPreview={setIntentPreview}
/>
<div className="border-t border-gray-200 sm:border-t-0">
<ChoiceGroup
name={`${baseId}-timing`}
number="02"
legend="進めたい時期"
options={TIMINGS}
value={timing}
onChoose={(tm) => {
setTiming(tm);
setSent(false);
}}
onPreview={setTimingPreview}
/>
</div>
</div>
{/* 補足は開閉式。閉じていても要約の1行で、選択に連動して変わったことが分かる */}
<details className="group/more border-t border-gray-200 sm:order-2">
<summary className="flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 px-4 py-2 text-[12px] leading-snug text-gray-700 transition-colors hover:bg-gray-50 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-amber-700 sm:px-6 [&::-webkit-details-marker]:hidden">
<span>
<span className="font-bold text-gray-900">送信後の段取り</span>
<span className="mt-0.5 block text-gray-600 sm:mt-0 sm:ml-2 sm:inline">
{intent ? `初回の返信 ${intent.reply}・最初に伺うこと3点` : "内容を選ぶと表示します"}
</span>
</span>
<span
aria-hidden="true"
className="text-[11px] font-bold text-amber-700 transition-transform duration-200 group-open/more:rotate-45 motion-reduce:transition-none"
>
+
</span>
</summary>
<div className="grid gap-4 px-4 pt-1 pb-4 sm:grid-cols-2 sm:gap-6 sm:px-6">
<div>
<p className="text-[11px] leading-none font-bold text-gray-600">最初に伺うこと</p>
{intent ? (
<ol className="mt-2 space-y-1">
{intent.asks.map((ask, i) => (
<li key={ask} className="flex gap-2 text-[12px] leading-[1.7] text-gray-700">
<span className="shrink-0 text-[11px] leading-[1.9] font-bold text-amber-700 tabular-nums">
{`0${i + 1}`}
</span>
{ask}
</li>
))}
</ol>
) : (
<p className="mt-2 text-[12px] leading-[1.7] text-gray-500">
内容を選ぶと、最初にお聞きする3点を表示します。
</p>
)}
</div>
<div>
<p className="text-[11px] leading-none font-bold text-gray-600">送信後のこと</p>
<div className="mt-2 space-y-1 text-[12px] leading-[1.7] text-gray-700">
<p>{intent ? `初回の返信は${intent.reply}` : "初回の返信の目安を表示します。"}</p>
{timing && <p>{timing.follow}</p>}
</div>
</div>
</div>
</details>
{/* 2段目: 送信。狭い幅では依頼文と一緒に下端へ追従し、広い幅では文のすぐ下に並べる。
DOM は選択肢の後のままなので、Tab の順は「選ぶ→送る」で変わらない */}
<div className="sticky bottom-0 z-10 border-t border-gray-200 bg-gray-50/95 px-4 py-3 backdrop-blur-sm sm:static sm:order-1 sm:bg-gray-50 sm:px-6 sm:py-3.5">
{/* 狭い幅だけ、上の文が画面外に出ても読めるよう縮めた依頼文を置く */}
<p aria-hidden="true" className="mb-2 text-[13px] leading-snug font-bold text-gray-900 sm:hidden">
<span className={intentWord ? "text-amber-800" : "text-gray-400"}>
{intentWord ?? "(内容)"}
</span>
を
<span className={timingWord ? "text-amber-800" : "text-gray-400"}>
{timingWord ?? "(時期)"}
</span>
<span className="inline-block">進めたい。</span>
</p>
<div className="flex items-center justify-between gap-3 sm:gap-6">
{sent ? (
<p className="flex items-center gap-2 text-[12.5px] leading-snug font-bold text-gray-900">
<span aria-hidden="true" className="inline-block size-1.5 shrink-0 bg-amber-600" />
この内容でお預かりしました
</p>
) : (
<p className="flex shrink-0 items-center gap-2 text-[11.5px] leading-none text-gray-600">
<span aria-hidden="true" className="flex gap-1">
{[0, 1].map((i) => (
<span
key={i}
className={`inline-block size-2 rounded-full transition-colors duration-200 motion-reduce:transition-none ${
i < chosen ? "bg-amber-600" : "border border-gray-400 bg-white"
}`}
/>
))}
</span>
{chosen}/2
<span className="hidden sm:inline">選択済み</span>
</p>
)}
{sent ? (
<button
type="button"
onClick={() => setSent(false)}
className="min-h-11 shrink-0 px-2 text-[12.5px] font-bold text-gray-700 underline underline-offset-4 transition-colors hover:text-amber-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-700"
>
書き直す
</button>
) : (
<button
type="button"
disabled={!ready}
onClick={onSubmit}
className="min-h-11 min-w-0 flex-1 bg-amber-700 px-4 text-[13px] font-bold text-white transition-[background-color,transform] duration-200 ease-out hover:-translate-y-0.5 hover:bg-amber-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-700 disabled:cursor-default disabled:bg-gray-200 disabled:text-gray-500 disabled:hover:translate-y-0 motion-reduce:transition-none motion-reduce:hover:translate-y-0 sm:flex-none sm:px-6"
>
{buttonLabel}
</button>
)}
</div>
</div>
<div className="border-t border-gray-100 px-4 py-2.5 text-[11px] leading-[1.8] text-gray-500 sm:order-2 sm:px-6">
<p>表示している選択肢・返信の目安はサンプルです。実際の内容は案件に合わせて差し替えてください。</p>
<details className="mt-1">
<summary className="inline-flex min-h-8 cursor-pointer items-center font-bold text-gray-600 hover:text-gray-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-700">
寸法と操作の根拠(2026-11-13 確認)
</summary>
<ul className="mt-1 space-y-1 pb-1">
<li>
選択行の高さ44px以上: WCAG 2.2 達成基準 2.5.5 Target Size (Enhanced)(AAA)は 44×44 CSS px、2.5.8 Target Size (Minimum)(AA)は 24×24 CSS px。{" "}
<a className="underline underline-offset-2 hover:text-gray-900" href="https://www.w3.org/WAI/WCAG22/Understanding/target-size-enhanced.html">W3C 2.5.5</a>
{" / "}
<a className="underline underline-offset-2 hover:text-gray-900" href="https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html">W3C 2.5.8</a>
</li>
<li>
選択を丸の中の点と太い枠でも示す: 達成基準 1.4.1 Use of Color(A)「色だけを唯一の視覚的手段にしない」。{" "}
<a className="underline underline-offset-2 hover:text-gray-900" href="https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html">W3C 1.4.1</a>
</li>
<li>
矢印キーで隣の選択肢へ移り、そのまま選択される: WAI-ARIA Authoring Practices の Radio Group パターン。ネイティブの radio はこの動きを持つ。{" "}
<a className="underline underline-offset-2 hover:text-gray-900" href="https://www.w3.org/WAI/ARIA/apg/patterns/radio/">W3C APG Radio Group</a>
</li>
</ul>
</details>
</div>
</section>
);
}
Add to your project via shadcn CLI
npx shadcn@latest add https://designs.first-ch.com/r/two-step-plan-cta.json