![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
textual-autocomplete
Advanced tools
textual-autocomplete is a Python library for creating dropdown autocompletion menus in Textual applications, allowing users to quickly select from a list of suggestions as they type. textual-autocomplete supports Textual version 0.14.0 and above.
https://user-images.githubusercontent.com/5740731/205718330-a9364894-9133-40ca-8249-6e3dcc13f456.mov
Warning Textual still has a major version number of
0
, meaning there are still significant API changes happening which can sometimes impact this project. I'll do my best to keep it compatible with the latest version of Textual, but there may be a slight delay between Textual releases and this library working with said release.
Simply wrap a Textual Input
widget as follows:
from textual.app import ComposeResult
from textual.widgets import Input
from textual_autocomplete import AutoComplete, Dropdown, DropdownItem
def compose(self) -> ComposeResult:
yield AutoComplete(
Input(placeholder="Type to search..."),
Dropdown(items=[
DropdownItem("Glasgow"),
DropdownItem("Edinburgh"),
DropdownItem("Aberdeen"),
DropdownItem("Dundee"),
]),
)
There are more complete examples here.
textual-autocomplete
can be installed from PyPI using your favourite dependency
manager.
Input
As shown in the quickstart, you can wrap the Textual builtin Input
widget with
AutoComplete
, and supply a Dropdown
.
The AutoComplete
manages communication between the Input
and the Dropdown
.
The Dropdown
is the widget you see on screen, as you type into the input.
The DropdownItem
s contain up to 3 columns. All must contain a "main" column, which
is the central column used in the filtering. They can also optionally contain a left and right metadata
column.
Dropdown
You can supply the data for the dropdown via a list or a callback function.
The easiest way to use textual-autocomplete is to pass in a list of DropdownItem
s,
as shown in the quickstart.
Instead of passing a list of DropdownItems
, you can supply a callback function
which will be called with the current input state. From this function, you should
return the list of DropdownItems
you wish to be displayed.
See here for a usage example.
The Dropdown
itself can be styled using Textual CSS.
For more fine-grained control over styling, you can target the following CSS classes:
.autocomplete--highlight-match
: the highlighted portion of a matching item.autocomplete--selection-cursor
: the item the selection cursor is on.autocomplete--left-column
: the left metadata column, if it exists.autocomplete--right-column
: the right metadata column, if it existsSince the 3 columns in DropdownItem
support Rich Text
objects, they can be styled dynamically.
The custom_meta.py file is an example of this, showing how the rightmost column is coloured dynamically based on the city population.
The examples directory contains multiple examples of custom styling.
When you select an item in the dropdown, an AutoComplete.Selected
event is emitted.
You can declare a handler for this event on_auto_complete_selected(self, event)
to respond
to an item being selected.
An item is selected when it's highlighted in the dropdown, and you press Enter or Tab.
Pressing Enter simply fills the value in the dropdown, whilst Tab fills the value and then shifts focus from the input.
Screen
that the AutoComplete
is on. The Dropdown
will be rendered on this layer.Input
. This means if your Input
is at the bottom of the screen, it's probably not going to be much use for now. I'm happy to discuss or look at PRs that offer a flag for having it float above.margin
to the Dropdown
. The position of the dropdown is updated by applying margin to the top/left of it.FAQs
Easily add autocomplete dropdowns to your Textual apps.
We found that textual-autocomplete demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.