JSFiddle - React, Tailwind, and code Playground
HTML
<div class="ui-widget-content" style="width: 230px;">
<input id="filter" type="text" style="width: 98%;" />
<div id="accordion" style="height: 300px; width: 230px; overflow-x: auto;">
<h3>Group One</h3>
<div>
<ul class="itemlist">
<li>
<input type="checkbox" />Arvin</li>
<li>
<input type="checkbox" />Jack</li>
<li>
<input type="checkbox" />Bryan</li>
<li>
<input type="checkbox" />Donald</li>
<li>
<input type="checkbox" />Harold</li>
<li>
<input type="checkbox" />Marshall</li>
</ul>
</div>
<h3>Group Two</h3>
<div>
<ul class="itemlist">
<li>
<input type="checkbox" />Joyce</li>
<li>
<input type="checkbox" />Alex</li>
<li>
<input type="checkbox" />Joy</li>
<li>
<input type="checkbox" />Joe</li>
<li>
<input type="checkbox" />Clark</li>
<li>
<input type="checkbox" />Carlton</li>
<li>
<input type="checkbox" />Nahum</li>
<li>
<input type="checkbox" />Timmy</li>
</ul>
</div>
<h3>Group Three</h3>
<div>
<ul class="itemlist">
<li>
<input type="checkbox" />Lisa</li>
<li>
<input type="checkbox" />Frank</li>
<li>
<input type="checkbox" />Wally</li>
<li>
<input type="checkbox" />Vince</li>
<li>
<input type="checkbox" />Allen</li>
</ul>
</div>
<div...
CSS
ul {
list-style-type:none;
}
JavaScript
$(function () {
$("#accordion").accordion({ icons: '', heightStyle: 'fill' });
});
$(function () {
$("#filter").keyup(function () {
// 取得塞選條件
var filter = $(this).val();
// 如果有塞選的值
if (filter.length > 0) {
// 取得清單
var allHasCount = 0;
$(".itemlist").each(function () {
// 用於紀錄是否有塞選到項目
var hasCount = 0;
// 找到清單判斷是否顯示
$(this).find("li").each(function () {
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut();
} else {
$(this).show();
hasCount++;
}
});
// 如果該群組尋找到 1 個以上項目
if (hasCount > 0) {
// 顯示群組
$(this).parent().prev().css("display", "block");
// 展開
$(this).parent().slideDown();
}
else {
// 隱藏群組
$(this).parent().prev().css("display", "none");
// 縮合
$(this).parent().slideUp();
if ($(this).parent().attr("aria-expanded") == "true")
$(this).parent().css("aria-expanded", "false");
}
// 計算找到的總數
allHasCount += hasCount;
});
// 如果都沒找到顯示訊息
if (allHasCount == 0) {
$(".notfound").css("display", "block");
}
else {
$(".notfound").css("display", "none");
}
}
else {
// 找到所有群組標題
$("#accordion h3").each(function () {
...