DefinitelyTyped/react-select/react-select-tests.tsx
Derrick Liu 0c33358b1e react-select: Export the Option interface (#9110)
* Add an export for Option so we can use it directly

* Update tests to import the newly exported Option
2016-05-01 21:55:08 +09:00

71 lines
2.1 KiB
TypeScript

/// <reference path="../react/react.d.ts" />
/// <reference path="../react/react-dom.d.ts" />
/// <reference path="./react-select.d.ts" />
import * as React from "react";
import * as ReactDOM from "react-dom";
import Select, { Option } from "react-select";
class SelectTest extends React.Component<React.Props<{}>, {}> {
render() {
const options: Option[] = [{ label: "Foo", value: "bar" }];
const onChange = (value: any) => console.log(value);
const onOpen = () => { return; };
const onClose = () => { return; };
const optionRenderer = (option: Option) => <span>{option.label}</span>
return <div>
<Select
name="test-select"
className="test-select"
key="1"
options={options}
optionRenderer={optionRenderer}
matchPos={"any"}
matchProp={"any"}
multi={true}
onValueClick={onChange}
onOpen={onOpen}
onClose={onClose}
valueKey="github"
labelKey="name"
onChange={onChange}
simpleValue
value={options}
/>
</div>;
}
}
class SelectAsyncTest extends React.Component<React.Props<{}>, {}> {
render() {
const getOptions = (input: string, callback: Function) => {
setTimeout(function() {
callback(null, options);
}, 500);
};
const options: Option[] = [{ label: "Foo", value: "bar" }];
const onChange = (value: any) => console.log(value);
return <div>
<Select.Async
name="test-select"
className="test-select"
key="1"
matchPos={"any"}
matchProp={"any"}
multi={true}
onValueClick={onChange}
valueKey="github"
labelKey="name"
onChange={onChange}
simpleValue
value={options}
loadOptions={getOptions}
/>
</div>;
}
}