Skip to content

Commit b0f877c

Browse files
authored
enhance MultiSelect with visibility control of new option via 'hideNoMatchesBlock' prop (#1118)
1 parent 2793463 commit b0f877c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

.changeset/wet-planets-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ensembleui/react-runtime": patch
3+
---
4+
5+
enhance MultiSelect with visibility control of new option via 'hideNoMatchesBlock' prop

packages/runtime/src/widgets/Form/MultiSelect.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ export type MultiSelectProps = {
7575
debounceMs: number;
7676
} & EnsembleAction;
7777
hintStyle?: EnsembleWidgetStyles;
78+
/** Whether to allow creating new options */
7879
allowCreateOptions?: boolean;
80+
/** Whether to hide the "No matches" block */
81+
hideNoMatchesBlock?: Expression<boolean>;
7982
/** The max number of items can be selected */
8083
maxCount: Expression<number>;
8184
/** Max tag count to show */
@@ -252,10 +255,8 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {
252255
option?: MultiSelectOption,
253256
): boolean => {
254257
return (
255-
option?.label
256-
.toString()
257-
?.toLowerCase()
258-
?.startsWith(input.toLowerCase()) || false
258+
option?.label.toString()?.toLowerCase()?.includes(input.toLowerCase()) ||
259+
false
259260
);
260261
};
261262

@@ -326,7 +327,11 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {
326327
};
327328

328329
const newOptionRender = (menu: ReactElement): ReactElement => (
329-
<Dropdown menu={menu} newOption={newOption} />
330+
<Dropdown
331+
menu={menu}
332+
newOption={newOption}
333+
hideNoMatchesBlock={Boolean(values?.hideNoMatchesBlock)}
334+
/>
330335
);
331336

332337
const notFoundContentRenderer = useMemo(() => {
@@ -456,13 +461,18 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {
456461
interface DropdownProps {
457462
menu: ReactElement;
458463
newOption: string;
464+
hideNoMatchesBlock: boolean;
459465
}
460466

461-
const Dropdown: React.FC<DropdownProps> = ({ menu, newOption }) => {
467+
const Dropdown: React.FC<DropdownProps> = ({
468+
menu,
469+
newOption,
470+
hideNoMatchesBlock,
471+
}) => {
462472
return (
463473
<>
464474
{menu}
465-
{newOption ? (
475+
{newOption && !hideNoMatchesBlock ? (
466476
<Space
467477
style={{
468478
padding: "10px 15px",

0 commit comments

Comments
 (0)