Skip to content

Commit ef15e33

Browse files
committed
Applied changes of filamentphp#17483
1 parent bd50530 commit ef15e33

File tree

9 files changed

+985
-25
lines changed

9 files changed

+985
-25
lines changed

packages/forms/dist/components/rich-editor.js

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/forms/docs/10-rich-editor.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,68 @@ RichEditor::make('content')
617617
->activePanel('mergeTags')
618618
```
619619

620+
## Using mentions
621+
622+
Mentions let users type a trigger character (like `@`) to search and insert inline references (e.g., users, tasks). Mentions are rendered inline as non-editable tokens (e.g. `@ Jane Doe`).
623+
624+
Configure mentions with providers using `mentions()`. Each provider handles a trigger `char` and either static items or async search:
625+
626+
```php
627+
use Filament\Forms\Components\RichEditor;
628+
use Filament\Forms\Components\RichEditor\MentionProviders\MentionProvider;
629+
630+
// Static items for multiple triggers
631+
RichEditor::make('content')
632+
->mentions([
633+
MentionProvider::make('@')
634+
->options([
635+
['id' => 1, 'label' => 'Jane Doe'],
636+
['id' => 2, 'label' => 'John Smith'],
637+
]),
638+
MentionProvider::make('#')
639+
->options(['Laravel', 'Filament', 'Livewire']),
640+
])
641+
```
642+
643+
For large datasets, provide async results with `getSearchResultsUsing()`. The callback receives the search term and should return an array of items (strings, or objects with `id` and `label`).
644+
645+
```php
646+
use Filament\Forms\Components\RichEditor;
647+
use Filament\Forms\Components\RichEditor\MentionProviders\MentionProvider;
648+
649+
RichEditor::make('content')
650+
->mentions([
651+
MentionProvider::make('@')
652+
->getSearchResultsUsing(fn (string $search): array => User::query()
653+
->where('name', 'like', "%{$search}%")
654+
->orderBy('name')
655+
->limit(10)
656+
->pluck('name', 'id')
657+
->all())
658+
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name),
659+
])
660+
```
661+
662+
663+
### Adding extra HTML attributes
664+
665+
You may apply extra HTML attributes to the rendered mention element:
666+
667+
```php
668+
MentionProvider::make('@')
669+
->options([
670+
['id' => 1, 'label' => 'Jane Doe'],
671+
])
672+
->extraAttributes([
673+
'type' => 'user',
674+
'class' => 'mention-user text-blue-600',
675+
])
676+
```
677+
678+
### Notes
679+
680+
- You can provide multiple providers, each with a different `char` (default `@`).
681+
620682
## Registering rich content attributes
621683

622684
There are elements of the rich editor configuration that apply to both the editor and the renderer. For example, if you are using [private images](#using-private-images-in-the-editor), [custom blocks](#using-custom-blocks), [merge tags](#using-merge-tags), or [plugins](#extending-the-rich-editor), you need to ensure that the same configuration is used in both places. To do this, Filament provides you with a way to register rich content attributes that can be used in both the editor and the renderer.

packages/forms/resources/js/components/rich-editor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export default function richEditorFormComponent({
1919
maxFileSize,
2020
maxFileSizeValidationMessage,
2121
mergeTags,
22+
mentions,
23+
getMentionSearchResultsUsing,
24+
getMentionLabelUsing,
2225
noMergeTagSearchResultsMessage,
2326
placeholder,
2427
state,
@@ -75,6 +78,9 @@ export default function richEditorFormComponent({
7578
maxFileSize,
7679
maxFileSizeValidationMessage,
7780
mergeTags,
81+
mentions,
82+
getMentionSearchResultsUsing,
83+
getMentionLabelUsing,
7884
noMergeTagSearchResultsMessage,
7985
placeholder,
8086
statePath,

0 commit comments

Comments
 (0)