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

推荐订阅源

Recorded Future
Recorded Future
C
Cyber Attacks, Cyber Crime and Cyber Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Google Online Security Blog
Google Online Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
WordPress大学
WordPress大学
博客园 - 聂微东
L
LINUX DO - 最新话题
月光博客
月光博客
小众软件
小众软件
T
Troy Hunt's Blog
A
Arctic Wolf
量子位
I
Intezer
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
有赞技术团队
有赞技术团队
N
News and Events Feed by Topic
美团技术团队
The Cloudflare Blog
P
Privacy International News Feed
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
N
News | PayPal Newsroom
Apple Machine Learning Research
Apple Machine Learning Research
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
V
Vulnerabilities – Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
Hacker News: Ask HN
Hacker News: Ask HN
雷峰网
雷峰网

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.