Skip to content

Instantly share code, notes, and snippets.

@humayunjavaid
Created September 29, 2022 12:10
Show Gist options
  • Save humayunjavaid/43e90d9dd3524f3ec349212b3352e187 to your computer and use it in GitHub Desktop.
Save humayunjavaid/43e90d9dd3524f3ec349212b3352e187 to your computer and use it in GitHub Desktop.
Trix Integration with Livewire And Alpine js
/* Component Render */
<x-rich-text wire:model.lazy="description"></x-rich-text>
/* 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