fix: autocomplete custom children class not work

* refactor(v3/vc-selector/input): use composition api

* fix: change input props className to class

* revert with cloneElement

* fix: auto-complete demo custom test
cssinjs
bqy_fe 2022-03-20 10:50:57 +08:00 committed by GitHub
parent c86338542d
commit 414e7a1c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 155 additions and 166 deletions

View File

@ -1,6 +1,10 @@
export type FocusEventHandler = (e: FocusEvent) => void; export type FocusEventHandler = (e: FocusEvent) => void;
export type MouseEventHandler = (e: MouseEvent) => void; export type MouseEventHandler = (e: MouseEvent) => void;
export type KeyboardEventHandler = (e: KeyboardEvent) => void; export type KeyboardEventHandler = (e: KeyboardEvent) => void;
export type CompositionEventHandler = (e: CompositionEvent) => void;
export type ClipboardEventHandler = (e: ClipboardEvent) => void;
export type ChangeEventHandler = (e: ChangeEvent) => void;
export type ChangeEvent = Event & { export type ChangeEvent = Event & {
target: { target: {
value?: string | undefined; value?: string | undefined;

View File

@ -30,7 +30,7 @@ exports[`renders ./components/auto-complete/demo/custom.vue correctly 1`] = `
<div style="width: 200px;" class="ant-select ant-select-show-search ant-select-auto-complete ant-select-single ant-select-customize-input ant-select-show-search"> <div style="width: 200px;" class="ant-select ant-select-show-search ant-select-auto-complete ant-select-single ant-select-customize-input ant-select-show-search">
<!----> <!---->
<!----> <!---->
<div class="ant-select-selector"><span class="ant-select-selection-search"><textarea placeholder="input here" id="rc_select_TEST_OR_SSR" autocomplete="off" class="ant-input ant-select-selection-search-input" style="height: 50px;" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_TEST_OR_SSR_list" aria-autocomplete="list" aria-controls="rc_select_TEST_OR_SSR_list" aria-activedescendant="rc_select_TEST_OR_SSR_list_0"></textarea></span> <div class="ant-select-selector"><span class="ant-select-selection-search"><textarea placeholder="input here" id="rc_select_TEST_OR_SSR" autocomplete="off" class="ant-input ant-select-selection-search-input custom" style="height: 50px;" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_TEST_OR_SSR_list" aria-autocomplete="list" aria-controls="rc_select_TEST_OR_SSR_list" aria-activedescendant="rc_select_TEST_OR_SSR_list_0"></textarea></span>
<!----><span class="ant-select-selection-placeholder"><!----></span> <!----><span class="ant-select-selection-placeholder"><!----></span>
</div> </div>
<!----> <!---->

View File

@ -1,46 +1,23 @@
import { cloneElement } from '../../_util/vnode'; import { cloneElement } from '../../_util/vnode';
import type { VNode } from 'vue'; import type { ExtractPropTypes, PropType, VNode } from 'vue';
import { defineComponent, getCurrentInstance, inject, onMounted, withDirectives } from 'vue'; import { defineComponent, getCurrentInstance, inject, onMounted, withDirectives } from 'vue';
import PropTypes from '../../_util/vue-types'; import PropTypes from '../../_util/vue-types';
import type { RefObject } from '../../_util/createRef';
import antInput from '../../_util/antInputDirective'; import antInput from '../../_util/antInputDirective';
import classNames from '../../_util/classNames'; import classNames from '../../_util/classNames';
import type { EventHandler } from '../../_util/EventInterface'; import type {
import type { VueNode } from '../../_util/type'; FocusEventHandler,
KeyboardEventHandler,
MouseEventHandler,
ChangeEventHandler,
CompositionEventHandler,
ClipboardEventHandler,
} from '../../_util/EventInterface';
interface InputProps { export const inputProps = {
prefixCls: string;
id: string;
inputElement: VueNode;
disabled: boolean;
autofocus: boolean;
autocomplete: string;
editable: boolean;
activeDescendantId?: string;
value: string;
open: boolean;
tabindex: number | string;
/** Pass accessibility props to input */
attrs: object;
inputRef: RefObject;
onKeydown: EventHandler;
onMousedown: EventHandler;
onChange: EventHandler;
onPaste: EventHandler;
onCompositionstart: EventHandler;
onCompositionend: EventHandler;
onFocus: EventHandler;
onBlur: EventHandler;
}
const Input = defineComponent({
name: 'Input',
inheritAttrs: false,
props: {
inputRef: PropTypes.any, inputRef: PropTypes.any,
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
id: PropTypes.string, id: PropTypes.string,
inputElement: PropTypes.any, inputElement: PropTypes.VueNode,
disabled: PropTypes.looseBool, disabled: PropTypes.looseBool,
autofocus: PropTypes.looseBool, autofocus: PropTypes.looseBool,
autocomplete: PropTypes.string, autocomplete: PropTypes.string,
@ -51,16 +28,26 @@ const Input = defineComponent({
tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/** Pass accessibility props to input */ /** Pass accessibility props to input */
attrs: PropTypes.object, attrs: PropTypes.object,
onKeydown: PropTypes.func, onKeydown: { type: Function as PropType<KeyboardEventHandler> },
onMousedown: PropTypes.func, onMousedown: { type: Function as PropType<MouseEventHandler> },
onChange: PropTypes.func, onChange: { type: Function as PropType<ChangeEventHandler> },
onPaste: PropTypes.func, onPaste: { type: Function as PropType<ClipboardEventHandler> },
onCompositionstart: PropTypes.func, onCompositionstart: { type: Function as PropType<CompositionEventHandler> },
onCompositionend: PropTypes.func, onCompositionend: { type: Function as PropType<CompositionEventHandler> },
onFocus: PropTypes.func, onFocus: { type: Function as PropType<FocusEventHandler> },
onBlur: PropTypes.func, onBlur: { type: Function as PropType<FocusEventHandler> },
}, };
export type InputProps = Partial<ExtractPropTypes<typeof inputProps>>;
const Input = defineComponent({
name: 'Input',
inheritAttrs: false,
props: inputProps,
setup(props) { setup(props) {
let blurTimeout = null;
const VCSelectContainerEvent = inject('VCSelectContainerEvent') as any;
if (process.env.NODE_ENV === 'test') { if (process.env.NODE_ENV === 'test') {
onMounted(() => { onMounted(() => {
const ins = getCurrentInstance(); const ins = getCurrentInstance();
@ -71,12 +58,8 @@ const Input = defineComponent({
} }
}); });
} }
return {
blurTimeout: null, return () => {
VCSelectContainerEvent: inject('VCSelectContainerEvent') as any,
};
},
render() {
const { const {
prefixCls, prefixCls,
id, id,
@ -99,7 +82,8 @@ const Input = defineComponent({
open, open,
inputRef, inputRef,
attrs, attrs,
} = this.$props as InputProps; } = props;
let inputNode: any = inputElement || withDirectives((<input />) as VNode, [[antInput]]); let inputNode: any = inputElement || withDirectives((<input />) as VNode, [[antInput]]);
const inputProps = inputNode.props || {}; const inputProps = inputNode.props || {};
@ -123,7 +107,7 @@ const Input = defineComponent({
tabindex, tabindex,
autocomplete: autocomplete || 'off', autocomplete: autocomplete || 'off',
autofocus, autofocus,
class: classNames(`${prefixCls}-selection-search-input`, inputNode?.props?.className), class: classNames(`${prefixCls}-selection-search-input`, inputNode?.props?.class),
style: { ...style, opacity: editable ? null : 0 }, style: { ...style, opacity: editable ? null : 0 },
role: 'combobox', role: 'combobox',
'aria-expanded': open, 'aria-expanded': open,
@ -168,16 +152,16 @@ const Input = defineComponent({
}, },
onPaste, onPaste,
onFocus: (...args: any[]) => { onFocus: (...args: any[]) => {
clearTimeout(this.blurTimeout); clearTimeout(blurTimeout);
onOriginFocus && onOriginFocus(args[0]); onOriginFocus && onOriginFocus(args[0]);
onFocus && onFocus(args[0]); onFocus && onFocus(args[0]);
this.VCSelectContainerEvent?.focus(args[0]); VCSelectContainerEvent?.focus(args[0]);
}, },
onBlur: (...args: any[]) => { onBlur: (...args: any[]) => {
this.blurTimeout = setTimeout(() => { blurTimeout = setTimeout(() => {
onOriginBlur && onOriginBlur(args[0]); onOriginBlur && onOriginBlur(args[0]);
onBlur && onBlur(args[0]); onBlur && onBlur(args[0]);
this.VCSelectContainerEvent?.blur(args[0]); VCSelectContainerEvent?.blur(args[0]);
}, 100); }, 100);
}, },
}, },
@ -187,6 +171,7 @@ const Input = defineComponent({
true, true,
) as VNode; ) as VNode;
return inputNode; return inputNode;
};
}, },
}); });