Skip to content

Commit

Permalink
Added scripts and blade tag
Browse files Browse the repository at this point in the history
  • Loading branch information
asantibanez committed Jun 3, 2020
1 parent 2b68e8d commit 04d1929
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/LivewireSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function selectValue($value)
$this->value = $value;

if ($this->searchable && $this->value == null) {
$this->emit("focus-search", ['name' => $this->name]);
$this->emit('livewire-select-focus-search', ['name' => $this->name]);
}

$this->notifyValueChanged();
Expand Down
46 changes: 16 additions & 30 deletions src/LivewireSelectServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,12 @@ class LivewireSelectServiceProvider extends ServiceProvider
*/
public function boot()
{
/*
* Optional methods to load your package assets
*/
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'livewire-select');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-select');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-select');

if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('livewire-select.php'),
], 'config');

// Publishing the views.
/*$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/livewire-select'),
], 'views');*/

// Publishing assets.
/*$this->publishes([
__DIR__.'/../resources/assets' => public_path('vendor/livewire-select'),
], 'assets');*/

// Publishing the translation files.
/*$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/livewire-select'),
], 'lang');*/

// Registering package commands.
// $this->commands([]);
], 'livewire-select-views');
}
}

Expand All @@ -50,12 +26,22 @@ public function boot()
*/
public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'livewire-select');

// Register the main class to use with the facade
$this->app->singleton('livewire-select', function () {
return new LivewireSelect;
Blade::directive('livewireSelectScripts', function () {
return <<<'HTML'
<script>
window.livewire.on('livewire-select-focus-search', (data) => {
const el = document.getElementById(`${data.name || 'invalid'}`);
if (!el) {
return;
}
el.focus();
});
</script>
HTML;
});
}
}

0 comments on commit 04d1929

Please sign in to comment.