Skip to content

Commit 0e0e887

Browse files
committed
onChange should provide primitive values without a label
1 parent ffafc49 commit 0e0e887

File tree

4 files changed

+10
-88
lines changed

4 files changed

+10
-88
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.28",
3+
"version": "1.0.29",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Inputs/Select/Select.stories.tsx

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { action } from "@storybook/addon-actions";
22
import { useEffect, useState } from "react";
3-
import { MultiValue, SingleValue } from "react-select";
43

54
import Select from ".";
6-
import { ISelectProps, Option } from "./types";
5+
import { ISelectProps } from "./types";
76

87
export default {
98
title: "Input/Select",
@@ -17,43 +16,7 @@ export default {
1716
};
1817

1918
export const SingleSelect = (args: ISelectProps) => {
20-
const [input, setInput] = useState<
21-
Record<
22-
string,
23-
MultiValue<Option | undefined> | SingleValue<Option | undefined>
24-
>
25-
>({
26-
foo: {
27-
value: "foo",
28-
label: "foo"
29-
}
30-
});
31-
32-
useEffect(() => {
33-
console.log(input);
34-
}, [input]);
35-
36-
return <Select {...args} name='foo' value={input.foo} onChange={setInput} />;
37-
};
38-
39-
SingleSelect.args = {
40-
name: "single-select",
41-
onChange: action("onChange"),
42-
options: [
43-
{ value: "foo", label: "Foo" },
44-
{ value: "bar", label: "Bar" },
45-
{ value: "baz", label: "Baz" }
46-
],
47-
value: "foo"
48-
};
49-
50-
export const SingleSelectWithStringValue = (args: ISelectProps) => {
51-
const [input, setInput] = useState<
52-
Record<
53-
string,
54-
MultiValue<Option | undefined> | SingleValue<Option | undefined | string>
55-
>
56-
>({
19+
const [input, setInput] = useState<Record<string, string[] | string>>({
5720
foo: "foo"
5821
});
5922

@@ -64,7 +27,7 @@ export const SingleSelectWithStringValue = (args: ISelectProps) => {
6427
return <Select {...args} name='foo' value={input.foo} onChange={setInput} />;
6528
};
6629

67-
SingleSelectWithStringValue.args = {
30+
SingleSelect.args = {
6831
name: "single-select",
6932
onChange: action("onChange"),
7033
options: [
@@ -76,43 +39,7 @@ SingleSelectWithStringValue.args = {
7639
};
7740

7841
export const MultiSelect = (args: ISelectProps) => {
79-
const [input, setInput] = useState<
80-
Record<
81-
string,
82-
MultiValue<Option | undefined> | SingleValue<Option | undefined>
83-
>
84-
>({
85-
foo: [
86-
{ value: "foo", label: "foo" },
87-
{ value: "bar", label: "bar" }
88-
]
89-
});
90-
91-
useEffect(() => {
92-
console.log(input);
93-
}, [input]);
94-
95-
return <Select {...args} value={input.foo} onChange={setInput} />;
96-
};
97-
98-
MultiSelect.args = {
99-
name: "foo",
100-
isMulti: true,
101-
options: [
102-
{ value: "foo", label: "Foo" },
103-
{ value: "bar", label: "Bar" },
104-
{ value: "baz", label: "Baz" }
105-
]
106-
};
107-
108-
export const MultiSelectWithStringArray = (args: ISelectProps) => {
109-
const [input, setInput] = useState<
110-
Record<
111-
string,
112-
| MultiValue<Option | undefined>
113-
| SingleValue<Option | undefined | string[]>
114-
>
115-
>({
42+
const [input, setInput] = useState<Record<string, string[] | string>>({
11643
foo: ["foo", "bar"]
11744
});
11845

@@ -123,7 +50,7 @@ export const MultiSelectWithStringArray = (args: ISelectProps) => {
12350
return <Select {...args} value={input.foo} onChange={setInput} />;
12451
};
12552

126-
MultiSelectWithStringArray.args = {
53+
MultiSelect.args = {
12754
name: "foo",
12855
isMulti: true,
12956
options: [

src/Components/Inputs/Select/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const Select: FC<ISelectProps> = props => {
1515
option: MultiValue<Option | undefined> | SingleValue<Option | undefined>
1616
): void => {
1717
if (Array.isArray(option) && isMulti) {
18-
return props.onChange({ [props.name]: option });
18+
return props.onChange({ [props.name]: option.map(o => o?.value) });
1919
}
2020

21-
return props.onChange({ [props.name]: option });
21+
return props.onChange({ [props.name]: (option as Option)?.value });
2222
};
2323

2424
const getValue = () => {

src/Components/Inputs/Select/types.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MultiValue, PropsValue, SingleValue } from "react-select";
1+
import { PropsValue } from "react-select";
22

33
export type Option = {
44
value: string;
@@ -17,12 +17,7 @@ export interface ISelectProps {
1717
max?: number;
1818
isMulti?: boolean;
1919
isSearchable?: boolean;
20-
onChange: (
21-
option: Record<
22-
string,
23-
MultiValue<Option | undefined> | SingleValue<Option | undefined>
24-
>
25-
) => void;
20+
onChange: (option: Record<string, string[] | string>) => void;
2621
options: Option[];
2722
inputWrapperClassName?: string;
2823
}

0 commit comments

Comments
 (0)