Skip to content

Commit 7861ae1

Browse files
authored
Merge pull request #1524 from KodeStar/remove_dropdown_on_single_provider
Remove search provider dropdown when there's only a single provider
2 parents 900fc83 + 66dfe95 commit 7861ae1

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

app/Search.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,31 @@ public static function form(): string
111111
if ((bool) $user_search_provider) {
112112
$name = 'app.options.'.$user_search_provider;
113113
$provider = self::providerDetails($user_search_provider);
114+
$providers = self::providers();
115+
$providerCount = count($providers);
116+
117+
// If there's only one provider, use its key instead of the user's setting
118+
if ($providerCount === 1) {
119+
$user_search_provider = $providers->keys()->first();
120+
}
114121

115122
$output .= '<div class="searchform">';
116123
$output .= '<form action="'.url('search').'"'.getLinkTargetAttribute().' method="get">';
117124
$output .= '<div id="search-container" class="input-container">';
118-
$output .= '<select name="provider">';
119-
foreach (self::providers() as $key => $searchprovider) {
120-
$selected = ((string) $key === (string) $user_search_provider) ? ' selected="selected"' : '';
121-
$output .= '<option value="'.$key.'"'.$selected.'>'.$searchprovider['name'].'</option>';
125+
126+
// Only show dropdown if there's more than one provider
127+
if ($providerCount > 1) {
128+
$output .= '<select name="provider">';
129+
foreach ($providers as $key => $searchprovider) {
130+
$selected = ((string) $key === (string) $user_search_provider) ? ' selected="selected"' : '';
131+
$output .= '<option value="'.$key.'"'.$selected.'>'.$searchprovider['name'].'</option>';
132+
}
133+
$output .= '</select>';
134+
} else {
135+
// Hidden input for single provider
136+
$output .= '<input type="hidden" name="provider" value="'.$user_search_provider.'" />';
122137
}
123-
$output .= '</select>';
138+
124139
$output .= '<input type="text" name="q" value="'.e(Input::get('q') ?? '').'" class="homesearch" autofocus placeholder="'.__('app.settings.search').'..." />';
125140
$output .= '<button type="submit">'.ucwords(__('app.settings.search')).'</button>';
126141
$output .= '</div>';

public/css/app.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,9 @@ a.settinglink {
11301130
position: relative;
11311131
z-index: 4;
11321132
}
1133+
.searchform:has(input[name=provider][type=hidden]) {
1134+
max-width: 520px;
1135+
}
11331136
.searchform form {
11341137
width: 100%;
11351138
}
@@ -1147,6 +1150,10 @@ a.settinglink {
11471150
width: 100%;
11481151
background: transparent;
11491152
}
1153+
.searchform input[name=q]:first-child {
1154+
border-top-left-radius: 5px;
1155+
border-bottom-left-radius: 5px;
1156+
}
11501157
.searchform button {
11511158
position: absolute;
11521159
right: 0px;
@@ -1170,6 +1177,10 @@ a.settinglink {
11701177
border-top-left-radius: 5px;
11711178
border-bottom-left-radius: 5px;
11721179
}
1180+
.searchform select ~ input[name=q] {
1181+
border-top-left-radius: 0;
1182+
border-bottom-left-radius: 0;
1183+
}
11731184

11741185
#search-autocomplete {
11751186
position: absolute;

public/js/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4166,7 +4166,8 @@ $.when($.ready).then(function () {
41664166
$("#search-container").on("input", "input[name=q]", function () {
41674167
var search = this.value;
41684168
var items = $("#sortable").find(".item-container");
4169-
var provider = $("#search-container select[name=provider]").val();
4169+
// Get provider from either select or hidden input
4170+
var provider = $("#search-container select[name=provider]").val() || $("#search-container input[name=provider]").val();
41704171
if (provider === "tiles") {
41714172
hideAutocomplete();
41724173
if (search.length > 0) {

public/mix-manifest.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ $.when($.ready).then(() => {
185185
.on("input", "input[name=q]", function () {
186186
const search = this.value;
187187
const items = $("#sortable").find(".item-container");
188-
const provider = $("#search-container select[name=provider]").val();
188+
// Get provider from either select or hidden input
189+
const provider =
190+
$("#search-container select[name=provider]").val() ||
191+
$("#search-container input[name=provider]").val();
189192

190193
if (provider === "tiles") {
191194
hideAutocomplete();

resources/assets/sass/_app.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ div.create {
926926
max-width: 620px;
927927
position: relative;
928928
z-index: 4;
929+
930+
// Reduce width when there's no select dropdown (only has hidden input)
931+
&:has(input[name="provider"][type="hidden"]) {
932+
max-width: 520px;
933+
}
934+
929935
form {
930936
width: 100%;
931937
}
@@ -944,6 +950,11 @@ div.create {
944950
width: 100%;
945951
background: transparent;
946952
}
953+
// When there's no select dropdown, round the input's left corners
954+
input[name="q"]:first-child {
955+
border-top-left-radius: 5px;
956+
border-bottom-left-radius: 5px;
957+
}
947958
button {
948959
position: absolute;
949960
right: 0px;
@@ -967,6 +978,11 @@ div.create {
967978
border-top-left-radius: 5px;
968979
border-bottom-left-radius: 5px;
969980
}
981+
// When select exists, remove input's left border radius
982+
select ~ input[name="q"] {
983+
border-top-left-radius: 0;
984+
border-bottom-left-radius: 0;
985+
}
970986
}
971987

972988
#search-autocomplete {

0 commit comments

Comments
 (0)