Skip to content

Commit fab5946

Browse files
authoredApr 1, 2022
feat(Cascader): 增加API参数size和 inputProps (#734)
1 parent c89cd0c commit fab5946

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed
 

‎packages/react-cascader/README.md

+53
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,57 @@ const Demo = () => {
8484
ReactDOM.render(<Demo />, _mount_);
8585
```
8686

87+
## 尺寸
88+
89+
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true-->
90+
```jsx
91+
import ReactDOM from 'react-dom';
92+
import { Cascader } from 'uiw';
93+
94+
const Demo = () => {
95+
96+
const options = [
97+
{
98+
label: '尺寸', value: 1,
99+
children: [
100+
{
101+
label: 'size',
102+
value: 2,
103+
children: [
104+
{ label: '小尺寸', value: 3 },
105+
{ label: '默认尺寸', value: 4 },
106+
{ label: '大尺寸', value: 5 },
107+
]
108+
},
109+
]
110+
}
111+
];
112+
113+
return (
114+
<Row style={{ flexDirection: 'column' }}>
115+
<Cascader
116+
style={{ width: 150 }}
117+
value={[1, 2, 3]}
118+
option={options}
119+
size="small"
120+
/>
121+
<Cascader
122+
style={{ width: 175, marginTop: 10 }}
123+
value={[1, 2, 4]}
124+
option={options}
125+
/>
126+
<Cascader
127+
style={{ width: 200, marginTop: 10 }}
128+
value={[1, 2, 5]}
129+
option={options}
130+
size="large"
131+
/>
132+
</Row>
133+
)
134+
};
135+
ReactDOM.render(<Demo />, _mount_);
136+
```
137+
87138
## 搜索选项
88139

89140
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true-->
@@ -263,3 +314,5 @@ ReactDOM.render(<Demo />, _mount_);
263314
| value | 指定当前选中的条目,多选时为一个数组 | String[] \| Number[] | - | - |
264315
| onChange | 选中选项调用此函数 | function( isSeleted, value, selectedOptions) | - | - |
265316
| onSearch | 开启搜索选项 | functionon(searchText) \| Boolean | - | v4.16.1 |
317+
| size | 选择框尺寸 | Enum{large, default, small } | `default` | v17.0.1 |
318+
| inputProps | 传给[Input](http://localhost:3000/#/components/input)组件的参数 | Object | - | v17.0.1 |

‎packages/react-cascader/src/index.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect, useMemo } from 'react';
22
import Input from '@uiw/react-input';
3-
import { IProps } from '@uiw/utils';
3+
import { HTMLInputProps, IProps } from '@uiw/utils';
44
import Dropdown, { DropdownProps } from '@uiw/react-dropdown';
55
import Menu from '@uiw/react-menu';
66
import Icon from '@uiw/react-icon';
@@ -11,13 +11,15 @@ type OptionType = { value: string | number; label: React.ReactNode; children?: A
1111
type SearchOptionType = { label: string; options: Array<OptionType> };
1212

1313
export interface CascaderProps extends IProps, DropdownProps {
14+
size?: 'large' | 'default' | 'small';
1415
option?: Array<OptionType>;
1516
value?: ValueType;
1617
onChange?: (isSeleted: boolean, value: ValueType, selectedOptions: Array<OptionType>) => void;
1718
onSearch?: boolean | ((searchText: string) => void);
1819
allowClear?: boolean;
1920
placeholder?: string;
2021
disabled?: boolean;
22+
inputProps?: HTMLInputProps;
2123
}
2224

2325
function Cascader(props: CascaderProps) {
@@ -26,6 +28,7 @@ function Cascader(props: CascaderProps) {
2628
onChange,
2729
onSearch,
2830

31+
size,
2932
disabled,
3033
allowClear,
3134
placeholder,
@@ -34,6 +37,7 @@ function Cascader(props: CascaderProps) {
3437
style = { width: 200 },
3538
option = [],
3639
others,
40+
inputProps,
3741
} = props;
3842

3943
const cls = [prefixCls, className].filter(Boolean).join(' ').trim();
@@ -178,7 +182,7 @@ function Cascader(props: CascaderProps) {
178182
<Dropdown
179183
className={cls}
180184
trigger="click"
181-
style={{ marginTop: 5, ...style }}
185+
style={{ marginTop: 5 }}
182186
overlayStyl={{ width: 100 }}
183187
disabled={disabled}
184188
{...others}
@@ -226,11 +230,13 @@ function Cascader(props: CascaderProps) {
226230
>
227231
<span onMouseLeave={() => renderSelectIcon('leave')} onMouseOver={() => renderSelectIcon('enter')}>
228232
<Input
233+
{...inputProps}
229234
value={searchOn ? searchText : inputValue}
230235
onChange={inputChange}
236+
size={size}
231237
disabled={disabled}
232238
placeholder={searchOn ? inputValue : placeholder}
233-
style={{ width: style?.width }}
239+
style={style}
234240
onFocus={() => onSearch && setSearchOn(true)}
235241
onBlur={() => onSearch && setSearchOn(false)}
236242
readOnly={!onSearch}

0 commit comments

Comments
 (0)
Please sign in to comment.