From ae611d0aa6a8f8022d1685dece0a23d375d94c95 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 6 Sep 2017 09:33:36 +1000 Subject: [PATCH 1/2] Add: Some test cases. --- types/react-select/react-select-tests.tsx | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/types/react-select/react-select-tests.tsx b/types/react-select/react-select-tests.tsx index 7ac189f231..15527339b1 100644 --- a/types/react-select/react-select-tests.tsx +++ b/types/react-select/react-select-tests.tsx @@ -186,6 +186,43 @@ describe("Examples", () => { } }); + it("onValueClick", () => { + class Component extends React.Component { + private onValueClick: ReactSelect.OnValueClickHandler = (option) => { + const optionValue: number = option.value; + } + + render() { + const options = [ + { value: 3, label: "Option 3" }, + { value: 9, label: "Option 9" } + ]; + + return ; + } + } + }); + + it("Custom value onValueClick", () => { + class Component extends React.Component { + private onValueClick: ReactSelect.OnValueClickHandler = (option) => { + const optionValue: CustomValueType = option.value; + } + + render() { + return ; + } + } + }); + it("Custom value onChange", () => { class Component extends React.Component { private onSelectChange: ReactSelect.OnChangeSingleHandler = (option) => { From 5a412fbc878e350d0557f85ffc75a23499b5076a Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 6 Sep 2017 09:43:09 +1000 Subject: [PATCH 2/2] Fix: OnValueClickHandler type now gets Option as first parameter, not a string value. --- types/react-select/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-select/index.d.ts b/types/react-select/index.d.ts index eae34b6905..15831caa44 100644 --- a/types/react-select/index.d.ts +++ b/types/react-select/index.d.ts @@ -40,7 +40,7 @@ declare namespace ReactSelectClass { type OnBlurHandler = React.FocusEventHandler; type OptionRendererHandler = (option: Option) => HandlerRendererResult; type ValueRendererHandler = (option: Option) => HandlerRendererResult; - type OnValueClickHandler = (value: string, event: React.MouseEvent) => void; + type OnValueClickHandler = (option: Option, event: React.MouseEvent) => void; type IsOptionUniqueHandler = (arg: { option: Option, options: Options, labelKey: string, valueKey: string }) => boolean; type IsValidNewOptionHandler = (arg: { label: string }) => boolean; type NewOptionCreatorHandler = (arg: { label: string, labelKey: string, valueKey: string }) => Option; @@ -421,7 +421,7 @@ declare namespace ReactSelectClass { /** * onClick handler for value labels: function (value, event) {} */ - onValueClick?: OnValueClickHandler; + onValueClick?: OnValueClickHandler; /** * pass the value to onChange as a simple value (legacy pre 1.0 mode), defaults to false