Overflow Menu for Bricks
A nestable Bricks element for a row of links that never wraps and never gets squashed. Whatever does not fit moves into a More menu. It measures the space it sits in, so the same menu works in a header, a narrow column or a sidebar.
Version: 0.1.2 · Requires: WordPress 6.0+, PHP 8.1+, Bricks · See the live demo
What it does
- Shows as many items as fit, in their original order, and moves the rest into a dropdown button, last item first.
- Shows a count of the hidden items on the button, if you want it.
- Moves items back as soon as space returns, when a window or a column is resized.
- Items are normal Bricks elements (links, buttons, icons or anything else), moved rather than copied, so their classes, ids and behaviour are kept.
Installation
- Upload and activate the plugin. Bricks must be active.
- In the Bricks editor search for Overflow Menu (General group). It arrives with seven sample links.
Quick start
- Edit the sample links, or replace them with your own elements.
- Add items with the plus button on the element in the structure panel, or by duplicating one.
- Open Menu settings and set the button label, the count and the minimum number of items to keep visible.
Settings
Menu
- Button label — default More
- Show count — a badge with the number of hidden items
- Always keep visible — the least number of items that stay in the row (default: 1)
- Menu opens from — the right edge (default) or the left edge of the button
- Accessible name — read by screen readers
Style
- Item alignment and Gap
- Button background, text, border and radius
- Badge background and text
- Menu background, radius, minimum width and hover background
How it is built
- The items sit in a row that does not wrap. A small script compares the row to its container, then moves items that overflow into the menu. A resize observer repeats this when the space changes.
- The button has
aria-expandedandaria-controls. Escape closes the menu and returns focus to the button, and so does clicking outside it or choosing an item.
Tips
- Give the menu a width. Put it in a block or column with a set width, or a flex item with
min-width:0, so it can shrink. - Keep item labels short. Long labels use up the row quickly.
- Use Always keep visible to protect the important links, such as Home or Contact.
Known limits
- The first paint happens before the script runs, so a menu that is too wide for its space can flicker for a moment on a slow page.
- The measurement uses the width of each item. Items with dynamic widths, such as a search box, are best kept outside the element.