The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOpt...

42 lines
1.3 KiB

import type { OptionType } from '@rocket.chat/fuselage';
import { Options } from '@rocket.chat/fuselage';
import type { ComponentProps, ReactElement, Ref } from 'react';
import { forwardRef, createContext, useContext } from 'react';
import UserAutoCompleteMultipleOption from './UserAutoCompleteMultipleOption';
// This is a hack in order to bypass the MultiSelect filter.
// The select requires a forwarded ref component in the renderOptions property
// but we also need to pass internal state to this renderer, as well as the props that also come from the Select.
export type UserLabel = {
_federated?: boolean;
username: string;
name?: string;
};
type OptionsContextValue = {
options: OptionType<string, UserLabel>[];
};
export const OptionsContext = createContext<OptionsContextValue>({
options: [],
});
const UserAutoCompleteMultipleOptions = forwardRef(function UserAutoCompleteMultipleOptions(
{ onSelect, ...props }: ComponentProps<typeof Options>,
ref: Ref<HTMLElement>,
): ReactElement {
const { options } = useContext(OptionsContext);
return (
<Options
{...props}
key='AutocompleteOptions'
options={options}
onSelect={onSelect}
ref={ref}
renderItem={UserAutoCompleteMultipleOption}
/>
);
});
export default UserAutoCompleteMultipleOptions;