From 86b7c1a2688e38d8db2f53bf9949e7caec0d7630 Mon Sep 17 00:00:00 2001 From: Izaak Baker Date: Wed, 7 Sep 2016 14:23:16 -0700 Subject: [PATCH] Add typings for Creatable class in react-select --- react-select/react-select-tests.tsx | 28 +++++++++++++++-- react-select/react-select.d.ts | 47 +++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/react-select/react-select-tests.tsx b/react-select/react-select-tests.tsx index de45b52d32..3b2ce8b429 100644 --- a/react-select/react-select-tests.tsx +++ b/react-select/react-select-tests.tsx @@ -5,7 +5,7 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import { Option, ReactSelectProps, ReactAsyncSelectProps, MenuRendererProps } from "react-select-props"; +import { Option, ReactSelectProps, ReactAsyncSelectProps, ReactCreatableSelectProps, MenuRendererProps } from "react-select-props"; import Select = require("react-select"); const CustomOption = React.createClass({ @@ -104,7 +104,6 @@ class SelectTest extends React.Component, {}> { key: "1", options: options, optionRenderer: optionRenderer, - allowCreate: true, autofocus: true, autosize: true, clearable: true, @@ -200,3 +199,28 @@ class SelectAsyncTest extends React.Component, {}> { } } + +class SelectCreatableTest extends React.Component, {}> { + + render() { + const options: Option[] = [{ label: "Foo", value: "bar" }]; + const onChange = (value: any) => console.log(value); + + const creatableSelectProps: ReactCreatableSelectProps = { + name: "test-creatable-select", + value: "bar", + options: options, + onChange: onChange, + isOptionUnique: () => { return true; }, + isValidNewOption: () => { return true; }, + newOptionCreator: () => { return { label: "NewFoo", value: "newBar" }; }, + promptTextCreator: () => { return ""; }, + shouldKeyDownEventCreateNewOption: () => { return true; } + }; + + return
+ +
+ } + +} diff --git a/react-select/react-select.d.ts b/react-select/react-select.d.ts index f58cdafbdb..701d5efc4a 100644 --- a/react-select/react-select.d.ts +++ b/react-select/react-select.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-select v1.0.0 // Project: https://github.com/JedWatson/react-select -// Definitions by: ESQUIBET Hugo , Gilad Gray +// Definitions by: ESQUIBET Hugo , Gilad Gray , Izaak Baker // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -68,12 +68,6 @@ declare namespace ReactSelect { * @default 'Add "{label}"?' */ addLabelText?: string; - /** - * allow new options to be created in multi mode (displays an "Add