Kinetic Combobox
A searchable select: type to filter the options, move with the arrow keys and press Enter. Shows "No matches" when nothing fits.
- <kt-kinetic-combobox>
- Selection
- No framework
The code
Copy the Kinetic Combobox
Fastest: press Copy on the card above for one complete file. To build it into your own
project, use the files below: the markup, the styles, this component’s script and the shared
effects script (effects.js) that every component uses.
<kt-kinetic-combobox label="Country" items="Argentina,Australia,Brazil,Canada,France,Germany,India,Japan,Mexico,Norway,Spain,United Kingdom" value="Japan" placeholder="Search countries"></kt-kinetic-combobox>
<kt-kinetic-combobox label="Assignee" items="Ada Lovelace,Grace Hopper,Alan Turing,Katherine Johnson,Linus Torvalds" placeholder="Search people"></kt-kinetic-combobox>
<kt-kinetic-combobox label="Region" items="us-east-1,us-west-2,eu-central-1,ap-south-1" value="eu-central-1" disabled></kt-kinetic-combobox>
kt-kinetic-combobox {
display: block;
width: 100%;
max-width: 340px;
}
.kt-combobox {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
position: relative;
padding: 12px 14px 13px;
border-radius: var(--kt-surface-radius);
border-style: solid;
border-width: var(--kt-card-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: var(--kt-surface-bg);
color: var(--kt-surface-ink);
box-shadow: var(--kt-comp-shadow);
transition: border-color 160ms ease, box-shadow 180ms ease, border-width 150ms ease;
}
.kt-combobox.is-disabled {
opacity: 0.55;
}
.kt-combobox-label {
display: block;
margin-bottom: 7px;
font-family: var(--font-mono);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--kt-surface-muted);
}
.kt-combobox-field {
position: relative;
display: flex;
align-items: center;
border-radius: var(--kt-radius-btn);
border-style: solid;
border-width: var(--kt-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: color-mix(in srgb, var(--kt-surface-ink) 6%, transparent);
transition: border-color 160ms ease, background-color 150ms ease, box-shadow 170ms ease;
}
.kt-combobox:not(.is-disabled) .kt-combobox-field:hover {
border-color: var(--kt-comp-border, var(--kt-surface-ink));
}
.kt-combobox.is-focus .kt-combobox-field,
.kt-combobox.is-open .kt-combobox-field {
border-color: var(--kt-comp-border, var(--_color));
background: color-mix(in srgb, var(--kt-surface-ink) 9%, transparent);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--_color) 28%, transparent);
}
.kt-combobox-input {
flex: 1;
min-width: 0;
height: 40px;
padding: 0 4px 0 12px;
margin: 0;
border: 0;
outline: 0;
background: transparent;
color: var(--kt-surface-ink);
font-family: var(--font-sans);
font-size: 13px;
font-weight: 600;
box-shadow: none;
text-overflow: ellipsis;
}
.kt-combobox-input::placeholder {
color: var(--kt-surface-muted);
font-weight: 500;
opacity: 0.9;
}
.kt-combobox-input:disabled {
cursor: not-allowed;
}
.kt-combobox-toggle {
flex-shrink: 0;
display: grid;
place-items: center;
width: 32px;
height: 32px;
margin-right: 4px;
padding: 0;
border: 0;
border-radius: var(--kt-radius-tag);
background: transparent;
color: var(--kt-surface-muted);
cursor: pointer;
transition: color 150ms ease, transform 200ms var(--ease-snap);
}
.kt-combobox-toggle:hover:not(:disabled) {
color: var(--kt-surface-ink);
}
.kt-combobox.is-open .kt-combobox-toggle {
transform: rotate(180deg);
color: var(--_color);
}
.kt-combobox-menu {
position: fixed;
z-index: 1200;
box-sizing: border-box;
padding: 5px;
border-radius: var(--kt-surface-radius);
border-style: solid;
border-width: var(--kt-card-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: var(--kt-surface-bg);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
overflow-y: auto;
opacity: 0;
visibility: hidden;
pointer-events: none;
transform: translateY(-6px) scale(0.98);
transform-origin: top center;
transition: opacity 150ms ease, transform 180ms var(--ease-snap), visibility 0s linear 150ms;
}
.kt-combobox-menu.is-flipped {
transform-origin: bottom center;
}
.kt-combobox.is-open .kt-combobox-menu {
opacity: 1;
visibility: visible;
pointer-events: auto;
transform: translateY(0) scale(1);
transition: opacity 150ms ease, transform 180ms var(--ease-snap), visibility 0s;
}
.kt-combobox-option {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
min-height: 34px;
padding: 8px 10px;
border-radius: var(--kt-radius-tag);
color: var(--kt-surface-ink);
font-family: var(--font-sans);
font-size: 12.5px;
font-weight: 600;
line-height: 1.2;
cursor: pointer;
}
.kt-combobox-option[hidden],
.kt-combobox-empty[hidden] {
display: none;
}
.kt-combobox-option.is-active {
background: color-mix(in srgb, var(--kt-surface-ink) 9%, transparent);
box-shadow: inset 2px 0 0 var(--_color);
}
.kt-combobox-option[aria-selected="true"] {
background: color-mix(in srgb, var(--_color) 12%, transparent);
}
.kt-combobox-option[aria-selected="true"].is-active {
background: color-mix(in srgb, var(--_color) 20%, transparent);
}
.kt-combobox-option-label {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.kt-combobox-option-label mark {
padding: 0;
background: color-mix(in srgb, var(--_color) 30%, transparent);
color: inherit;
border-radius: 2px;
box-shadow: 0 1px 0 var(--_color);
}
.kt-combobox-check {
flex-shrink: 0;
font-family: var(--font-mono);
font-size: 11px;
font-weight: 700;
color: var(--_color);
opacity: 0;
transform: scale(0.6);
transition: opacity 120ms ease, transform 160ms var(--ease-snap);
}
.kt-combobox-option[aria-selected="true"] .kt-combobox-check {
opacity: 1;
transform: scale(1);
}
.kt-combobox-empty {
padding: 12px 10px;
font-family: var(--font-mono);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
text-align: center;
color: var(--kt-surface-muted);
}
.kt-combobox-status {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/* VFX */
[data-vfx="sakuga"] .kt-combobox-field.is-snapping { animation: kt-combobox-pop 320ms var(--ease-overshoot); }
[data-vfx="elastic"] .kt-combobox-field.is-snapping { animation: kt-combobox-jelly 480ms cubic-bezier(0.34, 1.56, 0.64, 1); }
[data-vfx="glitch"] .kt-combobox-field.is-snapping { animation: kt-combobox-glitch 200ms steps(4, end); }
[data-vfx="neon"] .kt-combobox-field.is-snapping {
box-shadow: 0 0 16px 2px color-mix(in srgb, var(--_color) 80%, transparent);
animation: kt-combobox-pop 300ms var(--ease-snap);
}
[data-vfx="ink"] .kt-combobox-field.is-snapping { animation: kt-combobox-ink 320ms var(--ease-overshoot); }
[data-vfx="neon"] .kt-combobox.is-focus .kt-combobox-field,
[data-vfx="neon"] .kt-combobox.is-open .kt-combobox-field {
box-shadow: 0 0 0 2px color-mix(in srgb, var(--_color) 45%, transparent),
0 0 16px 1px color-mix(in srgb, var(--_color) 50%, transparent);
}
@keyframes kt-combobox-pop {
0% { transform: scale(0.97); }
45% { transform: scale(1.025); }
100% { transform: scale(1); }
}
@keyframes kt-combobox-jelly {
0% { transform: scale(0.96, 1.04); }
35% { transform: scale(1.035, 0.97); }
68% { transform: scale(0.99, 1.01); }
100% { transform: scale(1, 1); }
}
@keyframes kt-combobox-glitch {
0% { transform: translate(-2px, 1px) skewX(-6deg); }
45% { transform: translate(2px, -1px) skewX(5deg); }
100% { transform: translate(0, 0) skewX(0); }
}
@keyframes kt-combobox-ink {
0% { transform: scale(1.04, 0.96) rotate(-2deg); }
55% { transform: scale(0.98, 1.02) rotate(1deg); }
100% { transform: scale(1, 1) rotate(0); }
}
class KtKineticCombobox extends HTMLElement {
static get observedAttributes() {
return ["items", "value", "label", "placeholder", "disabled", "sfx"];
}
constructor() {
super();
this._rendered = false;
this._open = false;
this._typed = false;
this._active = -1;
this._visible = [];
this._popTimer = null;
this._uid = `kt-combobox-${Math.random().toString(36).slice(2, 8)}`;
this._onDocPointerDown = (e) => {
if (this._open && !this.contains(e.target)) this.close({ revert: true });
};
this._onReposition = (e) => {
if (this._open && !(e && e.target instanceof Node && this._menu.contains(e.target))) this.positionMenu();
};
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
}
disconnectedCallback() {
clearTimeout(this._popTimer);
this.teardownGlobal();
}
attributeChangedCallback(name) {
if (!this._rendered) return;
if (name === "items") {
this._typed = false;
this.close();
this.buildOptions();
}
this.syncAttributes();
}
get items() {
return (this.getAttribute("items") || "")
.split(",")
.map((s) => s.trim())
.filter(Boolean);
}
/** The chosen item's text ("" when nothing is chosen). Text, not an index, so reordering items keeps the choice. */
get value() {
const v = (this.getAttribute("value") || "").trim().toLowerCase();
const hit = this.items.find((t) => t.toLowerCase() === v);
return hit || "";
}
set value(val) {
if (val === "" || val === null || val === undefined) this.removeAttribute("value");
else this.setAttribute("value", String(val));
}
get label() { return this.getAttribute("label") || "Choose"; }
get disabled() { return this.hasAttribute("disabled"); }
get sfx() { return this.getAttribute("sfx") ?? "パカッ!"; }
render() {
this.innerHTML = "";
const wrap = document.createElement("div");
wrap.className = "kt-combobox";
wrap.innerHTML = `
<label class="kt-combobox-label"></label>
<div class="kt-combobox-field">
<input class="kt-combobox-input" type="text" role="combobox" aria-autocomplete="list" aria-haspopup="listbox" aria-expanded="false" autocomplete="off" autocapitalize="off" spellcheck="false" />
<button type="button" class="kt-combobox-toggle" tabindex="-1" aria-label="Show options">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3.5 6l4.5 4.5L12.5 6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<div class="kt-combobox-menu" role="listbox" aria-hidden="true"></div>
</div>
<span class="kt-combobox-status" role="status" aria-live="polite"></span>
`;
this._wrap = wrap;
this._labelEl = wrap.querySelector(".kt-combobox-label");
this._field = wrap.querySelector(".kt-combobox-field");
this._input = wrap.querySelector(".kt-combobox-input");
this._toggleBtn = wrap.querySelector(".kt-combobox-toggle");
this._menu = wrap.querySelector(".kt-combobox-menu");
this._status = wrap.querySelector(".kt-combobox-status");
this._input.id = `${this._uid}-input`;
this._labelEl.htmlFor = this._input.id;
this._menu.id = `${this._uid}-list`;
this._labelEl.id = `${this._uid}-label`;
this._menu.setAttribute("aria-labelledby", this._labelEl.id);
this._input.setAttribute("aria-controls", this._menu.id);
this._input.addEventListener("input", () => {
this._typed = true;
this.refresh();
this.open();
});
this._input.addEventListener("keydown", (e) => this.onKeydown(e));
this._input.addEventListener("focus", () => this._wrap.classList.add("is-focus"));
this._input.addEventListener("blur", () => {
this._wrap.classList.remove("is-focus");
// a click on an option or the arrow keeps focus on the input, so a blur really means leaving
this.close({ revert: true });
});
this._input.addEventListener("click", () => {
if (!this.disabled && !this._open) this.open();
});
this._toggleBtn.addEventListener("pointerdown", (e) => e.preventDefault());
this._toggleBtn.addEventListener("click", () => {
if (this.disabled) return;
this._input.focus({ preventScroll: true });
if (this._open) this.close({ revert: true });
else this.open();
});
// keep focus in the input while clicking inside the list
this._menu.addEventListener("pointerdown", (e) => e.preventDefault());
this.buildOptions();
this.appendChild(wrap);
}
buildOptions() {
this._menu.textContent = "";
this._options = this.items.map((text, idx) => {
const opt = document.createElement("div");
opt.className = "kt-combobox-option";
opt.id = `${this._uid}-opt-${idx}`;
opt.setAttribute("role", "option");
opt.setAttribute("aria-selected", "false");
const label = document.createElement("span");
label.className = "kt-combobox-option-label";
const check = document.createElement("span");
check.className = "kt-combobox-check";
check.setAttribute("aria-hidden", "true");
check.textContent = "✓";
opt.append(label, check);
opt.addEventListener("click", () => this.choose(idx));
opt.addEventListener("pointermove", () => {
const pos = this._visible.indexOf(idx);
if (pos !== -1 && pos !== this._active) this.setActive(pos, false);
});
this._menu.appendChild(opt);
return opt;
});
this._empty = document.createElement("div");
this._empty.className = "kt-combobox-empty";
this._empty.textContent = "No matches";
this._empty.hidden = true;
this._menu.appendChild(this._empty);
}
syncAttributes() {
if (!this._input) return;
this._labelEl.textContent = this.label;
this._input.disabled = this.disabled;
this._toggleBtn.disabled = this.disabled;
this._input.placeholder = this.getAttribute("placeholder") || "Search…";
this._wrap.classList.toggle("is-disabled", this.disabled);
if (!this._typed) this._input.value = this.value;
const chosen = this.value;
this._options.forEach((opt, idx) => {
opt.setAttribute("aria-selected", String(this.items[idx] === chosen && chosen !== ""));
});
if (this._open) this.refresh();
}
filtered() {
const q = this._typed ? this._input.value.trim().toLowerCase() : "";
const out = [];
this.items.forEach((t, i) => {
if (!q || t.toLowerCase().includes(q)) out.push(i);
});
return out;
}
refresh() {
const q = this._typed ? this._input.value.trim() : "";
this._visible = this.filtered();
const set = new Set(this._visible);
const items = this.items;
this._options.forEach((opt, idx) => {
opt.hidden = !set.has(idx);
if (set.has(idx)) this.paintLabel(opt.firstChild, items[idx], q);
});
this._empty.hidden = this._visible.length > 0;
// keep the highlighted option if it survived the filter, else take the first (or the chosen one)
const chosenIdx = items.indexOf(this.value);
let pos = this._active >= 0 ? this._visible.indexOf(this._lastActiveIdx) : -1;
if (pos === -1) pos = chosenIdx !== -1 && !q ? this._visible.indexOf(chosenIdx) : q && this._visible.length ? 0 : -1;
this.setActive(pos, false);
this._status.textContent = this._visible.length
? `${this._visible.length} ${this._visible.length === 1 ? "option" : "options"} available`
: "No matches";
if (this._open) this.positionMenu();
}
paintLabel(el, text, q) {
el.textContent = "";
const at = q ? text.toLowerCase().indexOf(q.toLowerCase()) : -1;
if (at === -1) {
el.textContent = text;
return;
}
const mark = document.createElement("mark");
mark.textContent = text.slice(at, at + q.length);
el.append(text.slice(0, at), mark, text.slice(at + q.length));
}
setActive(pos, scroll = true) {
this._active = pos;
this._lastActiveIdx = pos >= 0 ? this._visible[pos] : -1;
this._options.forEach((opt, idx) => opt.classList.toggle("is-active", idx === this._lastActiveIdx));
const opt = this._options[this._lastActiveIdx];
if (opt && this._open) {
this._input.setAttribute("aria-activedescendant", opt.id);
if (scroll) opt.scrollIntoView({ block: "nearest" });
} else {
this._input.removeAttribute("aria-activedescendant");
}
}
onKeydown(e) {
if (this.disabled) return;
const n = this._visible.length;
if (e.key === "ArrowDown") {
e.preventDefault();
if (!this._open) {
this.open();
if (this._active < 0 && this._visible.length) this.setActive(0);
return;
}
if (n) this.setActive(this._active < n - 1 ? this._active + 1 : 0);
} else if (e.key === "ArrowUp") {
e.preventDefault();
if (!this._open) {
this.open();
if (n) this.setActive(n - 1);
return;
}
if (n) this.setActive(this._active > 0 ? this._active - 1 : n - 1);
} else if (e.key === "Enter") {
if (this._open && this._active >= 0) {
e.preventDefault();
this.choose(this._visible[this._active]);
} else if (this._open) {
e.preventDefault();
}
} else if (e.key === "Escape") {
if (this._open) {
e.preventDefault();
e.stopPropagation();
this.close({ revert: true });
}
} else if (e.key === "Tab") {
this.close({ revert: true });
}
}
open() {
if (this._open || this.disabled) return;
this._open = true;
this._wrap.classList.add("is-open");
this._input.setAttribute("aria-expanded", "true");
this._menu.setAttribute("aria-hidden", "false");
this.refresh();
this.positionMenu();
document.addEventListener("pointerdown", this._onDocPointerDown, true);
window.addEventListener("resize", this._onReposition);
window.addEventListener("scroll", this._onReposition, true);
const idx = this._lastActiveIdx;
if (idx >= 0) this.setActive(this._visible.indexOf(idx));
}
close({ revert = false } = {}) {
if (this._open) {
this._open = false;
this._wrap.classList.remove("is-open");
this._input.setAttribute("aria-expanded", "false");
this._input.removeAttribute("aria-activedescendant");
this._menu.setAttribute("aria-hidden", "true");
this.teardownGlobal();
}
if (revert && this._typed) {
this._typed = false;
this._input.value = this.value;
this._active = -1;
}
}
teardownGlobal() {
document.removeEventListener("pointerdown", this._onDocPointerDown, true);
window.removeEventListener("resize", this._onReposition);
window.removeEventListener("scroll", this._onReposition, true);
}
positionMenu() {
const rect = this._field.getBoundingClientRect();
const menu = this._menu;
const width = Math.round(rect.width);
const menuH = menu.offsetHeight;
const below = window.innerHeight - rect.bottom;
const flip = menuH + 12 > below && rect.top > below;
menu.style.width = `${width}px`;
menu.style.left = `${Math.round(rect.left)}px`;
menu.style.maxHeight = `${Math.max(120, Math.min(260, (flip ? rect.top : below) - 14))}px`;
const h = menu.offsetHeight;
menu.style.top = `${Math.round(flip ? rect.top - h - 6 : rect.bottom + 6)}px`;
menu.classList.toggle("is-flipped", flip);
}
clearChoice() {
if (!this.getAttribute("value")) {
this._input.value = "";
return;
}
this.removeAttribute("value");
this._input.value = "";
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: "", index: -1 } }));
}
choose(idx) {
const text = this.items[idx];
if (text === undefined) return;
const changed = text !== this.value;
this._typed = false;
this.setAttribute("value", text);
this._input.value = text;
this.close();
this.syncAttributes();
if (changed) {
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: text, index: idx } }));
}
this.celebrate();
}
celebrate() {
if (SakugaFX.getMode() === "enterprise") return;
this._field.classList.remove("is-snapping");
void this._field.offsetWidth;
this._field.classList.add("is-snapping");
clearTimeout(this._popTimer);
this._popTimer = setTimeout(() => this._field.classList.remove("is-snapping"), 480);
const rect = this._field.getBoundingClientRect();
SakugaFX.emitImpact(rect.left + rect.width / 2, rect.top + rect.height / 2, readAccent(this._wrap), {
sfx: this.sfx,
scale: 0.75,
sfxY: rect.top - 4
});
}
}
customElements.define("kt-kinetic-combobox", KtKineticCombobox);
function contrastInk(hex) {
const clean = hex.replace("#", "");
if (clean.length !== 6) return "#ffffff";
const r = parseInt(clean.slice(0, 2), 16);
const g = parseInt(clean.slice(2, 4), 16);
const b = parseInt(clean.slice(4, 6), 16);
const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return lum > 0.6 ? "#09090b" : "#ffffff";
}
function readAccent(el) {
const val = getComputedStyle(el).getPropertyValue("--kt-accent").trim();
return val || "#09090b";
}
class SakugaVFXEngine {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.rafId = null;
this.lastTime = 0;
this.textEnabled = false;
this.textOverride = "";
this.vfxTextColor = "auto";
this.resize();
window.addEventListener("resize", () => this.resize());
}
attach(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.resize();
}
resize() {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
this.canvas.width = Math.floor(window.innerWidth * dpr);
this.canvas.height = Math.floor(window.innerHeight * dpr);
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
getMode() {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "enterprise";
return document.documentElement.getAttribute("data-vfx") || "enterprise";
}
wake() {
if (this.rafId !== null) return;
this.lastTime = performance.now();
const tick = (now) => {
const dt = Math.min((now - this.lastTime) / 1000, 0.05);
this.lastTime = now;
this.render(dt);
if (this.items.length > 0) {
this.rafId = requestAnimationFrame(tick);
} else {
this.rafId = null;
this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
}
};
this.rafId = requestAnimationFrame(tick);
}
emitBurst(x, y, color, { count = 14, speed = 240, spread = Math.PI * 2, baseAngle = 0, shards = true } = {}) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < count; i++) {
const angle = baseAngle + (Math.random() - 0.5) * spread;
const vel = speed * (0.45 + Math.random() * 0.75);
this.items.push({
kind: shards && i % 3 === 0 ? "shard" : "spark",
x, y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - (spread > 4 ? 35 : 0),
gravity: 400,
drag: 0.94,
size: 3 + Math.random() * 4,
rot: Math.random() * Math.PI * 2,
vrot: (Math.random() - 0.5) * 14,
life: 0,
maxLife: 0.32 + Math.random() * 0.22,
color
});
}
this.wake();
}
emitShockwave(x, y, color, maxRadius = 64) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "ring", x, y, radius: 8, maxRadius, life: 0, maxLife: 0.32, color });
this.wake();
}
emitSlash(x, y, color, angle = -0.3) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "slash", x, y, angle, length: 96, life: 0, maxLife: 0.2, color });
this.wake();
}
emitSmoke(x, y, color, dirX = 0) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < 4; i++) {
this.items.push({
kind: "smoke",
x: x + (Math.random() - 0.5) * 8,
y: y + (Math.random() - 0.5) * 8,
vx: dirX * (50 + Math.random() * 70) + (Math.random() - 0.5) * 35,
vy: -20 - Math.random() * 50,
size: 5 + Math.random() * 5,
life: 0,
maxLife: 0.34 + Math.random() * 0.16,
color
});
}
this.wake();
}
emitPixels(x, y, color, count = 14) {
if (this.getMode() !== "glitch") return;
for (let i = 0; i < count; i++) {
const angle = Math.floor(Math.random() * 8) * (Math.PI / 4);
const vel = 120 + Math.random() * 200;
this.items.push({
kind: "pixel",
x: x + (Math.random() - 0.5) * 18,
y: y + (Math.random() - 0.5) * 12,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel,
size: 4 + Math.floor(Math.random() * 5),
life: 0,
maxLife: 0.24 + Math.random() * 0.14,
color
});
}
this.wake();
}
emitScanline(x, y, color, width = 120) {
if (this.getMode() !== "glitch") return;
for (let i = -1; i <= 1; i += 2) {
this.items.push({
kind: "scanline",
x,
y: y + i * (5 + Math.random() * 6),
width,
life: 0,
maxLife: 0.18,
color
});
}
this.wake();
}
emitRays(x, y, color, count = 10, maxRadius = 72) {
if (this.getMode() !== "neon") return;
for (let i = 0; i < count; i++) {
const angle = (Math.PI * 2 * i) / count + (Math.random() - 0.5) * 0.18;
this.items.push({
kind: "ray",
x,
y,
angle,
maxRadius: maxRadius * (0.75 + Math.random() * 0.45),
life: 0,
maxLife: 0.34,
color
});
}
this.wake();
}
emitInkSplatter(x, y, color, count = 14) {
if (this.getMode() !== "ink") return;
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const vel = 110 + Math.random() * 230;
this.items.push({
kind: "inkblot",
x,
y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - 30,
gravity: 480,
drag: 0.91,
size: 2.5 + Math.random() * 5.5,
life: 0,
maxLife: 0.38 + Math.random() * 0.22,
color
});
}
// Brush arc sweep
this.items.push({
kind: "brusharc",
x,
y,
radius: 24 + Math.random() * 14,
startAngle: -Math.PI * 0.75,
endAngle: Math.PI * 0.35,
life: 0,
maxLife: 0.26,
color
});
this.wake();
}
emitMangaSFX(x, y, text, color) {
const mode = this.getMode();
const finalText = this.textOverride || text;
if (mode === "enterprise" || !this.textEnabled || !finalText || finalText === "none") return;
const fillColor = this.vfxTextColor !== "auto" ? this.vfxTextColor : color;
const outline = this.vfxTextColor !== "auto"
? contrastInk(this.vfxTextColor)
: (document.documentElement.getAttribute("data-bw") === "dark" ? "#09090b" : "#ffffff");
this.items.push({
kind: "sfx",
x: x + (Math.random() - 0.5) * 14,
y: y - 16,
vy: -48,
tilt: (Math.random() - 0.5) * 0.26,
text: finalText,
life: 0,
maxLife: 0.6,
color: fillColor,
outline
});
this.wake();
}
emitImpact(x, y, color, { sfx = "", scale = 1, dirX = 0, sfxY = y - 4 } = {}) {
const mode = this.getMode();
if (mode === "enterprise") return;
if (mode === "elastic") {
this.emitShockwave(x, y, color, Math.round(52 * scale));
this.emitSmoke(x, y, color, dirX);
} else if (mode === "glitch") {
this.emitPixels(x, y, color, Math.round(12 * scale));
this.emitScanline(x, y, color, Math.round(96 * scale));
} else if (mode === "neon") {
this.emitShockwave(x, y, color, Math.round(58 * scale));
this.emitRays(x, y, color, Math.round(9 * scale), Math.round(52 * scale));
} else if (mode === "ink") {
this.emitInkSplatter(x, y, color, Math.round(13 * scale));
} else {
this.emitShockwave(x, y, color, Math.round(50 * scale));
this.emitBurst(x, y, color, {
count: Math.round(12 * scale),
speed: Math.round(210 * scale),
spread: dirX ? 1.8 : Math.PI * 2,
baseAngle: dirX < 0 ? Math.PI : 0
});
this.emitSlash(x, y, color, -0.28);
}
this.emitMangaSFX(x, sfxY, sfx, color);
}
render(dt) {
const ctx = this.ctx;
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
const next = [];
for (const p of this.items) {
p.life += dt;
if (p.life >= p.maxLife) continue;
const t = p.life / p.maxLife;
const easeOut = 1 - Math.pow(1 - t, 3);
const alpha = Math.max(0, 1 - Math.pow(t, 2));
ctx.save();
ctx.globalAlpha = alpha;
if (p.kind === "spark" || p.kind === "shard") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.rot += p.vrot * dt;
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
ctx.fillStyle = p.color;
if (p.kind === "shard") {
const s = p.size * (1 - t * 0.4);
ctx.beginPath();
ctx.moveTo(0, -s);
ctx.lineTo(s * 0.72, 0);
ctx.lineTo(0, s);
ctx.lineTo(-s * 0.72, 0);
ctx.closePath();
ctx.fill();
} else {
ctx.beginPath();
ctx.arc(0, 0, p.size * 0.5 * (1 - t * 0.5), 0, Math.PI * 2);
ctx.fill();
}
} else if (p.kind === "ring") {
const r = p.radius + (p.maxRadius - p.radius) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineWidth = Math.max(1, 3 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.stroke();
} else if (p.kind === "slash") {
ctx.translate(p.x, p.y);
ctx.rotate(p.angle);
const len = p.length * easeOut;
const th = 4.5 * (1 - t);
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.moveTo(-len, 0);
ctx.quadraticCurveTo(0, -th, len, 0);
ctx.quadraticCurveTo(0, th, -len, 0);
ctx.fill();
} else if (p.kind === "smoke") {
p.x += p.vx * dt;
p.y += p.vy * dt;
const r = p.size * (0.8 + easeOut * 1.25);
ctx.fillStyle = p.color;
ctx.globalAlpha = 0.24 * (1 - t);
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "pixel") {
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
const s = p.size * (1 - t * 0.35);
ctx.fillRect(Math.round(p.x - s / 2), Math.round(p.y - s / 2), s, s);
} else if (p.kind === "scanline") {
const w = p.width * (0.4 + easeOut * 0.8);
ctx.fillStyle = p.color;
ctx.fillRect(p.x - w / 2, p.y, w, 2);
} else if (p.kind === "ray") {
const inner = 12 + easeOut * 16;
const outer = inner + p.maxRadius * (1 - t * 0.35);
ctx.strokeStyle = p.color;
ctx.shadowColor = p.color;
ctx.shadowBlur = 10;
ctx.lineWidth = Math.max(1, 2.8 * (1 - t));
ctx.beginPath();
ctx.moveTo(p.x + Math.cos(p.angle) * inner, p.y + Math.sin(p.angle) * inner);
ctx.lineTo(p.x + Math.cos(p.angle) * outer, p.y + Math.sin(p.angle) * outer);
ctx.stroke();
} else if (p.kind === "inkblot") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * (1 - t * 0.45), 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "brusharc") {
const sweep = p.startAngle + (p.endAngle - p.startAngle) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineCap = "round";
ctx.lineWidth = Math.max(1.5, 6 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius * (0.85 + easeOut * 0.4), p.startAngle, sweep);
ctx.stroke();
} else if (p.kind === "sfx") {
p.y += p.vy * dt * (1 - t * 0.6);
const s = t < 0.18 ? 0.55 + (t / 0.18) * 0.65 : 1.2 - (t - 0.18) * 0.25;
ctx.translate(p.x, p.y);
ctx.rotate(p.tilt);
ctx.scale(s, s);
ctx.font = '900 19px "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif';
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineJoin = "round";
ctx.lineWidth = 4.5;
ctx.strokeStyle = p.outline;
ctx.strokeText(p.text, 0, 0);
ctx.fillStyle = p.color;
ctx.fillText(p.text, 0, 0);
}
ctx.restore();
next.push(p);
}
this.items = next;
}
}
const SakugaFX = new SakugaVFXEngine(document.getElementById("sakuga-vfx-canvas"));
window.SakugaFX = SakugaFX;
window.readAccent = readAccent;
window.contrastInk = contrastInk;
Attributes
| Name | What it does | Default |
|---|---|---|
items | Comma separated options. | — |
value | The chosen option as its text (not an index), so reordering items keeps the choice. Empty or unknown means nothing chosen. | — |
label | Text above the field. | Choose |
placeholder | Hint shown while the field is empty. | Search… |
disabled | Present when the field cannot be used. | — |
sfx | Sound-effect text on choosing an option. | パカッ! |
Keyboard and screen readers
- The input has role="combobox" with aria-expanded, aria-controls and aria-autocomplete="list"; the list is a listbox of options.
- Focus stays in the input; the highlighted option is exposed with aria-activedescendant.
- Typing filters the options and opens the list; ArrowDown and ArrowUp move the highlight (wrapping); Enter chooses it.
- Escape closes the list and restores the chosen text; Tab or clicking away does the same.
- A polite status announces the number of matches, or "No matches". Fires change with { value, index }.
Styling variables
Every look is a CSS variable: --kt-accent, --kt-accent-ink, --kt-radius-btn, --kt-surface-radius, --kt-surface-bg, --kt-border-w, --kt-comp-shadow and --font-sans. The
copied file sets them all from your choices.
FAQ
Kinetic Combobox: questions answered
How do I use the Kinetic Combobox?
Press Copy on the card to get a complete HTML file, or copy the HTML, CSS and JavaScript tabs into your own page. In your markup the element is written as <kt-kinetic-combobox>.
Which attributes does <kt-kinetic-combobox> accept?
items, value, label, placeholder, disabled, sfx. Each one is described in the attributes table on this page.
Is the Kinetic Combobox accessible?
The input has role="combobox" with aria-expanded, aria-controls and aria-autocomplete="list"; the list is a listbox of options. Focus stays in the input; the highlighted option is exposed with aria-activedescendant. Typing filters the options and opens the list; ArrowDown and ArrowUp move the highlight (wrapping); Enter chooses it. Escape closes the list and restores the chosen text; Tab or clicking away does the same. A polite status announces the number of matches, or "No matches". Fires change with { value, index }.
Can I change the Kinetic Combobox colors, corners and font?
Yes. Use the options on this page: accent color, border radius, background, border, shadow and Google font. The copied code already contains your choices, and every one of them is a CSS variable you can edit later.