Overlays
Dropdown menu
A button that reveals a list of links and actions, built on <details>. It opens without JavaScript; in the browser, Escape, a click outside and a chosen action close it.
JxDropdownMenu
import 'package:jx_cli/ui.dart'
New in 0.0.3
Preview
Choose an action.
When to use it
- An account menu.
- Secondary actions of a row or a card ("Duplicate", "Delete").
Minimal example
JxDropdownMenu(
id: 'account',
label: 'Account',
items: [
JxMenuItem(label: 'Profile', href: '/profile'),
JxMenuItem(label: 'Sign out', href: '/sign-out'),
],
)
Complete example
A full Jaspr component you can paste into a project.
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';
/// Row actions; the destructive one is separated and red.
@client
class ProjectActions extends StatelessComponent {
const ProjectActions({required this.projectId, required this.onDelete, super.key});
final String projectId;
final VoidCallback onDelete;
@override
Component build(BuildContext context) {
return JxDropdownMenu(
id: 'actions-$projectId',
label: 'Actions',
variant: JxButtonVariant.ghost,
size: JxButtonSize.sm,
align: JxMenuAlign.end,
items: [
JxMenuItem(label: 'Open', href: '/projects/$projectId'),
JxMenuItem(label: 'Settings', href: '/projects/$projectId/settings'),
const JxMenuItem.separator(),
JxMenuItem(label: 'Delete', danger: true, onSelect: onDelete),
],
);
}
}
Properties
| Property | Type | Default | Description |
|---|---|---|---|
id |
String |
required |
Id of the
<details>
; unique on the page.
|
label |
String |
required |
Text of the trigger button. |
items |
List<JxMenuItem> |
required |
Links, actions and separators. |
variant |
JxButtonVariant |
outline |
Style of the trigger, as for
JxButton
.
|
size |
JxButtonSize |
md |
Size of the trigger. |
align |
JxMenuAlign |
start |
Lines the list up with the
start
or
end
of the trigger.
|
classes |
String? |
null |
Extra JX classes, appended after the component classes. |
Related types
| Name | Role |
|---|---|
JxMenuItem(label:, href:, onSelect:, danger:, disabled:)
|
A link (
href
) or an action (
onSelect
).
|
JxMenuItem.separator()
|
A line between groups. |
JxMenuAlign |
start, end. |
Customizing
-
Pass
classesto add or override utilities: they come last, soclasses: 'w:full'wins over the default width. - The trigger uses the button styles; the list the surface border and shadow of cards.
Responsive
-
Use
align: JxMenuAlign.endnear the right edge so the list stays on screen.
Accessibility
-
A disclosure: the trigger is a native
<summary>announced as expanded or collapsed; Tab moves through the entries. -
Entries are real links and buttons; a disabled link loses its
hrefand getsaria-disabled. - In the browser, Escape closes the list and gives the focus back to the trigger; a click or tap outside closes it too.
Limitations
- Rendered on the server alone, only the trigger closes it.
-
Not an ARIA
menu: no arrow-key navigation between entries. -
The list opens below the trigger and can be clipped by a parent with
ov:hidden.