Skip to content

Commit eaa5891

Browse files
committed
docs: explain RichEditor custom view wrappers
1 parent e220b31 commit eaa5891

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ RichEditor::make('content')
1717

1818
<AutoScreenshot name="forms/fields/rich-editor/simple" alt="Rich editor" version="5.x" />
1919

20+
## Wrapping the editor in a custom Blade view
21+
22+
The RichEditor uses an embedded default renderer. Do not include the internal `filament-forms::components.rich-editor` view from your own Blade view, as it is not part of the extension API and may change between versions.
23+
24+
If you need to add an outer wrapper, create a custom RichEditor class with your own view:
25+
26+
```php
27+
use Filament\Forms\Components\RichEditor;
28+
29+
class CustomRichEditor extends RichEditor
30+
{
31+
protected string $view = 'components.custom-rich-editor';
32+
}
33+
```
34+
35+
Then, render the component's embedded markup from that view:
36+
37+
```blade
38+
<div class="my-class">
39+
{!! $field->toEmbeddedHtml() !!}
40+
</div>
41+
```
42+
43+
The `$field` variable is available automatically in a custom field view. This delegates the editor markup back to Filament, so your wrapper remains independent of the internal implementation. For styling-only changes, prefer the documented CSS hook classes instead.
44+
2045
## Storing content as JSON
2146

2247
By default, the rich editor stores content as HTML. If you would like to store the content as JSON instead, you can use the `json()` method:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="custom-rich-editor">
2+
{!! $field->toEmbeddedHtml() !!}
3+
</div>

tests/src/Forms/Components/RichEditorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@
2929
Artisan::call('filament:assets');
3030
});
3131

32+
test('can render its embedded markup inside a custom view', function (): void {
33+
$richEditor = Schema::make(Livewire::make())
34+
->statePath('data')
35+
->components([
36+
CustomViewRichEditor::make('content'),
37+
])
38+
->getComponents()[0];
39+
40+
$html = $richEditor->toHtml();
41+
42+
expect($html)
43+
->toContain('custom-rich-editor')
44+
->toContain('fi-fo-rich-editor');
45+
});
46+
3247
test('fields can be required', function (): void {
3348
$errors = [];
3449

@@ -2201,3 +2216,8 @@ public function save(): void
22012216
$this->record->update($this->form->getState());
22022217
}
22032218
}
2219+
2220+
class CustomViewRichEditor extends RichEditor
2221+
{
2222+
protected string $view = 'components.custom-rich-editor';
2223+
}

0 commit comments

Comments
 (0)