Skip to content

Commit b933bb6

Browse files
fix(FilterBar): remote query dropdown for value field
1 parent 40f5a22 commit b933bb6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/searchbar/src/filterbar/FilterForm.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ export const FilterForm = ({
172172
/>
173173
</Controller>
174174
);
175+
} else if (!!field.onSearch || field.values?.length) {
176+
return (
177+
<Controller name="value">
178+
<Select
179+
searchable
180+
allowCreate
181+
allowClear
182+
options={field.values ?? []}
183+
label={t("label.value")}
184+
onQuery={field.onSearch}
185+
/>
186+
</Controller>
187+
);
175188
} else {
176189
return (
177190
<Controller name="value">

packages/searchbar/stories/SearchBar.stories.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
MenuItem,
3131
} from "@react-fabric/core";
3232
import { SuperDate } from "@react-fabric/superdate";
33-
import { shortHash } from "@react-fabric/utilities";
33+
import { Countries, matchString, shortHash } from "@react-fabric/utilities";
3434
import { action } from "@storybook/addon-actions";
3535
import type { Meta, StoryObj } from "@storybook/react";
3636
import { FIELD_TYPE, OPERATOR, SearchBar } from "../src";
@@ -194,6 +194,25 @@ export const _SearchBar: SearchBarStory = {
194194
label: "Extras",
195195
type: FIELD_TYPE.NONE,
196196
},
197+
{
198+
field: "country",
199+
label: "Country",
200+
type: FIELD_TYPE.STRING,
201+
onSearch(q) {
202+
return new Promise((resolve) => {
203+
setTimeout(() => {
204+
resolve(
205+
Countries.list
206+
.filter(
207+
(ctr) =>
208+
matchString(ctr.name, q) || matchString(ctr.fullname, q),
209+
)
210+
.map((c) => c.name),
211+
);
212+
}, 1000);
213+
});
214+
},
215+
},
197216
],
198217
filters: [
199218
{

0 commit comments

Comments
 (0)