I would like to mimic two behaviors as Gmail recipient input.
import * as ReactDOM from 'react-dom';
import { useState } from 'react';
import {
DataManager,
Query,
ReturnOption,
UrlAdaptor
} from '@syncfusion/ej2-data';
import '@syncfusion/ej2-base/styles/material.css';
import '@syncfusion/ej2-buttons/styles/material.css';
import '@syncfusion/ej2-inputs/styles/material.css';
import '@syncfusion/ej2-react-dropdowns/styles/material.css';
import {
ChangeEventArgs,
FilteringEventArgs,
FocusEventArgs,
MultiSelectComponent,
TaggingEventArgs
} from '@syncfusion/ej2-react-dropdowns';
import './RecipientInput.scss';
const RecipientInput = (props) => {
const searchData: { [key: string]: Object }[] = [
];
let fields: object = { text: 'country', value: 'index' };
let multiselectComponent: MultiSelectComponent;
let onTagging = (e: TaggingEventArgs) => {
if (e.itemData['country'].indexOf('@') < 0) {
e.setClass('invalid');
}
// set the current selected item text as class to chip element.
// e.setClass((e.itemData as any)[this.fields.text].toLowerCase());
};
const onSelect = () => {
props.recipients(multiselectComponent.value);
}
const onFiltering = (args: FilteringEventArgs) => {
let query = new Query();
// frame the query based on search string with filter type.
query =
args.text !== ''
? query.where('country', 'startswith', args.text, true)
: query;
// pass the filter data source, filter query to updateData method.
args.updateData(searchData, query);
};
return (
<MultiSelectComponent
ref={(scope) => {
(multiselectComponent as MultiSelectComponent | null) = scope;
}}
mode="Default"
onChange={onSelect}
showClearButton={true}
allowCustomValue={true}
addTagOnBlur={true}
openOnClick={false}
closePopupOnSelect={true}
dataSource={searchData}
fields={fields}
allowFiltering={true}
htmlAttributes={{ innerHeight: '24px' }}
filtering={onFiltering}
tagging={onTagging}
/>
);
};
export default RecipientInput;