coringawc/filament-input-loading
Installation
Run composer require coringaawc/filament-input-loading in your Laravel project. No additional configuration is required—auto-discovery handles registration.
First Use Case
Replace your existing TextInput import in a Filament form with:
use CoringaWc\FilamentInputLoading\TextInput;
Then use lazy() or debounce() on the input as usual:
TextInput::make('search')
->debounce(500)
->live(onBlur: true),
The loading spinner will now appear inside the input during server processing.
Where to Look First
src/TextInput.php for customization options (e.g., spinner color, size).lazy()/debounce() behavior.Basic Integration
Replace Filament\Forms\Components\TextInput with CoringaWc\FilamentInputLoading\TextInput in your form builder. No other changes are needed for core functionality.
Conditional Loading
Use live() modifiers to control when the spinner appears:
TextInput::make('query')
->debounce(300)
->live(onBlur: true, unlessBlank: true),
unlessBlank: Spinner only shows if the input has content.onBlur: Spinner triggers on field blur (useful for search-as-you-type).Customizing the Spinner
Override the default spinner via the getSpinnerView() method in your form:
TextInput::make('custom')
->debounce(500)
->extraAttributes(['data-spinner-color' => 'red']);
Extend the TextInput class to modify the spinner template (see Gotchas).
Integration with Other Filament Components
Combine with Select, MultiSelect, or Toggle by extending their classes similarly (though this package only modifies TextInput by default).
Dynamic Forms
For dynamic forms (e.g., FormBuilder), ensure the custom TextInput is registered in your form’s getComponents() method:
public static function getComponents(): array {
return [
TextInput::make('dynamic_field')->debounce(500),
];
}
Search Functionality
Use debounce(300) for search inputs to reduce server load while providing real-time feedback.
TextInput::make('search_term')
->debounce(300)
->live(onChange: true),
Form Validation Feedback
Pair with live(onBlur: true) to show validation errors and loading spinners during async validation:
TextInput::make('email')
->debounce(500)
->rules(['email'])
->live(onBlur: true),
API-Driven Forms
For API-heavy forms, use lazy() to trigger updates only when the input loses focus:
TextInput::make('api_key')
->lazy()
->live(onBlur: true),
Livewire Hooks
If you need to customize spinner behavior, hook into Livewire’s updated events:
protected function updated($property) {
if (str_contains($property, 'search_')) {
// Custom logic for search fields
}
}
Tailwind CSS
The spinner uses Tailwind classes (animate-spin). Customize via your tailwind.config.js:
module.exports = {
theme: {
extend: {
colors: {
spinner: '#ef4444', // Example: Red spinner
},
},
},
};
Testing
Test loading states with Livewire’s call() method:
$this->call('search', ['query' => 'test']);
$this->assertSee('animate-spin'); // Verify spinner appears
Filament Version Mismatch
Class 'Filament\Forms\Components\TextInput' not found.composer.json:
"require": {
"filament/filament": "^2.0"
}
Spinner Not Appearing
live() modifier or incorrect debounce()/lazy() usage.wire:model.lazy or wire:model.debounce attribute in the rendered HTML.CSS Conflicts
z-index in your CSS:
.filament-input-loading__spinner {
z-index: 10;
}
Performance Overhead
debounce values (e.g., 100ms) may cause UI jank.debounce(300) or higher for search inputs to balance responsiveness and server load.Inspect Rendered HTML Check if the spinner’s SVG/HTML is present in the input:
<div class="filament-input-loading__spinner">
<svg class="animate-spin" ...></svg>
</div>
If missing, the TextInput replacement wasn’t applied correctly.
Livewire Logs
Enable Livewire logging to debug live() updates:
Livewire::configureLogging();
Check storage/logs/livewire.log for update events.
Blade Template Overrides
If you’ve customized Filament’s text-input.blade.php, ensure the spinner’s container (filament-input-loading__spinner) isn’t removed.
Extending the Spinner Override the spinner’s view by publishing the package’s assets:
php artisan vendor:publish --tag=filament-input-loading-views
Then modify resources/views/vendor/filament-input-loading/spinner.blade.php.
Accessibility
Add aria-busy to the input for screen readers:
TextInput::make('search')
->debounce(500)
->extraAttributes(['aria-busy' => 'false'])
->live(onChange: true),
Update aria-busy dynamically in your Livewire component:
public function updatedSearch($value) {
$this->dispatch('set-aria-busy', busy: true);
// ... async logic
$this->dispatch('set-aria-busy', busy: false);
}
Dark Mode Support
Ensure the spinner’s color contrasts in dark mode. Use Tailwind’s dark: variant:
.filament-input-loading__spinner {
color: theme('colors.white');
}
.dark .filament-input-loading__spinner {
color: theme('colors.gray.300');
}
Localization The spinner has no text, but if you add a label (e.g., "Loading..."), translate it:
TextInput::make('query')
->debounce(500)
->placeholder(__('Loading...')),
Server-Side Logic
For long-running operations, combine with Livewire’s wire:loading state:
public function updatedSearch($query) {
$this->searching = true;
// Simulate delay
sleep(2);
$this->searching = false;
}
@if($this->searching)
<div class="spinner"></div>
@endif
Package Updates Monitor for breaking changes in Filament v2.x updates. Test after major Filament releases.
How can I help you explore Laravel packages today?