惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
博客园 - Franky
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 叶小钗
罗磊的独立博客
The GitHub Blog
The GitHub Blog
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
N
Netflix TechBlog - Medium
T
The Exploit Database - CXSecurity.com
云风的 BLOG
云风的 BLOG
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
Cyberwarzone
Cyberwarzone
T
Threatpost
T
Threat Research - Cisco Blogs
Recent Announcements
Recent Announcements
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
量子位
V
V2EX
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed
I
Intezer
Schneier on Security
Schneier on Security
雷峰网
雷峰网
B
Blog RSS Feed
Jina AI
Jina AI
爱范儿
爱范儿
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
美团技术团队
博客园 - 【当耐特】

Aaron Gustafson: Latest Posts & Links

LLM biased against accessible code (Claude Code issue #56079) :: Aaron Gustafson Can Your AI Pass the Accessibility Test? :: Aaron Gustafson Can Your AI Pass the Accessibility Test? :: Aaron Gustafson Fixing Accessibility After the Fact Is Too Late :: Aaron Gustafson Easy Data-entry Verification with a Web Component :: Aaron Gustafson Artificial Intelligence Has One Chance To Get Accessibility Right :: Aaron Gustafson Building a general-purpose accessibility agent—and what we learned in the process :: Aaron Gustafson Fixing Accessibility After the Fact Is Too Late :: Aaron Gustafson AI companies will fail. We can salvage something from the wreckage :: Aaron Gustafson Accessible faux-nested interactive controls :: Aaron Gustafson AI-assisted coding transforms PDF to web app using NYS Design System :: Aaron Gustafson Modern CSS Feature Support For Shadow DOM :: Aaron Gustafson AI is locking people out. At Scale. :: Aaron Gustafson The Incredible Overcomplexity of the Shadcn Radio Button :: Aaron Gustafson Accessibility in the End of Deterministic Design (Again) :: Aaron Gustafson Making keyboard navigation effortless :: Aaron Gustafson The WebAIM Million: The 2026 report on the accessibility of the top 1,000,000 home pages :: Aaron Gustafson Under the hood of MDN’s new frontend :: Aaron Gustafson Endgame for the Open Web :: Aaron Gustafson slideVars :: Aaron Gustafson AI is accidently making documentation accessible :: Aaron Gustafson Design systems can’t automate away all of your accessibility considerations :: Aaron Gustafson The Power of ‘No’ in Internet Standards :: Aaron Gustafson Nice Select :: Aaron Gustafson Visual Validation Feedback for Form Fields :: Aaron Gustafson Never Lose Form Progress Again :: Aaron Gustafson Different contexts, different tools, same person :: Aaron Gustafson Accessibility Assistant for Figma v52 :: Aaron Gustafson Some blind fans to experience Super Bowl with tactile device that tracks ball :: Aaron Gustafson Why we teach our students progressive enhancement :: Aaron Gustafson Repeatable Form Fields Made Simple :: Aaron Gustafson A Production-Ready Web Component Starter Template :: Aaron Gustafson Fullscreen Video and Iframes Made Easy :: Aaron Gustafson Lazy Loading Images Based on Screen Size :: Aaron Gustafson A Web Component for Obfuscating Form Fields :: Aaron Gustafson Forrester Research: As technology has evolved, so has the need for accessibility :: Aaron Gustafson Creating a more accessible web with ARIA Notify :: Aaron Gustafson Optimizing Your Codebase for AI Coding Agents :: Aaron Gustafson A Web Component for Conditionally Displaying Fields :: Aaron Gustafson Default Isn’t Design :: Aaron Gustafson Identifying Accessibility Data Gaps in CodeGen Models :: Aaron Gustafson Designing for Distress: Understanding Users in Crisis :: Aaron Gustafson Why I'm Betting Against AI Agents in 2025 (Despite Building Them) :: Aaron Gustafson Why AI Won’t Destroy Us with Microsoft’s Brad Smith :: Aaron Gustafson Learning Web Design, 6th Edition is out! :: Aaron Gustafson
Dynamic Datalist: Autocomplete from an API :: Aaron Gustafson
Aaron Gustafson · 2025-12-16 · via Aaron Gustafson: Latest Posts & Links

HTML’s datalist element provides native autocomplete functionality, but it’s entirely static—you have to know all the options up front. The dynamic-datalist web component solves this by fetching suggestions from an API endpoint as users type, giving you the benefits of native autocomplete with the flexibility of dynamic data.

This component is a modern replacement for my old jQuery predictive typing plugin. I’ve reimagined it as a standards-based web component.

Basic usage

To use the component, wrap it around your input field and specify an endpoint:

<dynamic-datalist endpoint="/api/search">
  <label for="search"
    >Search
    <input
      type="text"
      id="search"
      name="search"
      placeholder="Type to search..."
    />
  </label>
</dynamic-datalist>

As users type, the component makes GET requests to that endpoint, passing in the typed value as the “query” parameter (e.g., /api/search?query=WHAT_THE_USER_TYPED). The response from the endpoint is used to populates a dynamic datalist element with the results.

The structure of the response should be JSON with an options array of string values:

{
  "options": ["option 1", "option 2", "option 3"]
}

How it works

Under the hood, the component:

  1. Adopts (or creates) a datalist element for your input,
  2. Listens for “input” events,
  3. Debounces requests (waiting at least 250ms) to avoid overwhelming your API,
  4. Sends requests to your endpoint with the current value of the input,
  5. Reads back the JSON response,
  6. Updates the datalist option elements, and
  7. Dispatches the update event.

All of this happens transparently—users just see autocomplete suggestions appearing as they type.

Need POST?

You can change the submission method via the method attribute:

<dynamic-datalist endpoint="/api/lookup" method="post">
  <label for="lookup"
    >Lookup
    <input type="text" id="lookup" name="lookup" />
  </label>
</dynamic-datalist>

This sends a POST request with a JSON body: { "query": "..." }. Currently GET and POST are supported, but I could add more if folks want them.

Custom variable names

As I mentioned, the component uses “query” as the parameter name by default, but you can easily change it via the key attribute:

<dynamic-datalist endpoint="/api/terms" key="term">
  <label for="search"
    >Term search
    <input type="text" id="search" name="term" />
  </label>
</dynamic-datalist>

This sends the GET request /api/terms?term=....

Working with existing datalists

If your input already has a datalist defined, the component will inherit it and replace the existing options with the fetched results, which makes for a nice progressive enhancement:

<dynamic-datalist endpoint="/api/cities">
  <label for="city"
    >City
    <input
      type="text"
      id="city"
      list="cities-list"
      placeholder="Type a city…"
    />
  </label>
  <datalist id="cities-list">
    <option>New York</option>
    <option>Los Angeles</option>
    <option>Chicago</option>
  </datalist>
</dynamic-datalist>

Users see the pre-populated cities immediately, and as they type, API results supplement the list. If JavaScript fails or the web component doesn’t load, users still get the static options. Nothing breaks.

Event handling

If you want to tap into the component’s event system, it fires three custom events:

  • dynamic-datalist:ready - Fired when the component initializes
  • dynamic-datalist:update - Fired when the datalist is updated with new options
  • dynamic-datalist:error - Fired when an error occurs fetching data
const element = document.querySelector("dynamic-datalist");

element.addEventListener("dynamic-datalist:ready", (e) => {
  console.log("Component ready:", e.detail);
});

element.addEventListener("dynamic-datalist:update", (e) => {
  console.log("Options updated:", e.detail.options);
});

element.addEventListener("dynamic-datalist:error", (e) => {
  console.error("Error:", e.detail.error);
});

Each event provides helpful detail objects with references to the input, datalist, and other relevant data.

Demo

Check out the demo for live examples (there are also unpkg and ESM builds if you want to test CDN delivery):

Grab it

The project is available on GitHub. You can also install via npm:

npm install @aarongustafson/dynamic-datalist

If you go that route, there are a few ways to register the element depending on your build setup:

Option 1: Define it yourself

import { DynamicDatalistElement } from "@aarongustafson/dynamic-datalist";

customElements.define("dynamic-datalist", DynamicDatalistElement);

Option 2: Let the helper guard registration

import "@aarongustafson/dynamic-datalist/define.js";
// or, when you need to wait:
import { defineDynamicDatalist } from "@aarongustafson/dynamic-datalist/define.js";

defineDynamicDatalist();

Option 3: Drop the helper in via a <script> tag

<script
  src="./node_modules/@aarongustafson/dynamic-datalist/define.js"
  type="module"
></script>

Regardless of how you register it, there are no framework dependencies—just clean autocomplete powered by your API. As I mentioned, it’s also available via CDNs, such as unpkg too, if you’d prefer to go that route.