Skip to content

Commit

Permalink
fix: 修复 select 选中 值的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fikyair committed Nov 23, 2021
1 parent 9c67a4e commit 6c5c38f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chocolate-ui",
"version": "1.1.4",
"version": "1.1.5",
"description": "Indulge in silky smoothness",
"author": "shiming_xsm",
"private": false,
Expand Down
10 changes: 6 additions & 4 deletions src/components/Select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export interface SelectProps {

interface ISelectContext {
index?: string;
onSelect?: (selectItem: string) => void;
onSelect?: (selectItem: itemType) => void;
onShowOption?: (value: boolean) => void;
value?: string;
}

type itemType = { key: string, val: string}

export const SelectContext = createContext<ISelectContext>({ index: "0" });

export const Select: React.FC<SelectProps> = (props) => {
Expand All @@ -38,9 +40,9 @@ export const Select: React.FC<SelectProps> = (props) => {
const [showOption, setShowOption] = useState(false);
const [inputValue, setInputValue] = useState(defaultValue);

const handleClick = (value: string | ChangeEvent<HTMLInputElement>) => {
setInputValue(value as string);
onChange && onChange(value as ChangeEvent<HTMLInputElement>);
const handleClick = (item: itemType) => {
setInputValue(item.val as string);
onChange && onChange(item.key as unknown as ChangeEvent<HTMLInputElement>);
};
const handleShowOption = (value: boolean) => {
setShowOption(value);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Select/selectOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const SelectOption: React.FC<SelectOptionProps> = (props) => {
const [hover, setHover] = useState(false);

const handleOptionItem = (e: MouseEvent<HTMLLIElement>) => {
const _value = (e.target as any).innerHTML;
const _value = (e.target as any).innerHTML as string;
if (!props.disabled) {
context.onSelect && context.onSelect(_value);
context.onSelect && context.onSelect({ key: value, val: _value } );
context.onShowOption && context.onShowOption(false);
}
};
Expand Down

0 comments on commit 6c5c38f

Please sign in to comment.