fix: select class not update #4194

pull/4199/head
tangjinzhou 4 years ago
parent 02e134f81d
commit 74b66ecbfb

@ -1,12 +1,12 @@
import { computed, defineComponent, inject, ref, VNodeChild, App, PropType, Plugin } from 'vue'; import { computed, defineComponent, ref, VNodeChild, App, PropType, Plugin } from 'vue';
import omit from 'omit.js'; import omit from 'omit.js';
import classNames from '../_util/classNames'; import classNames from '../_util/classNames';
import RcSelect, { Option, OptGroup, SelectProps as RcSelectProps, BaseProps } from '../vc-select'; import RcSelect, { Option, OptGroup, SelectProps as RcSelectProps, BaseProps } from '../vc-select';
import { OptionProps as OptionPropsType } from '../vc-select/Option'; import { OptionProps as OptionPropsType } from '../vc-select/Option';
import { defaultConfigProvider } from '../config-provider';
import getIcons from './utils/iconUtil'; import getIcons from './utils/iconUtil';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { tuple } from '../_util/type'; import { tuple } from '../_util/type';
import useConfigInject from '../_util/hooks/useConfigInject';
type RawValue = string | number; type RawValue = string | number;
@ -74,11 +74,10 @@ const Select = defineComponent({
props: SelectProps(), props: SelectProps(),
SECRET_COMBOBOX_MODE_DO_NOT_USE: 'SECRET_COMBOBOX_MODE_DO_NOT_USE', SECRET_COMBOBOX_MODE_DO_NOT_USE: 'SECRET_COMBOBOX_MODE_DO_NOT_USE',
emits: ['change', 'update:value'], emits: ['change', 'update:value'],
setup(props: any, { attrs, emit }) { slots: ['notFoundContent', 'suffixIcon', 'itemIcon', 'removeIcon', 'clearIcon', 'dropdownRender'],
setup(props, { attrs, emit, slots, expose }) {
const selectRef = ref(null); const selectRef = ref(null);
const configProvider = inject('configProvider', defaultConfigProvider);
const focus = () => { const focus = () => {
if (selectRef.value) { if (selectRef.value) {
selectRef.value.focus(); selectRef.value.focus();
@ -104,60 +103,37 @@ const Select = defineComponent({
return mode; return mode;
}); });
const prefixCls = computed(() => { const { prefixCls, direction, configProvider } = useConfigInject('select', props);
return configProvider.getPrefixCls('select', props.prefixCls);
});
const mergedClassName = computed(() => const mergedClassName = computed(() =>
classNames( classNames({
{
[`${prefixCls.value}-lg`]: props.size === 'large', [`${prefixCls.value}-lg`]: props.size === 'large',
[`${prefixCls.value}-sm`]: props.size === 'small', [`${prefixCls.value}-sm`]: props.size === 'small',
[`${prefixCls.value}-rtl`]: props.direction === 'rtl', [`${prefixCls.value}-rtl`]: direction.value === 'rtl',
[`${prefixCls.value}-borderless`]: !props.bordered, [`${prefixCls.value}-borderless`]: !props.bordered,
}, }),
attrs.class,
),
); );
const triggerChange = (...args: any[]) => { const triggerChange = (...args: any[]) => {
emit('update:value', args[0]); emit('update:value', args[0]);
emit('change', ...args); emit('change', ...args);
}; };
return { expose({
selectRef,
mergedClassName,
mode,
focus,
blur, blur,
configProvider, focus,
triggerChange, });
prefixCls, return () => {
};
},
render() {
const {
configProvider,
mode,
mergedClassName,
triggerChange,
prefixCls,
$slots: slots,
$props,
} = this as any;
const props: SelectTypes = $props;
const { const {
notFoundContent, notFoundContent,
listHeight = 256, listHeight = 256,
listItemHeight = 24, listItemHeight = 24,
getPopupContainer, getPopupContainer,
dropdownClassName, dropdownClassName,
direction,
virtual, virtual,
dropdownMatchSelectWidth, dropdownMatchSelectWidth,
} = props; } = props;
const { renderEmpty, getPopupContainer: getContextPopupContainer } = configProvider; const { renderEmpty, getPopupContainer: getContextPopupContainer } = configProvider;
const isMultiple = mode === 'multiple' || mode === 'tags'; const isMultiple = mode.value === 'multiple' || mode.value === 'tags';
// ===================== Empty ===================== // ===================== Empty =====================
let mergedNotFound: VNodeChild; let mergedNotFound: VNodeChild;
@ -165,7 +141,7 @@ const Select = defineComponent({
mergedNotFound = notFoundContent; mergedNotFound = notFoundContent;
} else if (slots.notFoundContent) { } else if (slots.notFoundContent) {
mergedNotFound = slots.notFoundContent(); mergedNotFound = slots.notFoundContent();
} else if (mode === 'combobox') { } else if (mode.value === 'combobox') {
mergedNotFound = null; mergedNotFound = null;
} else { } else {
mergedNotFound = renderEmpty('Select') as any; mergedNotFound = renderEmpty('Select') as any;
@ -174,9 +150,9 @@ const Select = defineComponent({
// ===================== Icons ===================== // ===================== Icons =====================
const { suffixIcon, itemIcon, removeIcon, clearIcon } = getIcons( const { suffixIcon, itemIcon, removeIcon, clearIcon } = getIcons(
{ {
...this.$props, ...props,
multiple: isMultiple, multiple: isMultiple,
prefixCls, prefixCls: prefixCls.value,
}, },
slots, slots,
); );
@ -189,37 +165,38 @@ const Select = defineComponent({
'clearIcon', 'clearIcon',
'size', 'size',
'bordered', 'bordered',
]) as any; ]);
const rcSelectRtlDropDownClassName = classNames(dropdownClassName, { const rcSelectRtlDropDownClassName = classNames(dropdownClassName, {
[`${prefixCls}-dropdown-${direction}`]: direction === 'rtl', [`${prefixCls.value}-dropdown-${direction.value}`]: direction.value === 'rtl',
}); });
return ( return (
<RcSelect <RcSelect
ref="selectRef" ref={selectRef}
virtual={virtual} virtual={virtual}
dropdownMatchSelectWidth={dropdownMatchSelectWidth} dropdownMatchSelectWidth={dropdownMatchSelectWidth}
{...selectProps} {...selectProps}
{...this.$attrs} {...attrs}
listHeight={listHeight} listHeight={listHeight}
listItemHeight={listItemHeight} listItemHeight={listItemHeight}
mode={mode} mode={mode.value}
prefixCls={prefixCls} prefixCls={prefixCls.value}
direction={direction} direction={direction.value}
inputIcon={suffixIcon} inputIcon={suffixIcon}
menuItemSelectedIcon={itemIcon} menuItemSelectedIcon={itemIcon}
removeIcon={removeIcon} removeIcon={removeIcon}
clearIcon={clearIcon} clearIcon={clearIcon}
notFoundContent={mergedNotFound} notFoundContent={mergedNotFound}
class={mergedClassName} class={[mergedClassName.value, attrs.class]}
getPopupContainer={getPopupContainer || getContextPopupContainer} getPopupContainer={getPopupContainer || getContextPopupContainer}
dropdownClassName={rcSelectRtlDropDownClassName} dropdownClassName={rcSelectRtlDropDownClassName}
onChange={triggerChange} onChange={triggerChange}
dropdownRender={selectProps.dropdownRender || this.$slots.dropdownRender} dropdownRender={selectProps.dropdownRender || slots.dropdownRender}
> >
{slots.default?.()} {slots.default?.()}
</RcSelect> </RcSelect>
); );
};
}, },
}); });
/* istanbul ignore next */ /* istanbul ignore next */

Loading…
Cancel
Save