This component is meant to display a menu of options to the user, activated by clicking
any element. It can also be controlled from the parent, by binding the menushown
boolean.
buttonelement: HTMLElement
(required) - The DOM element that will act as the "button" for this menu. The menu will be placed next to the button and be controlled by the button. Keyboard access will be enabled when the button has focus. This component adds all appropriate attributes (tabindex, roles, and aria) automatically.items: PopupMenuItem[]
(required) - The list of menu items to be shown. Parent may change this at any time based on user activity.menushown?: boolean
(defaultfalse
) - Bind this prop to track/change the visible state of the menu from the parent.value?: string
(default no selection) - Bind this prop to track/change the currently selected value from the parent.align?: GlueAlignOpts
(defaultauto
) - Control where the menu will appear. Default is to use the current viewport to make a decision to maximize potential for menu growth.cover?: boolean
(defaultfalse
) - When the menu is active, should it cover the button or be rendered above/below it?showSelected?: boolean
(defaulttrue
) - When an item is currently selected, should it appear in the menu (with a visual indicator), or simply be removed from the list (showSelected:false
)?width?: string
(defaultundefined
) - When defined, this width will be passed through to the menu's CSS width. Use a valid CSS dimension such as33em
or159px
. Generally this will be used when you need to match the menu width to something else, like the button. If the width is static like100%
a simple CSS rule is likely more efficient.computedalign: readable<{ valign: 'top'|'bottom', halign: 'left'|'right' }>
(default store is provided) - Bind this prop to receive a store that is updated each time a menu placement decision is made. Example of when this is useful is when you are trying to round corners of your button and need to know whether the menu is above or below your button so you know which corners to round and which to leave square. Note that the values do not update when the menu is hidden, so you may need to rely onmenushown
as well.adjustparentheight?: boolean
(defaultfalse
) - Set totrue
if you want the parent element's styling to increase its minHeight when necessary. Useful for parent elements not styled for variable size children and which you want override the the size of.usePortal?: HTMLElement|true
(defaultfalse
) - If the menu would be clipped by anoverflow: hidden
, you can set this prop and it will be placed in the specified container, or thedocument.body
if you simply saytrue
. Placement will still be calculated correctly, unless there are scrolling containers between the button and the menu.loading?: boolean
(defaultfalse
) - Useful for when youritems
need to be fetched but you want the associated element shown. Set to loading until they're ready to be displayed and the popup menu will not be shown until theloading
bind istrue
.hilited?: number|undefined
(defaultundefined
) - A bindable value for inspecting which item initems
is currently highlighted as the item currently active in the list. This is not the same asvalue
and the highlighted item may or may not be selected as for thevalue
of the field.menuid?: string
(defaultrandomid()
) - The id of the<ul>
element that is the displayed list ofitems
.emptyText?: string
(default¯\_(ツ)_/¯
) - When there are no items (e.g. it's a filtered search and there were no results), we still display one disabled item in the menu to let the user know what is going on. Use this prop to specify the message.menuContainerClass?: string
(default''
) - CSS class to pass through so you can do extra styling workmenuClass?: string
(default''
) - CSS class to pass through so you can do extra styling workmenuItemClass?: string
(default''
) - CSS class to pass through so you can do extra styling workmenuItemHilitedClass?: string
(default''
) - CSS class to pass through so you can do extra styling workmenuItemSelectedClass?: string
(default''
) - CSS class to pass through so you can do extra styling work
on:change
- Dispatched any time a new value is selected. Does not fire when you change thevalue
property from the outside. Event detail will be the full PopupMenuItem object that was selected.
PopupMenuItem: { value: string, label?: string, disabled?: boolean }
- Each item must have a unique non-empty value. Display label is optional, as is adisabled
status that will show the item in the list but not allow users to hilite or select it.
Since there are so many different possibilities for the button you attach to, the PopupMenu does not have a disabled
prop. If the PopupMenu should be disabled, simply remove it from the DOM with an {#if}
block. Remember to also set aria-disabled
on your button and likely provide some visual indicators like cursor: default
or the disabled
attribute on elements that support it.