本文へ移動

ツリー・チェックボックス

概要

チェックボックスをツリー状に並べ、複雑な操作と入れ子メニューを制御します。
(例)アンカーリンクとコンテンツの表示・非表示を制御

デザイン

サンプル

用途によって、テキストで✓をさせたり、リンクをさせたり変更してください。

<nav class="treeList mb-8">
<ul>
<li><label><input type="checkbox" data-node="1" aria-labelledby="tree-label-1"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-1">サンプル1</button>
	<input type="button" value="" class="openerBtn" aria-label="サンプル1の子項目を開閉" aria-controls="tree-children-1" aria-expanded="false">
	<ul id="tree-children-1" hidden>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-2"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-2">サンプル1ー1</button></li>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-3"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-3">サンプル1ー2</button></li>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-4"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-4">サンプル1ー3</button></li>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-5"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-5">サンプル1ー4</button></li>
	</ul>
</li>
<li><label><input type="checkbox" data-node="1" aria-labelledby="tree-label-6"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-6">サンプル2</button></li>
<li><label><input type="checkbox" data-node="1" aria-labelledby="tree-label-7"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-7">サンプル3</button>
	<input type="button" value="" class="openerBtn" aria-label="サンプル3の子項目を開閉" aria-controls="tree-children-7" aria-expanded="false">
	<ul id="tree-children-7" hidden>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-8"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-8">サンプル3ー1</button></li>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-9"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-9">サンプル3ー2</button>
		<input type="button" value="" class="openerBtn" aria-label="サンプル3ー2の子項目を開閉" aria-controls="tree-children-9" aria-expanded="false">
	<ul id="tree-children-9" hidden>
			<li><label><input type="checkbox" data-node="3" aria-labelledby="tree-label-10"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-10">サンプル3ー2ー1</button></li>
			<li><label><input type="checkbox" data-node="3" aria-labelledby="tree-label-11"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-11">サンプル3ー2ー2</button></li>
			<li><label><input type="checkbox" data-node="3" aria-labelledby="tree-label-12"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-12">サンプル3ー2ー3</button>
	<input type="button" value="" class="openerBtn" aria-label="サンプル3ー2ー3の子項目を開閉" aria-controls="tree-children-12" aria-expanded="false">
	<ul id="tree-children-12" hidden>
		<li><label><input type="checkbox" data-node="4" aria-labelledby="tree-label-13"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-13">サンプル3ー2ー3ー1</button></li>
		<li><label><input type="checkbox" data-node="4" aria-labelledby="tree-label-14"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-14">サンプル3ー2ー3ー2</button></li>
	</ul>
			
			</li>
			<li><label><input type="checkbox" data-node="3" aria-labelledby="tree-label-15"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-15">サンプル3ー2ー4</button></li>
		</ul>
		</li>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-16"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-16">サンプル3ー3</button></li>
		<li><label><input type="checkbox" data-node="2" aria-labelledby="tree-label-17"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-17">サンプル3ー4</button></li>
	</ul>
</li>
<li><label><input type="checkbox" data-node="1" aria-labelledby="tree-label-18"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-18">サンプル4</button></li>
<li><label><input type="checkbox" data-node="1" aria-labelledby="tree-label-19"><span class="inputCheck"></span></label><button type="button" class="textBlack" id="tree-label-19">サンプル5</button></li>
</ul>
</nav>
NAV
CLASS ナビゲーションタグ(NAV)に [treeList] を設置して、UL(チェックボックス)を階層化します。
階層
DATA属性 data-node="X" Xに、入れ子階層の数値を設定します。
階層
CLASS [openerBtn] は、入れ子を開閉するボタンです。aria-labelに操作対象名、aria-controlsに子リストのIDを指定します。初期状態は子リストのhiddenで指定し、aria-expandedも一致させます。

改変対象ファイル

CSS:
_ul.scss 内に改変対象箇所があります。
_ul.scssは、本番へは反映せずに、必要なUIのコードを_modules.scssに追加してください。
Javascript:
ツリー・チェックボックスの動作:treeCheckBox()関数
必要なUIのコードをライブラリー (/temp/js/tips.js) から本番 (/common/js/tips.js) に追加してください。