Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-planets-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ensembleui/react-runtime": patch
---

enhance MultiSelect with visibility control of new option via 'hideNoMatchesBlock' prop
24 changes: 17 additions & 7 deletions packages/runtime/src/widgets/Form/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export type MultiSelectProps = {
debounceMs: number;
} & EnsembleAction;
hintStyle?: EnsembleWidgetStyles;
/** Whether to allow creating new options */
allowCreateOptions?: boolean;
/** Whether to hide the "No matches" block */
hideNoMatchesBlock?: Expression<boolean>;
/** The max number of items can be selected */
maxCount: Expression<number>;
/** Max tag count to show */
Expand Down Expand Up @@ -252,10 +255,8 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {
option?: MultiSelectOption,
): boolean => {
return (
option?.label
.toString()
?.toLowerCase()
?.startsWith(input.toLowerCase()) || false
option?.label.toString()?.toLowerCase()?.includes(input.toLowerCase()) ||
false
);
};

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

const newOptionRender = (menu: ReactElement): ReactElement => (
<Dropdown menu={menu} newOption={newOption} />
<Dropdown
menu={menu}
newOption={newOption}
hideNoMatchesBlock={Boolean(values?.hideNoMatchesBlock)}
/>
);

const notFoundContentRenderer = useMemo(() => {
Expand Down Expand Up @@ -456,13 +461,18 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {
interface DropdownProps {
menu: ReactElement;
newOption: string;
hideNoMatchesBlock: boolean;
}

const Dropdown: React.FC<DropdownProps> = ({ menu, newOption }) => {
const Dropdown: React.FC<DropdownProps> = ({
menu,
newOption,
hideNoMatchesBlock,
}) => {
return (
<>
{menu}
{newOption ? (
{newOption && !hideNoMatchesBlock ? (
<Space
style={{
padding: "10px 15px",
Expand Down