Skip to content

Dynamic width for autocomplete suggestions dropdown widget #173

Open
hexycat wants to merge 3 commits intoMaxteabag:mainfrom
hexycat:autocomplete-dropdown-dynamic-width
Open

Dynamic width for autocomplete suggestions dropdown widget #173
hexycat wants to merge 3 commits intoMaxteabag:mainfrom
hexycat:autocomplete-dropdown-dynamic-width

Conversation

@hexycat
Copy link
Copy Markdown

@hexycat hexycat commented Apr 12, 2026

Summary

The width of the AutocompleteDropdown widget is now explicitly set on every call of the set_items method, determined by the longest item in the visible suggestion list plus border/padding/scrollbar offsets.

Reason

Currently the width of the dropdown is always set to min-width regardless of its content or the max-width value. The likely reason is related to the width: auto CSS property of the dropdown combined with the width CSS property of the parent container, which results in the width being constrained to min-width.

This is especially noticeable when table names share long identical prefixes.
In such case suggestions may look like this:
image

After changes:
image

Changes

  1. Add _update_width method to AutocompleteDropdown class.
    It computes and sets the width of the dropdown from the longest visible suggestion plus border/padding/scrollbar offsets, clamped between MIN_WIDTH (25) and MAX_WIDTH (80).
    The method is called at the end of set_items, so the width is updated whenever the list of visible suggestions changes
  2. Add UI tests tests/ui/test_autocomplete_dropdown.py covering the new expected width behaviour of AutocompleteDropdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant