Add type for handleValidate prop function for react-tag-autocomplete

This commit is contained in:
Rahul-Sagore
2019-03-29 00:11:35 +05:30
parent e809175e0c
commit 9df5095d72
2 changed files with 7 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
// Type definitions for react-tag-autocomplete 5.6
// Project: https://github.com/i-like-robots/react-tags#readme
// Definitions by: James Lismore <https://github.com/jlismore>
// Rahul Sagore <https://github.com/Rahul-Sagore>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -81,6 +82,10 @@ export interface ReactTagsProps {
* Optional event handler when the input changes. Receives the current input value.
*/
handleInputChange?: (input: string) => void;
/**
* Optional validation function that determines if tag should be added to tags. Receives a tag object. Should return a boolean.
*/
handleValidate?: (tag: Tag) => boolean;
/**
* An object containing additional attributes that will be applied to the underlying <input /> field.
*/

View File

@@ -30,6 +30,7 @@ class TestAll extends React.Component {
const onBlur = () => {};
const onFocus = () => {};
const onInputChange = (input: string) => {};
const onValidate = (tag: { id: string | number; name: string }) => true;
const inputAttributes = { maxLength: 10 };
const suggestions = [
{ id: 3, name: "Bananas" },
@@ -55,6 +56,7 @@ class TestAll extends React.Component {
handleDelete={onDeleteTag}
handleFocus={onFocus}
handleInputChange={onInputChange}
handleValidate={onValidate}
inputAttributes={inputAttributes}
maxSuggestionsLength={10}
minQueryLength={5}