Skip to content

Commit

Permalink
[duoyun-ui] Fixed <dy-form> dup change event
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Jan 24, 2024
1 parent 2140dd2 commit 0794366
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/duoyun-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "duoyun-ui",
"version": "1.1.16",
"version": "1.1.17",
"description": "A lightweight desktop UI component library, implemented using Gem",
"keywords": [
"frontend",
Expand Down
21 changes: 8 additions & 13 deletions packages/duoyun-ui/src/elements/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,43 +285,38 @@ export class DuoyunFormItemElement extends GemElement<FormItemState> {
constructor() {
super();
this.addEventListener('change', (evt: CustomEvent) => {
if (!this.name) {
evt.stopPropagation();
}
evt.stopPropagation();
if (this.#type === 'slot') {
this.#change(evt.detail);
this.#itemchange(evt.detail);
}
});
}

#change = (value: number | string | any[] | any) => {
#itemchange = (value: number | string | any[] | any) => {
if (this.name) {
this.itemchange({ name: this.name, value });
}
};

#onChange = (evt: CustomEvent<any>) => {
evt.stopPropagation();
this.#change(evt.detail);
this.#itemchange(evt.detail);
};

#onCheckboxChange = (evt: CustomEvent<boolean>) => {
evt.stopPropagation();
this.#change(this.value ? (evt.detail ? this.value : '') : evt.detail);
this.#itemchange(this.value ? (evt.detail ? this.value : '') : evt.detail);
};

#onTextChangeWithIndex = (evt: CustomEvent<string>, index: number) => {
evt.stopPropagation();
const value = (this.value || []) as string[];
this.#change([...value.slice(0, index), evt.detail, ...value.slice(index + 1)]);
this.#itemchange([...value.slice(0, index), evt.detail, ...value.slice(index + 1)]);
};

#onTextCleanWithIndex = async (index: number) => {
this.#change(((this.value || []) as string[]).filter((_, i) => i !== index));
this.#itemchange(((this.value || []) as string[]).filter((_, i) => i !== index));
};

#onTextAdd = async () => {
this.#change([...((this.value || []) as string[]), '']);
this.#itemchange([...((this.value || []) as string[]), '']);
};

mounted = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/patterns/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type FormItemProps<T = unknown> = {
required?: boolean;
rules?: DuoyunFormItemElement['rules'];

slot?: TemplateResult;
slot?: TemplateResult | HTMLElement | HTMLElement[];
};

export type FormItem<T = unknown> =
Expand Down

0 comments on commit 0794366

Please sign in to comment.