mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
:globe: fix cascader locale, close #13486
This commit is contained in:
parent
56665144ae
commit
a2a016d8cf
@ -840,7 +840,6 @@ exports[`Cascader should highlight keyword and filter when search in Cascader 1`
|
||||
},
|
||||
]
|
||||
}
|
||||
placeholder="Please select"
|
||||
popupClassName=""
|
||||
popupPlacement="bottomLeft"
|
||||
popupVisible={true}
|
||||
@ -1131,7 +1130,6 @@ exports[`Cascader should render not found content 1`] = `
|
||||
},
|
||||
]
|
||||
}
|
||||
placeholder="Please select"
|
||||
popupClassName=""
|
||||
popupPlacement="bottomLeft"
|
||||
popupVisible={true}
|
||||
|
@ -7,6 +7,7 @@ import KeyCode from 'rc-util/lib/KeyCode';
|
||||
import Input from '../input';
|
||||
import Icon from '../icon';
|
||||
import { ConfigConsumer, ConfigProviderProps } from '../config-provider';
|
||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||
import warning from '../_util/warning';
|
||||
|
||||
export interface CascaderOptionType {
|
||||
@ -14,7 +15,6 @@ export interface CascaderOptionType {
|
||||
label?: React.ReactNode;
|
||||
disabled?: boolean;
|
||||
children?: Array<CascaderOptionType>;
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@ -105,6 +105,10 @@ export interface CascaderState {
|
||||
flattenOptions: CascaderOptionType[][] | undefined;
|
||||
}
|
||||
|
||||
interface CascaderLocale {
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
// We limit the filtered item count by default
|
||||
const defaultLimit = 50;
|
||||
|
||||
@ -182,7 +186,6 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
|
||||
static defaultProps = {
|
||||
prefixCls: 'ant-cascader',
|
||||
inputPrefixCls: 'ant-input',
|
||||
placeholder: 'Please select',
|
||||
transitionName: 'slide-up',
|
||||
popupPlacement: 'bottomLeft',
|
||||
options: [],
|
||||
@ -393,13 +396,16 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
|
||||
this.input = node;
|
||||
};
|
||||
|
||||
renderCascader = ({ getPopupContainer: getContextPopupContainer }: ConfigProviderProps) => {
|
||||
renderCascader = (
|
||||
{ getPopupContainer: getContextPopupContainer }: ConfigProviderProps,
|
||||
locale: CascaderLocale,
|
||||
) => {
|
||||
const { props, state } = this;
|
||||
const {
|
||||
prefixCls,
|
||||
inputPrefixCls,
|
||||
children,
|
||||
placeholder,
|
||||
placeholder = locale.placeholder,
|
||||
size,
|
||||
disabled,
|
||||
className,
|
||||
@ -409,6 +415,7 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
|
||||
suffixIcon,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
const { value, inputFocused } = state;
|
||||
|
||||
const sizeCls = classNames({
|
||||
@ -548,6 +555,12 @@ export default class Cascader extends React.Component<CascaderProps, CascaderSta
|
||||
};
|
||||
|
||||
render() {
|
||||
return <ConfigConsumer>{this.renderCascader}</ConfigConsumer>;
|
||||
return (
|
||||
<ConfigConsumer>
|
||||
{(configArgument: ConfigProviderProps) => (
|
||||
<LocaleReceiver>{locale => this.renderCascader(configArgument, locale)}</LocaleReceiver>
|
||||
)}
|
||||
</ConfigConsumer>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
import * as React from 'react';
|
||||
import * as PropTypes from 'prop-types';
|
||||
import defaultLocaleData from './default';
|
||||
|
||||
const defaultComponentName = 'global';
|
||||
|
||||
export interface LocaleReceiverProps {
|
||||
componentName: string;
|
||||
defaultLocale: object | Function;
|
||||
componentName?: string;
|
||||
defaultLocale?: object | Function;
|
||||
children: (locale: object, localeCode?: string) => React.ReactElement<any>;
|
||||
}
|
||||
|
||||
@ -12,6 +15,11 @@ export interface LocaleReceiverContext {
|
||||
}
|
||||
|
||||
export default class LocaleReceiver extends React.Component<LocaleReceiverProps> {
|
||||
static defaultProps = {
|
||||
componentName: defaultComponentName,
|
||||
defaultLocale: defaultLocaleData[defaultComponentName],
|
||||
};
|
||||
|
||||
static contextTypes = {
|
||||
antLocale: PropTypes.object,
|
||||
};
|
||||
@ -21,7 +29,7 @@ export default class LocaleReceiver extends React.Component<LocaleReceiverProps>
|
||||
getLocale() {
|
||||
const { componentName, defaultLocale } = this.props;
|
||||
const { antLocale } = this.context;
|
||||
const localeFromContext = antLocale && antLocale[componentName];
|
||||
const localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
|
||||
return {
|
||||
...(typeof defaultLocale === 'function' ? defaultLocale() : defaultLocale),
|
||||
...(localeFromContext || {}),
|
||||
@ -33,7 +41,7 @@ export default class LocaleReceiver extends React.Component<LocaleReceiverProps>
|
||||
const localeCode = antLocale && antLocale.locale;
|
||||
// Had use LocaleProvide but didn't set locale
|
||||
if (antLocale && antLocale.exist && !localeCode) {
|
||||
return 'en-us';
|
||||
return defaultLocaleData.locale;
|
||||
}
|
||||
return localeCode;
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ export default {
|
||||
DatePicker,
|
||||
TimePicker,
|
||||
Calendar,
|
||||
// locales for all comoponents
|
||||
global: {
|
||||
placeholder: 'Please select',
|
||||
},
|
||||
Table: {
|
||||
filterTitle: 'Filter menu',
|
||||
filterConfirm: 'OK',
|
||||
|
@ -9,6 +9,10 @@ export default {
|
||||
DatePicker,
|
||||
TimePicker,
|
||||
Calendar,
|
||||
// locales for all comoponents
|
||||
global: {
|
||||
placeholder: '请选择',
|
||||
},
|
||||
Table: {
|
||||
filterTitle: '筛选',
|
||||
filterConfirm: '确定',
|
||||
|
Loading…
Reference in New Issue
Block a user