Select
Select components.
Select Native, Personalization Blocks
Example:
TallStackUi::personalize() ->select() ->block('block', 'classes');
Select Styled, Personalization Blocks
Example:
TallStackUi::personalize() ->select('styled') ->block('block', 'classes');
An option to use multi-dimensional array.
When the value and label do not come from the label
and value
positions respectively, you must specify this manually using the select
attribute:
<x-select.native :options="[ ['name' => 'TALL', 'id' => 1], ['name' => 'LIVT', 'id' => 2],]" select="label:name|value:id" />
This option is also available for the other select components below.
Customized styled select component to interact with Livewire.
An option to make the select component required.
The user will not be able to deselect the selected option after selecting an option.
An option to use multi-dimensional array.
When the value and label do not come from the label
and value
positions respectively, you must specify this manually using the select
attribute:
<x-select.styled :options="[ ['name' => 'TALL', 'id' => 1], ['name' => 'LIVT', 'id' => 2],]" select="label:name|value:id" />
An option to disable specific options.
An option to limit the number of selections.
The styled select allows you to display an image next to the option label. To do this,
the options simply have an index called image
with the image URL.
You can also set a different index to the image
via the select
attribute.
<x-select.styled :options="[ ['label' => 'Taylor Otwell', 'value' => 1, 'preview' => 'https://unavatar.io/github/taylorotwell'], ['label' => 'Nuno Maduro', 'value' => 2, 'preview' => 'https://unavatar.io/github/nunomaduro'], ['label' => 'Jess Archer', 'value' => 3, 'preview' => 'https://unavatar.io/github/jessarcher'],]" select="label:label|value:value|image:preview" />
You can also set a description for each option. To do this, the options simply have an index called description
.
You can also set a different index to the description
via the select
attribute:
<x-select.styled :options="[ ['label' => 'Taylor Otwell', 'value' => 1, 'note' => 'Taylor Otwell is the creator of Laravel'], ['label' => 'Nuno Maduro', 'value' => 2, 'note' => 'Nuno Maduro is the creator of PestPHP'], ['label' => 'Jess Archer', 'value' => 3, 'note' => 'Jess Archer is the creator of Laravel Prompts'],]" select="label:label|value:value|description:note" />
Lazy loading is a way to slowly load options as you scroll down the floating element that displays the available options. While this is extremely useful for delaying the loading of large amounts of options, there is two major caveat:
- The
searchable
attribute will not work to search for options that have not yet been loaded. - The
lazy
attribute expects to receive values greater than or equal to 10.
An option to interact with the search term when nothing is found.
The styled select component allows you to query for values via an API. In this mode, all the options available above
remain available for use, the difference is that instead of setting the options using the options
parameter, you must
specify the API URL where the results will come from. For identification purposes, a header called X-Tallstack-Ui
will be added to all requests.
When the value and label do not come from the label
and value
positions respectively, you must specify this manually using the select
attribute,
like mentioned in the multi-dimensional array section. This example do not set the select
attribute
because the API returns the values in the correct format.
The styled select component filters the API results using internal logic to search for the desired option based on the term entered in the input only in the item's
label
or description
. You can disable this behavior to make the filters apply only in the API. In other words, you need to
ensure that, for example, the value search applies a where
based on the term sent in the search and appended to the query string search
.
This is only available in the styled API select.
In this example, the query was builded as follows:
use App\Models\User;use Illuminate\Http\Request;use Illuminate\Support\Facades\Route;use Illuminate\Database\Eloquent\Builder; Route::get('/users', function (Request $request) { $search = $request->get('search'); return User::query() ->when($search, fn (Builder $query) => $query->where('name', 'like', "%{$search}%")) ->unless($search, fn (Builder $query) => $query->limit(10)) ->get() ->map(fn (User $user): array => [ 'label' => $user->name, 'value' => $user->id, ]);})->name('api.users');
Which means:
- When
search
is set, then the query will be filtered by thename
column. - When
search
is not set, then the query will return only 10 results.
Optionally, you can set the unfiltered
globally by the TallStackUI configuration file.
You have the possibility to customize some things related to the request, such as the method used: get
or post
, and also add more params
to the request.
One of the big advantages of using these advanced options is the params
parameter, because it is hydrated. This means that if you are using this component within the Livewire components and create a variable
to be used in params , when making any changes to this variable and Livewire hydrates the page, the next time the select is opened to make a new request, params will be updated in the request.