Categories: CSSScriptWeb Design

Floating Autocomplete Box For Textarea – floatype.js

floatype.js is a lightweight and fast JavaScript library that adds autocomplete/autosuggestion functionality to textareas.

As soon as you start typing characters into a textarea, the library automatically displays a floating dropdown box next to the cursor with preset suggestions to choose from.

See Also:

How to use it:

1. Install and import the floatype.js library.

# NPM
$ npm i @knadh/floatype
// ES module
import { floatype } from @knadh/floatype;
// Browser
<script type="module">
  import { floatype } from './floatype.js';
</script>

2. Define an array of suggestions as follows:

const myData = ["CSS", "Script", "Com"];

3. Initialize the floatype.js on your textarea element and enable the autocomplete functionality using the onQuery.

floatype(document.querySelector("textarea"), {
  onQuery: async (val) => {
  // This callback returns an array of search results.
  // Typically, this will be a server side fetch() request.
  // Example:
  //    const resp = await fetch(`/search?q=${query}`);
  //    const res = await response.json();
  //    return res;
  const q = val.trim().toLowerCase();
  return myData.filter(s => s.startsWith(q)).slice(0, 10);
  }
});

4. Apply your own CSS styles to the autocomplete list.

.floatype {
  /* styles here */}

.floatype-item {
  /* styles here */}

.floatype-item:hover {
  /* styles here */}

.floatype-sel {
  /* styles here */}

Changelog:

v1.2.2 (04/30/2025)

  • Bugfixes

The post Floating Autocomplete Box For Textarea – floatype.js appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

Pittsburgh Post-Gazette Will Stay Open After Journalism Nonprofit Purchases It

NEW YORK (AP) — Barely two weeks before it was due to shut down, the…

13 minutes ago

Petroleum Analysis Patrick DeHaan On Gas In Indiana

FORT WAYNE, Ind. (WOWO) — Recent announcements from President Trump regarding an Iranian blockade are…

19 minutes ago

Daredevil: Born Again Season 2, Episode 5 Review

Full spoilers follow for Daredevil: Born Again Season 2, Episode 5, "The Grand Design,” which…

1 hour ago

Save 50% Off the Baseus Pico AM52, One of the First Qi2.2 MagSafe Power Banks on the Market

There's a new super-fast wireless power bank in town, with an opportunity to get it…

1 hour ago

Expand Your Home Gym on the Cheap With the Yoleo Weight Bench for Just $55.49 Shipped

Looking to expand your home gym on the cheap? For this week only, one of…

2 hours ago

The Dungeon Crawler RPG Crowdfunding Campaign Just Launched and Has Already Decimated Its Goals

The Dungeon Crawler Carl books are having a moment right now. Matt Dinniman's popular LitRPG…

2 hours ago

This website uses cookies.