JSFiddle - React, Tailwind, and code Playground
by Michel Plungjan
HTML
<form class="fltr">
<fieldset>
<legend>Graphics</legend>
<div style="display: flex;" class="ggrp">
<label class="checked"><input id="A1" name="gfx" type="radio" value="A1" checked /> A1</label>
<label><input id="A2" name="gfx" type="radio" value="A2" /> A2</label>
<label><input id="A3" name="gfx" type="radio" value="A3" /> A3</label>
</div>
</fieldset>
<fieldset>
<legend>Display</legend>
<div style="display: flex;" class="dgrp">
<div class="A1"><label class="checked"><input id="B1" name="dsp" type="radio" value="B1" checked /> B1</label> </div>
<div class="A1 A2"><label><input id="B2" name="dsp" type="radio" value="B2" /> B2</label> </div>
<div class="A2"><label><input id="B3" name="dsp" type="radio" value="B3" /> B3</label> </div>
<div class="A3"><label><input id="B4" name="dsp" type="radio" value="B4" /> B4</label></div>
</div>
</fieldset>
</form>
CSS
.fltr label.checked {
border-color: #44D62C;
color: #44D62C;
}
JavaScript
const filterForm = document.querySelector('form.fltr');
filterForm.addEventListener('click', (e) => {
const tgt = e.target;
if (!tgt.matches('[type=radio]')) return;
const parent = tgt.closest('div');
parent.querySelectorAll('input')
.forEach(rad => rad.closest('label').classList.toggle('checked', rad.checked));
if (!parent.matches('.ggrp')) return; // not a ggrp
document.querySelectorAll('.dgrp div').forEach(div => {
div.hidden = !div.matches(`.${tgt.id}`);
if (!div.hidden) div.querySelector('input').click();
});
});