Skip to content

Commit fdf2eb6

Browse files
authored
feat(blazorui): add FixedCalloutWidth parameter to BitSearchBox #11511 (#11538)
1 parent 3bd141a commit fdf2eb6

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

src/BlazorUI/Bit.BlazorUI/Components/Inputs/SearchBox/BitSearchBox.razor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public partial class BitSearchBox : BitTextInputBase<string?>
5757
[Parameter, ResetClassBuilder]
5858
public bool DisableAnimation { get; set; }
5959

60+
/// <summary>
61+
/// Forces the suggest callout width to be always fixed at the component's width.
62+
/// </summary>
63+
[Parameter] public bool FixedCalloutWidth { get; set; }
64+
6065
/// <summary>
6166
/// Whether or not to make the icon be always visible (it hides by default when the search box is focused).
6267
/// </summary>
@@ -535,7 +540,7 @@ await _js.BitCalloutToggleCallout(
535540
headerId: string.Empty,
536541
footerId: string.Empty,
537542
setCalloutWidth: false,
538-
fixedCalloutWidth: false,
543+
fixedCalloutWidth: FixedCalloutWidth,
539544
maxWindowWidth: 0);
540545
}
541546

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/SearchBox/BitSearchBoxDemo.razor

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@
223223
DebounceTime="300"
224224
Placeholder="e.g. pro"
225225
SuggestItemsProvider="LoadItems" />
226+
<br /><br /><br />
227+
<div><b>FixedCalloutWidth</b></div><br />
228+
<BitSearchBox Immediate
229+
FixedCalloutWidth
230+
Placeholder="e.g. app"
231+
SuggestItems="GetLongSuggestedItems()" />
226232
</div>
227233
</DemoExample>
228234

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/SearchBox/BitSearchBoxDemo.razor.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public partial class BitSearchBoxDemo
5555
Description = "Whether or not to animate the search box icon on focus.",
5656
},
5757
new()
58+
{
59+
Name = "FixedCalloutWidth",
60+
Type = "bool",
61+
DefaultValue = "false",
62+
Description = "Forces the suggest callout width to be always fixed at the component's width.",
63+
},
64+
new()
5865
{
5966
Name = "FixedIcon",
6067
Type = "bool",
@@ -646,6 +653,20 @@ private List<string> GetSuggestedItems() =>
646653
"Lettuce"
647654
];
648655

656+
private List<string> GetLongSuggestedItems() =>
657+
[
658+
"Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple",
659+
"Red Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple",
660+
"Blue Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple",
661+
"Green Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple",
662+
"Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana",
663+
"Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange",
664+
"Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape",
665+
"Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli",
666+
"Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot",
667+
"Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce"
668+
];
669+
649670
private Func<string, string, bool> SearchFunc = (string searchText, string itemText) =>
650671
{
651672
if (string.IsNullOrEmpty(searchText) || string.IsNullOrEmpty(itemText)) return false;

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/SearchBox/BitSearchBoxDemo.razor.samples.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,39 @@ public partial class BitSearchBoxDemo
9797
Immediate
9898
Placeholder=""e.g. app""
9999
SuggestItems=""GetSuggestedItems()"" />
100+
<div>SearchValue: @searchValue</div>
100101
101102
102103
<BitSearchBox @bind-Value=""@searchValueWithSuggestFilterFunction""
103104
Immediate
104105
Placeholder=""e.g. app""
105106
SuggestItems=""GetSuggestedItems()""
106107
SuggestFilterFunction=""@SearchFunc"" />
108+
<div>SearchValue: @searchValueWithSuggestFilterFunction</div>
107109
108110
109111
<BitSearchBox @bind-Value=""@searchValueWithMinSearchLength""
110112
Immediate
111113
Placeholder=""e.g. app""
112114
MinSuggestTriggerChars=""1""
113115
SuggestItems=""GetSuggestedItems()"" />
116+
<div>SearchValue: @searchValueWithMinSearchLength</div>
114117
115118
116119
<BitSearchBox @bind-Value=""@searchValueWithMaxSuggestedItems""
117120
Immediate
118121
Placeholder=""e.g. app""
119122
MaxSuggestCount=""2""
120123
SuggestItems=""GetSuggestedItems()"" />
124+
<div>SearchValue: @searchValueWithMaxSuggestedItems</div>
121125
122126
123127
<BitSearchBox @bind-Value=""@searchValueWithSearchDelay""
124128
Immediate
125129
DebounceTime=""2000""
126130
Placeholder=""e.g. app""
127131
SuggestItems=""GetSuggestedItems()"" />
132+
<div>SearchValue: @searchValueWithSearchDelay</div>
128133
129134
130135
<BitSearchBox @bind-Value=""@searchValueWithItemsProvider""
@@ -139,7 +144,13 @@ public partial class BitSearchBoxDemo
139144
Immediate
140145
DebounceTime=""300""
141146
Placeholder=""e.g. pro""
142-
SuggestItemsProvider=""LoadItems"" />";
147+
SuggestItemsProvider=""LoadItems"" />
148+
149+
150+
<BitSearchBox Immediate
151+
FixedCalloutWidth
152+
Placeholder=""e.g. app""
153+
SuggestItems=""GetLongSuggestedItems()"" />";
143154
private readonly string example10CsharpCode = @"
144155
private string searchValue;
145156
private string searchValueWithSuggestFilterFunction;
@@ -150,16 +161,30 @@ public partial class BitSearchBoxDemo
150161
151162
private List<string> GetSuggestedItems() =>
152163
[
153-
""Apple"",
154-
""Red Apple"",
155-
""Blue Apple"",
156-
""Green Apple"",
157-
""Banana"",
158-
""Orange"",
159-
""Grape"",
160-
""Broccoli"",
161-
""Carrot"",
162-
""Lettuce""
164+
""Apple"",
165+
""Red Apple"",
166+
""Blue Apple"",
167+
""Green Apple"",
168+
""Banana"",
169+
""Orange"",
170+
""Grape"",
171+
""Broccoli"",
172+
""Carrot"",
173+
""Lettuce""
174+
];
175+
176+
private List<string> GetLongSuggestedItems() =>
177+
[
178+
""Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple"",
179+
""Red Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple"",
180+
""Blue Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple"",
181+
""Green Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple Apple"",
182+
""Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana"",
183+
""Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange Orange"",
184+
""Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape Grape"",
185+
""Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli Broccoli"",
186+
""Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot Carrot"",
187+
""Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce Lettuce""
163188
];
164189
165190
private Func<string, string, bool> SearchFunc = (string searchText, string itemText) =>

0 commit comments

Comments
 (0)