PillMenu
Dropdown menu for making selection with pills showing the selected items.
#
Documentation
#
"use client";
import { type MenuOption } from "@optiaxiom/react";
import {
PillMenu,
PillMenuContent,
PillMenuTrigger,
} from "@optiaxiom/react/unstable";
import { useMemo, useState } from "react";
const colors = ["Ocean", "Blue", "Purple", "Red", "Orange", "Yellow"];
export function App() {
const [value, setValue] = useState(
colors.filter((_, index) => index % 3 === 0),
);
return (
<PillMenu
options={useMemo(
() =>
colors.map(
(color) =>
({
execute: () =>
setValue((values) =>
values.includes(color)
? values.filter((v) => v !== color)
: [...values, color],
),
label: color,
multi: true,
selected: () => value.includes(color),
}) satisfies MenuOption,
),
[value],
)}
>
<PillMenuTrigger>Add color</PillMenuTrigger>
<PillMenuContent />
</PillMenu>
);
}#
Props
#
#
PillMenu
#
Supports all Box props in addition to its own. Renders a <div> element.
Prop |
|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
defaultOpenThe initial open state in uncontrolled mode.
Default: |
emptyCustom empty state content.
|
inputValueThe input value in controlled mode.
|
inputVisibleWhether to always show the input or only if there are selectable options and/or when user starts to type.
|
loadingWhether to show loading spinner or skeleton items inside the menu.
|
onInputValueChangeHandler that is called when input value changes.
|
onOpenChangeHandler that is called when the open state changes.
|
openThe open state in controlled mode.
|
options*The items we want to render.
|
placeholderThe placeholder for the search input.
|
#
PillMenuTrigger
#
Supports all Box props in addition to its own. Renders a <div> element.
Prop |
|---|
addonAfterDisplay content inside the button after
|
addonBeforeDisplay content inside the button before
|
appearanceControl the appearance by selecting between the different button types.
|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
disabledWhether the button is disabled.
|
iconDisplay an icon before or after the button content or omit
|
iconPositionControl whether to show the icon before or after the button content.
|
loadingWhether to show loading spinner inside the button.
|
sizeControl the size of the button.
|
squareWhether button should have square shape.
|
#
PillMenuContent
#
Supports all Box props in addition to its own. Renders a <div> element.
Prop |
|---|
align
|
alignOffset
|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
minWWhether to set the min-width to the width of the trigger.
|
onCloseAutoFocusEvent handler called when auto-focusing on close. Can be prevented.
|
onEscapeKeyDownEvent handler called when the escape key is down. Can be prevented.
|
onFocusOutsideEvent handler called when the focus moves outside of the
|
onInteractOutsideEvent handler called when an interaction happens outside the
|
onOpenAutoFocusEvent handler called when auto-focusing on open. Can be prevented.
|
onPointerDownOutsideEvent handler called when the a
|
side
|
sideOffset
|
#
Changelog
#
#
1.6.2
#
- Added component