Skip to main content

rc-fab-menu

Floating action button menu wrapper for an rc-menu action surface.

Use this when a primary floating action needs a short menu of related commands. The component specializes rc-menu-button, so it keeps menu keyboard behavior, light dismiss, focus return, and anchor positioning while adding FAB placement and reveal styling.

Package
@rcarls/rc-fab-menu
Element
<rc-fab-menu>
Native dependency
Consumer-supplied trigger button plus rc-menu
State model
Controlled or uncontrolled open state inherited from rc-menu-button
Main events
rc-fab-menu-togglerc-menu-activate

Installation

npm install @rcarls/rc-fab-menu
import '@rcarls/rc-fab-menu/define';

Usage

Place a native trigger button in the trigger slot and an rc-menu in the default slot. Listen for rc-menu-activate on the menu or wrapper to handle the chosen action.

<rc-fab-menu>
<button slot="trigger" type="button" aria-label="Create">
<span aria-hidden="true">+</span>
</button>

<rc-menu label="Create">
<button data-value="recipe">Recipe</button>
<button data-value="collection">Collection</button>
</rc-menu>
</rc-fab-menu>

The trigger receives aria-haspopup="menu" and aria-expanded from the inherited menu-button behavior. The popup opens above the trigger by default with placement="top-end".

Without a theme, the trigger remains a native-looking button. Apply a packaged theme to opt into FAB dimensions, shape, elevation, typography, and motion.

Live demo

Material sizing

Material FAB sizes are theme concerns rather than component API values. With rc-theme-material, use modifier classes on the host:

<rc-fab-menu class="rc-fab--large">
<button slot="trigger" type="button" aria-label="Create">+</button>
<rc-menu label="Create">...</rc-menu>
</rc-fab-menu>

The same rc-fab--small and rc-fab--large classes work on rc-fab.

API

rc-fab-menu inherits open, defaultOpen, placement, openMenu(), closeMenu(), and toggleMenu() from rc-menu-button.

Properties

PropertyMarkupTypeDefaultDescription
positionpositionRCFabMenuPosition'bottom-end'Viewport corner where the floating action menu trigger is anchored.
placementplacementAnchorPlacement'top-end'Preferred placement of the action menu relative to the trigger button.
openopenbooleanNot specifiedApplies open state in controlled mode without dispatching an event.
defaultOpendefault-openbooleanNot specifiedApplies the uncontrolled default before any controlled write occurs.
orientationorientation'horizontal' | 'vertical' | undefinedNot specifiedOrientation of this menu button, affects which arrow keys open/close the menu. If not set, inherits from a parent rc-menubar or element with role="menubar".

Methods

MethodDescription
openMenu(focusTarget: 'first' | 'last')Opens the menu and moves focus into it.
closeMenu(returnFocus: unknown)Closes the menu.
toggleMenu()Toggles the menu between open and closed.
focus(options?: FocusOptions)Overrides the default focus() so that programmatic focus calls (e.g. from a roving-tabindex parent navigating back to this element via arrow keys) always reach the trigger. Chrome's delegatesFocus will not delegate to a tabindex="-1" element, so when the toolbar marks this host inactive it suppresses the trigger — and the next focusItem() call silently fails. Lifting the suppression here and directly calling trigger.focus() bypasses that restriction.

Events

EventDetail typeDescription
rc-fab-menu-toggleCustomEventFired when user interaction opens or closes the action menu.
rc-menu-button-toggleCustomEventFired when the menu opens or closes

Slots

NameDescription
triggerNative button or button-like element that opens the action menu.
default`rc-menu` element containing floating action commands.
indicatorOptional decorative indicator rendered at the trigger's inline end

CSS Custom Properties

PropertyDefaultDescription
--rc-fab-menu-position-cssfixedCSS position value for the floating wrapper.
--rc-fab-menu-inset-block1.5remDistance from the block-axis edge; falls back through --rc-fab-inset-block.
--rc-fab-menu-inset-inline1.5remDistance from the inline-axis edge; falls back through --rc-fab-inset-inline.
--rc-fab-menu-z-index10Stacking order for the floating wrapper; falls back through --rc-fab-z-index.
--rc-fab-menu-trigger-gapNot specifiedGap between trigger icon and label content. No default.
--rc-fab-menu-sizeNot specifiedTrigger minimum inline and block size. No default; set explicitly or apply a theme.
--rc-fab-menu-padding-blockNot specifiedTrigger block-axis padding (defers to native button padding when unset).
--rc-fab-menu-padding-inlineNot specifiedTrigger inline-axis padding (defers to native button padding when unset).
--rc-fab-menu-appearanceNot specifiedTrigger appearance (defers to native button appearance when unset).
--rc-fab-menu-borderNot specifiedTrigger border (defers to native button border when unset).
--rc-fab-menu-radiusNot specifiedTrigger border radius (defers to native button radius when unset).
--rc-fab-menu-bgNot specifiedTrigger background (defers to native button background when unset).
--rc-fab-menu-colorNot specifiedTrigger foreground color (defers to native button color when unset).
--rc-fab-menu-shadowNot specifiedTrigger elevation shadow (defers to native button shadow when unset).
--rc-fab-menu-fontNot specifiedTrigger font shorthand (defers to native button font when unset).
--rc-fab-menu-font-familyNot specifiedTrigger font family (defers to native button font-family when unset).
--rc-fab-menu-font-sizeNot specifiedTrigger font size (defers to native button font-size when unset).
--rc-fab-menu-font-weightNot specifiedTrigger font weight (defers to native button font-weight when unset).
--rc-fab-menu-letter-spacingNot specifiedTrigger letter spacing (defers to native button letter-spacing when unset).
--rc-fab-menu-text-decorationNot specifiedTrigger text decoration (defers to native button text-decoration when unset).
--rc-fab-menu-user-selectNot specifiedTrigger user-select (defers to native button user-select when unset).
--rc-fab-menu-transitionNot specifiedTrigger transition shorthand (defers to native button transition when unset).
--rc-fab-menu-bg-hoverNot specifiedTrigger hover background (defers to native button hover styling when unset).
--rc-fab-menu-shadow-hoverNot specifiedTrigger hover elevation shadow (defers to native button hover styling when unset).
--rc-fab-menu-bg-openNot specifiedTrigger background while the menu is open (defers to native button styling when unset).
--rc-fab-menu-shadow-openNot specifiedTrigger elevation shadow while the menu is open (defers to native button styling when unset).
--rc-fab-menu-shadow-activeNot specifiedTrigger pressed elevation shadow (defers to native button styling when unset).
--rc-fab-menu-active-transformNot specifiedTrigger transform while pressed (defers to native button styling when unset).
--rc-fab-menu-focus-ringNot specifiedTrigger focus ring (defers to native button focus styling when unset).
--rc-fab-menu-focus-ring-offsetNot specifiedTrigger focus ring offset (defers to native button focus styling when unset).
--rc-fab-menu-disabled-opacityNot specifiedTrigger opacity while disabled (defers to native disabled styling when unset).
--rc-fab-menu-disabled-shadowNot specifiedTrigger elevation shadow while disabled (defers to native disabled styling when unset).
--rc-fab-menu-popup-z-index1000Stacking order of the popup container; falls back through --rc-menu-button-popup-z-index.
--rc-fab-menu-popup-duration0msPopup reveal transition duration.
--rc-fab-menu-popup-transform-originbottom rightPopup reveal transform origin.
--rc-menu-button-trigger-block-sizevar(--rc-control-block-size)Minimum block size of the trigger
--rc-menu-button-trigger-padding-blockvar(--rc-control-padding-block)Trigger block-axis padding
--rc-menu-button-trigger-padding-inlinevar(--rc-control-padding-inline)Trigger inline-axis padding
--rc-menu-button-trigger-gapvar(--rc-item-gap)Gap between flex children in the trigger
--rc-menu-button-trigger-bordervar(--rc-border)Trigger border
--rc-menu-button-trigger-radiusvar(--rc-control-radius)Trigger border radius
--rc-menu-button-trigger-backgroundvar(--rc-button-bg)Trigger background
--rc-menu-button-trigger-colorvar(--rc-button-text)Trigger text color
--rc-menu-button-trigger-transitionNot specifiedCSS transition applied to the trigger
--rc-menu-button-trigger-hover-backgroundcolor-mix(in srgb, Highlight 8%, transparent)Trigger hover background
--rc-menu-button-trigger-hover-colorinheritTrigger hover text color
--rc-menu-button-trigger-hover-border-colorcurrentColorTrigger hover border color
--rc-menu-button-trigger-open-backgroundcolor-mix(in srgb, Highlight 12%, transparent)Trigger background when the menu is open
--rc-menu-button-trigger-open-colorinheritTrigger text color when the menu is open
--rc-menu-button-trigger-open-border-colorcurrentColorTrigger border color when the menu is open
--rc-menu-button-indicator-size1emInline and block size of the slotted indicator
--rc-menu-button-indicator-colorcurrentColorColor of the slotted indicator
--rc-menu-button-indicator-insetvar(--rc-menu-button-trigger-padding-inline)Indicator distance from the trigger's inline end
--rc-menu-button-popup-z-index1000Z-index of the popup overlay

CSS Parts

PartDescription
rootThe root popup anchor inherited from `rc-menu-button`.
popupThe popup container inherited from `rc-menu-button`.