Components
Combobox
Combobox
Combine a text input field with a dropdown menu for enhanced user interaction.
Installation
npx @udecode/plate-ui@latest add combobox
Examples
@ Mention
Mention and reference other users or entities within your text using @-mentions.
Try mentioning
BB-8
or Boba Fett
.import React from 'react';
import { ComboboxItemProps } from '@udecode/plate-combobox';
import {
EmojiItemData,
KEY_EMOJI,
TEmojiCombobox,
useEmojiComboboxState,
} from '@udecode/plate-emoji';
import { Combobox } from './combobox';
export function EmojiComboboxItem({ item }: ComboboxItemProps<EmojiItemData>) {
const {
data: { id, emoji },
} = item;
return (
<div>
{emoji} :{id}:
</div>
);
}
export function EmojiCombobox({
pluginKey = KEY_EMOJI,
id = pluginKey,
...props
}: TEmojiCombobox) {
const { trigger, onSelectItem } = useEmojiComboboxState({ pluginKey });
return (
<Combobox
id={id}
trigger={trigger}
controlled
onSelectItem={onSelectItem as any}
onRenderItem={EmojiComboboxItem}
{...props}
/>
);
}
import React from 'react';
import { ComboboxProps } from '@udecode/plate-combobox';
import { getPluginOptions, useEditorRef } from '@udecode/plate-common';
import {
ELEMENT_MENTION,
getMentionOnSelectItem,
MentionPlugin,
} from '@udecode/plate-mention';
import { Combobox } from './combobox';
export function MentionCombobox({
pluginKey = ELEMENT_MENTION,
id = pluginKey,
...props
}: Partial<ComboboxProps> & {
pluginKey?: string;
}) {
const editor = useEditorRef();
const { trigger } = getPluginOptions<MentionPlugin>(editor, pluginKey);
return (
<Combobox
id={id}
trigger={trigger!}
controlled
onSelectItem={getMentionOnSelectItem({
key: pluginKey,
})}
{...props}
/>
);
}