A menu of actions or links that opens from a button.
Mirrors Dropdown from @digdir/designsystemet-react.
import Designsystemet.Dropdown as Dropdown
caseActions : Dropdown.Id
caseActions =
Dropdown.id "case-actions"
view : Html Msg
view =
Html.div []
[ Dropdown.trigger caseActions [ Button.secondary ] [ Html.text "Handlinger" ]
, Dropdown.view caseActions
[]
[ Dropdown.heading Heading.H2 [] [ Html.text "Sak 42" ]
, Dropdown.list []
[ Dropdown.item [] [ Dropdown.button [ Events.onClick Archive ] [ Html.text "Arkiver" ] ]
, Dropdown.item [] [ Dropdown.button (Dialog.showModal confirmDelete) [ Html.text "Slett" ] ]
]
]
]A dropdown is a Popover with menu styling. The
browser opens it from the trigger and closes it on Esc or an outside click;
designsystemet-web positions it. Dropdown.Id is a separate type, so a
popover's id can't open a dropdown by mistake.
<Dropdown id="x"> → Dropdown.view (Dropdown.id "x") []<Dropdown.TriggerContext> → not needed: share a Dropdown.Id<Dropdown.Trigger> → Dropdown.trigger id []<Dropdown.Heading> (level 2 by default) → Dropdown.heading Heading.H2 []<Dropdown.List> → Dropdown.list []<Dropdown.Item> → Dropdown.item []<Dropdown.Button> → Dropdown.button []placement="top" → Dropdown.placement Placement.Topopen={isOpen} (controlled) → Dropdown.open model.isOpenonOpen / onClose → Dropdown.onToggleLike Popover, the dropdown is popover="auto",
so the browser handles light dismiss, which React does in JavaScript.
As for Popover: the position styles
(translate, scroll-margin-bottom, max-height, width), the arrow's
--_ds-floating-arrow-* properties and data-floating. Style the dropdown
with classes instead of Attr.style.
The DOM id, for ports and tests.
A <div class="ds-dropdown" popover>, by default below its trigger and
aligned to its end edge.
The id always comes from the Id, so triggers keep pointing at it.
An Attr.id in the attributes is ignored.
Where the dropdown appears relative to its trigger. Defaults to
Placement.BottomEnd.
A heading for the menu or a group in it. As with
Heading, the level is required. React defaults to
H2, but the right level depends on the surrounding page.
Dropdown.heading Heading.H3 [] [ Html.text "Sortering" ]The <ul> of menu items. To group items, use several, each after its own
heading.
A full-width, tertiary Button for a menu item.
For a link, use Button.viewAs Html.a [ Button.tertiary, Attr.href "…" ].
The dropdown styles it the same way.
A Button that opens and closes the dropdown.
Dropdown.trigger userMenu [ Button.tertiary ] [ Html.text "Kari Nordmann" ]Open the dropdown if closed, close it if open. Concatenate with your own attributes on any button:
Button.icon { label = "Flere valg", icon = moreIcon }
(Button.tertiary :: Dropdown.toggle rowMenu)Close the dropdown, or leave it closed. On a menu item, it closes the menu when the item is chosen:
Dropdown.button (Events.onClick Archive :: Dropdown.hide caseActions)
[ Html.text "Arkiver" ]Whether the dropdown is open, from your model (React's open prop). Like
Popover.open, it needs the companion script
and an onToggle that updates your state when the user closes it.
Sent when the dropdown opens or closes, by the trigger, Esc, an outside
click or code. See
Popover.onToggle.
Whether a dropdown is showing.
The
idthat links a dropdown to the buttons that open it.