chore: add clear event handler

This commit is contained in:
aalizzwell 2022-10-12 19:56:12 +08:00
parent b5e4b70ea6
commit 6b4b1f2e57
3 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import { comboListProps, ComboListProps } from './combo-list.props';
import { ButtonEdit } from '../../button-edit';
import { groupIcon, ViewType } from './types';
import { useState } from './composition/use-state';
import { useEventHandlers } from './composition/use-event-handlers';
export default defineComponent({
name: 'FComboList',
props: comboListProps,
@ -13,6 +14,7 @@ export default defineComponent({
// is panel visible
const [isPanelVisible] = useState<boolean>(false);
const [displayText, setDisplayText] = useState(props.displayText);
const { onClear } = useEventHandlers(props, context, modelValue);
return () => {
return (
<>
@ -29,7 +31,7 @@ export default defineComponent({
maxLength={props.maxLength}
style="display:block"
modelValue={displayText.value}
onClear={() => setDisplayText('')}
onClear={onClear}
/>
{/** tag area */}
{props.viewType === ViewType.Tag && (

View File

@ -4,4 +4,11 @@ import { Ref, UnwrapRef } from "vue";
* UseState type
* @description vue类型系统限制state只读
*/
export type UseState<T> = [Readonly<Ref<UnwrapRef<T>>>, (state: UnwrapRef<T>) => void];
export type UseState<T> = [Readonly<Ref<UnwrapRef<T>>>, (state: UnwrapRef<T>) => void];
export interface UseEventHandlers {
/**
*
*/
onClear: ($event: Event) => void;
}

View File

@ -0,0 +1,12 @@
import { Ref, SetupContext } from "vue";
import { ComboListProps } from "../combo-list.props";
import { UseEventHandlers } from "./types";
export function useEventHandlers(props: ComboListProps, context: SetupContext, modelValue: Ref<string | undefined>): UseEventHandlers {
function onClear($event: Event) {
modelValue.value = '';
}
return {
onClear
};
}