correct typo: filedNames => fieldNames

This commit is contained in:
afc163 2018-07-03 19:54:33 +08:00 committed by 陈帅
parent 8eb8c686ce
commit db4a5edf8e
5 changed files with 28 additions and 28 deletions

View File

@ -45,6 +45,6 @@ function onChange(value) {
}
ReactDOM.render(
<Cascader filedNames={{ label: 'name', value: 'code', children: 'items' }} options={options} onChange={onChange} placeholder="Please select" />,
<Cascader fieldNames={{ label: 'name', value: 'code', children: 'items' }} options={options} onChange={onChange} placeholder="Please select" />,
mountNode);
````

View File

@ -28,7 +28,7 @@ Cascade selection box.
| disabled | whether disabled select | boolean | false |
| displayRender | render function of displaying selected options | `(label, selectedOptions) => ReactNode` | `label => label.join(' / ')` |
| expandTrigger | expand current item when click or hover, one of 'click' 'hover' | string | 'click' |
| filedNames | custom field name for label and value and children | object | `{ label: 'label', value: 'value', children: 'children' }` |
| fieldNames | custom field name for label and value and children | object | `{ label: 'label', value: 'value', children: 'children' }` |
| getPopupContainer | Parent Node which the selector should be rendered to. Default to `body`. When position issues happen, try to modify it into scrollable content and position it relative.[example](https://codepen.io/afc163/pen/zEjNOy?editors=0010) | Function(triggerNode) | () => document.body |
| loadData | To load option lazily, and it cannot work with `showSearch` | `(selectedOptions) => void` | - |
| notFoundContent | Specify content to show when no result matches. | string | 'Not Found' |

View File

@ -15,13 +15,13 @@ export interface CascaderOptionType {
[key: string]: any;
}
export interface FiledNamesType {
export interface FieldNamesType {
value?: string;
label?: string;
children?: string;
}
export interface FilledFiledNamesType {
export interface FilledFieldNamesType {
value: string;
label: string;
children: string;
@ -30,14 +30,14 @@ export interface FilledFiledNamesType {
export type CascaderExpandTrigger = 'click' | 'hover';
export interface ShowSearchType {
filter?: (inputValue: string, path: CascaderOptionType[], names: FilledFiledNamesType) => boolean;
filter?: (inputValue: string, path: CascaderOptionType[], names: FilledFieldNamesType) => boolean;
render?: (
inputValue: string,
path: CascaderOptionType[],
prefixCls: string | undefined,
names: FilledFiledNamesType,
names: FilledFieldNamesType,
) => React.ReactNode;
sort?: (a: CascaderOptionType[], b: CascaderOptionType[], inputValue: string, names: FilledFiledNamesType) => number;
sort?: (a: CascaderOptionType[], b: CascaderOptionType[], inputValue: string, names: FilledFieldNamesType) => number;
matchInputWidth?: boolean;
}
@ -81,7 +81,7 @@ export interface CascaderProps {
inputPrefixCls?: string;
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
popupVisible?: boolean;
filedNames?: FiledNamesType;
fieldNames?: FieldNamesType;
}
export interface CascaderState {
@ -100,7 +100,7 @@ function highlightKeyword(str: string, keyword: string, prefixCls: string | unde
]);
}
function defaultFilterOption(inputValue: string, path: CascaderOptionType[], names: FilledFiledNamesType) {
function defaultFilterOption(inputValue: string, path: CascaderOptionType[], names: FilledFieldNamesType) {
return path.some(option => (option[names.label] as string).indexOf(inputValue) > -1);
}
@ -108,7 +108,7 @@ function defaultRenderFilteredOption(
inputValue: string,
path: CascaderOptionType[],
prefixCls: string | undefined,
names: FilledFiledNamesType,
names: FilledFieldNamesType,
) {
return path.map((option, index) => {
const label = option[names.label];
@ -119,7 +119,7 @@ function defaultRenderFilteredOption(
}
function defaultSortFilteredOption(
a: CascaderOptionType[], b: CascaderOptionType[], inputValue: string, names: FilledFiledNamesType,
a: CascaderOptionType[], b: CascaderOptionType[], inputValue: string, names: FilledFieldNamesType,
) {
function callback(elem: CascaderOptionType) {
return (elem[names.label] as string).indexOf(inputValue) > -1;
@ -128,11 +128,11 @@ function defaultSortFilteredOption(
return a.findIndex(callback) - b.findIndex(callback);
}
function getFilledFieldNames(filedNames: FiledNamesType = {}) {
const names: FilledFiledNamesType = {
children: filedNames.children || 'children',
label: filedNames.label || 'label',
value: filedNames.value || 'value',
function getFilledFieldNames(fieldNames: FieldNamesType = {}) {
const names: FilledFieldNamesType = {
children: fieldNames.children || 'children',
label: fieldNames.label || 'label',
value: fieldNames.value || 'value',
};
return names;
}
@ -164,7 +164,7 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
inputFocused: false,
popupVisible: props.popupVisible,
flattenOptions:
props.showSearch ? this.flattenTree(props.options, props.changeOnSelect, props.filedNames) : undefined,
props.showSearch ? this.flattenTree(props.options, props.changeOnSelect, props.fieldNames) : undefined,
};
}
@ -177,7 +177,7 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
}
if (nextProps.showSearch && this.props.options !== nextProps.options) {
this.setState({
flattenOptions: this.flattenTree(nextProps.options, nextProps.changeOnSelect, nextProps.filedNames),
flattenOptions: this.flattenTree(nextProps.options, nextProps.changeOnSelect, nextProps.fieldNames),
});
}
}
@ -247,8 +247,8 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
}
getLabel() {
const { options, displayRender = defaultDisplayRender as Function, filedNames } = this.props;
const names = getFilledFieldNames(filedNames);
const { options, displayRender = defaultDisplayRender as Function, fieldNames } = this.props;
const names = getFilledFieldNames(fieldNames);
const value = this.state.value;
const unwrappedValue = Array.isArray(value[0]) ? value[0] : value;
const selectedOptions: CascaderOptionType[] = arrayTreeFilter(options,
@ -272,10 +272,10 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
flattenTree(
options: CascaderOptionType[],
changeOnSelect: boolean | undefined,
filedNames: FiledNamesType | undefined,
fieldNames: FieldNamesType | undefined,
ancestor: CascaderOptionType[] = [],
) {
const names: FilledFiledNamesType = getFilledFieldNames(filedNames);
const names: FilledFieldNamesType = getFilledFieldNames(fieldNames);
let flattenOptions = [] as CascaderOptionType[][];
let childrenName = names.children;
options.forEach((option) => {
@ -288,7 +288,7 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
this.flattenTree(
option[childrenName],
changeOnSelect,
filedNames,
fieldNames,
path,
),
);
@ -298,8 +298,8 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
}
generateFilteredOptions(prefixCls: string | undefined) {
const { showSearch, notFoundContent, filedNames } = this.props;
const names: FilledFiledNamesType = getFilledFieldNames(filedNames);
const { showSearch, notFoundContent, fieldNames } = this.props;
const names: FilledFieldNamesType = getFilledFieldNames(fieldNames);
const {
filter = defaultFilterOption,
render = defaultRenderFilteredOption,
@ -386,7 +386,7 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
'renderFilteredOption',
'sortFilteredOption',
'notFoundContent',
'filedNames',
'fieldNames',
]);
let options = props.options;

View File

@ -29,7 +29,7 @@ subtitle: 级联选择
| disabled | 禁用 | boolean | false |
| displayRender | 选择后展示的渲染函数 | `(label, selectedOptions) => ReactNode` | `label => label.join(' / ')` |
| expandTrigger | 次级菜单的展开方式,可选 'click' 和 'hover' | string | 'click' |
| filedNames | 自定义 options 中 label name children 的字段 | object | `{ label: 'label', value: 'value', children: 'children' }` |
| fieldNames | 自定义 options 中 label name children 的字段 | object | `{ label: 'label', value: 'value', children: 'children' }` |
| getPopupContainer | 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。[示例](https://codepen.io/afc163/pen/zEjNOy?editors=0010) | Function(triggerNode) | () => document.body |
| loadData | 用于动态加载选项,无法与 `showSearch` 一起使用 | `(selectedOptions) => void` | - |
| notFoundContent | 当下拉列表为空时显示的内容 | string | 'Not Found' |

View File

@ -54,7 +54,7 @@
"raf": "^3.4.0",
"rc-animate": "^2.4.1",
"rc-calendar": "~9.6.0",
"rc-cascader": "~0.13.0",
"rc-cascader": "~0.14.0",
"rc-checkbox": "~2.1.5",
"rc-collapse": "~1.9.0",
"rc-dialog": "~7.1.0",