Skip to content

Commit

Permalink
fix(list-picker): list-picker mutiple controlled error (#1517)
Browse files Browse the repository at this point in the history
Co-authored-by: berber1016 <c1094282069@gmail.com>
  • Loading branch information
berber1016 and berber1016 committed Nov 23, 2021
1 parent 187aa45 commit 23a1ace
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/list-picker/Trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const Trigger: React.FC<TriggerProps> = (props) => {
onClear?.(e);
e.stopPropagation();
};

return <Input.Button placeholder={placeholder} value={value as string} onClear={handleClear} {...rest} />;
return <Input.Button placeholder={placeholder} value={(value as string) ?? ''} onClear={handleClear} {...rest} />;
};

export default Trigger;
11 changes: 11 additions & 0 deletions src/list-picker/demos/List-picker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ListPicker from '../listPicker';
import SearchBar from '../../search-bar';
import Tabs, { Tab } from '../../tabs';
import List from '../../list';
import Button from '../../button/Button';

export default {
title: 'Upgraded/ListPicker',
Expand Down Expand Up @@ -45,6 +46,11 @@ const Template: Story<ListPickerProps> = () => {
<div>
<h3>单选</h3>
<div className="demo-box">
<div style={{ padding: '10px' }}>
<Button size="small" onClick={() => setValue(undefined)}>
清空
</Button>
</div>
<ListPicker
value={value}
onChange={onChange}
Expand Down Expand Up @@ -178,6 +184,11 @@ const Template: Story<ListPickerProps> = () => {
</ListPicker>
</div>
<div className="demo-box">
<div style={{ padding: '10px' }}>
<Button size="small" onClick={() => setMultipleValue(['ziyi', 'zier'])}>
全选
</Button>
</div>
<ListPicker
value={multipleValue}
onChange={(val) => {
Expand Down
6 changes: 2 additions & 4 deletions src/list-picker/listPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ListPicker: React.FC<ListPickerProps> = (props) => {
separator = '',
className,
style,
model = 'simple',
model = 'single',
needConfim = model === 'multiple',
} = props;
const defaultPrefix = usePrefixCls(prefixCls);
Expand All @@ -53,9 +53,7 @@ const ListPicker: React.FC<ListPickerProps> = (props) => {
}, [controlledValue, getLabelByValue, separator, options]);

useEffect(() => {
if (!needConfim) {
setValue(controlledValue);
}
setValue(controlledValue);
}, [controlledValue, needConfim, setValue]);
useEffect(() => {
if (needConfim && !visible && !isEqual(controlledValue, value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const List: React.ForwardRefRenderFunction<HTMLDivElement, ListProps> & {
children,
disabled = false,
value: controlledValue,
model = 'simple',
model = 'single',
collapse: initCollapse = 10,
prefix,
suffix,
Expand Down
2 changes: 1 addition & 1 deletion src/list/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OptionProps, ListProps } from './interfance';

interface ListContextProps {
value?: string | string[];
model?: 'simple' | 'cascader' | 'multiple';
model?: 'single' | 'cascader' | 'multiple';
onChange?: (value?: string | string[], options?: OptionProps | OptionProps[]) => void;
options?: Map<string, OptionProps>;
setOptions?: (options?: OptionProps[]) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/list/interfance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export type ModelType = 'cascader' | 'multiple' | 'simple';
export type ModelType = 'cascader' | 'multiple' | 'single';

export interface SelectionProps extends ListProps {
className?: string;
Expand Down

1 comment on commit 23a1ace

@vercel
Copy link

@vercel vercel bot commented on 23a1ace Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.