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 |
---|
asChild Change the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
defaultOpen The initial open state in uncontrolled mode.
Default: |
empty Custom empty state content.
|
inputValue The input value in controlled mode.
|
inputVisible Whether to always show the input or only if there are selectable options and/or when user starts to type.
|
loading Whether to show loading spinner or skeleton items inside the menu.
|
onInputValueChange Handler that is called when input value changes.
|
onOpenChange Handler that is called when the open state changes.
|
open The open state in controlled mode.
|
options* The items we want to render.
|
placeholder The placeholder for the search input.
|
#
PillMenuTrigger
#
Supports all Box props in addition to its own. Renders a <div>
element.
Prop |
---|
addonAfter Display content inside the button after
|
addonBefore Display content inside the button before
|
appearance Control the appearance by selecting between the different button types.
|
asChild Change the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
disabled Whether the button is disabled.
|
icon Display an icon before or after the button content or omit
|
iconPosition Control whether to show the icon before or after the button content.
|
loading Whether to show loading spinner inside the button.
|
size Control the size of the button.
|
square Whether button should have square shape.
|
#
PillMenuContent
#
Supports all Box props in addition to its own. Renders a <div>
element.
Prop |
---|
align
|
alignOffset
|
asChild Change the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
minW Whether to set the min-width to the width of the trigger.
|
onCloseAutoFocus Event handler called when auto-focusing on close. Can be prevented.
|
onEscapeKeyDown Event handler called when the escape key is down. Can be prevented.
|
onFocusOutside Event handler called when the focus moves outside of the
|
onInteractOutside Event handler called when an interaction happens outside the
|
onOpenAutoFocus Event handler called when auto-focusing on open. Can be prevented.
|
onPointerDownOutside Event handler called when the a
|
side
|
sideOffset
|
#
Changelog
#
#
1.6.2
#
- Added component