mantine-combobox
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMantine Combobox Skill
Mantine Combobox 技能
Overview
概述
ComboboxSelectAutocompleteTagsInputComboboxSelectAutocompleteTagsInputCore Workflow
核心工作流
1. Create the store
1. 创建store
tsx
const combobox = useCombobox({
onDropdownClose: () => combobox.resetSelectedOption(),
onDropdownOpen: () => combobox.selectFirstOption(),
});tsx
const combobox = useCombobox({
onDropdownClose: () => combobox.resetSelectedOption(),
onDropdownOpen: () => combobox.selectFirstOption(),
});2. Render structure
2. 渲染结构
tsx
<Combobox store={combobox} onOptionSubmit={handleSubmit}>
<Combobox.Target>
<InputBase
component="button"
pointer
rightSection={<Combobox.Chevron />}
onClick={() => combobox.toggleDropdown()}
>
{value || <Input.Placeholder>Pick value</Input.Placeholder>}
</InputBase>
</Combobox.Target>
<Combobox.Dropdown>
<Combobox.Options>
{options.map((item) => (
<Combobox.Option value={item} key={item}>{item}</Combobox.Option>
))}
</Combobox.Options>
</Combobox.Dropdown>
</Combobox>tsx
<Combobox store={combobox} onOptionSubmit={handleSubmit}>
<Combobox.Target>
<InputBase
component="button"
pointer
rightSection={<Combobox.Chevron />}
onClick={() => combobox.toggleDropdown()}
>
{value || <Input.Placeholder>Pick value</Input.Placeholder>}
</InputBase>
</Combobox.Target>
<Combobox.Dropdown>
<Combobox.Options>
{options.map((item) => (
<Combobox.Option value={item} key={item}>{item}</Combobox.Option>
))}
</Combobox.Options>
</Combobox.Dropdown>
</Combobox>3. Handle submit
3. 处理提交
tsx
const handleSubmit = (val: string) => {
setValue(val);
combobox.closeDropdown();
};tsx
const handleSubmit = (val: string) => {
setValue(val);
combobox.closeDropdown();
};Target Types
目标类型
| Scenario | Use |
|---|---|
| Button trigger (no text input) | |
| Input trigger | |
| Pills + separate input (multi-select) | |
| 场景 | 使用方式 |
|---|---|
| 按钮触发(无文本输入) | |
| 输入框触发 | |
| 胶囊标签 + 独立输入框(多选) | |
References
参考资料
- — Full API:
references/api.mdoptions and store, all sub-component props, CSS variables, Styles API selectorsuseCombobox - — Code examples: searchable select, multi-select with pills, groups, custom rendering, clear button, form integration
references/patterns.md
- — 完整API:
references/api.md选项和store、所有子组件属性、CSS变量、Styles API选择器useCombobox - — 代码示例:可搜索选择器、带胶囊标签的多选组件、分组、自定义渲染、清除按钮、表单集成
references/patterns.md