Created
September 29, 2022 12:10
-
-
Save humayunjavaid/43e90d9dd3524f3ec349212b3352e187 to your computer and use it in GitHub Desktop.
Trix Integration with Livewire And Alpine js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Component Render */ | |
<x-rich-text wire:model.lazy="description"></x-rich-text> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Blade Component */ | |
<div | |
x-data="{ | |
value: @entangle($attributes->wire('model')), | |
isFocused() { return document.activeElement !== this.$refs.trix }, | |
setValue() { this.$refs.trix.editor.loadHTML(this.value) }, | |
}" | |
x-init="setValue(); $watch('value', () => isFocused() && setValue())" | |
x-on:trix-change="value = $event.target.value" | |
{{ $attributes->whereDoesntStartWith('wire:model') }} | |
wire:ignore | |
> | |
<input id="x" type="hidden"> | |
<trix-editor x-ref="trix" input="x" class="form-textarea"></trix-editor> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment