Skip to content

Commit

Permalink
Deprecate number field change event
Browse files Browse the repository at this point in the history
  • Loading branch information
seggewiss committed May 28, 2024
1 parent d60aad5 commit 8b4ac57
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .changeset/violet-carrots-watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
"@shopware-ag/meteor-component-library": patch
---

Fix number field event
# Fix number field events
- Deprecated `change` event for `mt-number-field`
- Added `update:modelValue` event to `mt-number-field`
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const TestInputValue: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("42");

expect(args.change).toHaveBeenCalledWith(42);
expect(args.updateModelValue).toHaveBeenCalledWith(42);
},
};
Expand All @@ -40,6 +41,7 @@ export const TestIncreaseByKeyStroke: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("11");

expect(args.change).toHaveBeenCalledWith(11);
expect(args.updateModelValue).toHaveBeenCalledWith(11);
},
};
Expand All @@ -58,6 +60,7 @@ export const TestIncreaseByControl: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("11");

expect(args.change).toHaveBeenCalledWith(11);
expect(args.updateModelValue).toHaveBeenCalledWith(11);
},
};
Expand All @@ -78,6 +81,7 @@ export const TestDecreaseByKeyStroke: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("9");

expect(args.change).toHaveBeenCalledWith(9);
expect(args.updateModelValue).toHaveBeenCalledWith(9);
},
};
Expand All @@ -97,6 +101,7 @@ export const TestDecreaseByControl: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("9");

expect(args.change).toHaveBeenCalledWith(9);
expect(args.updateModelValue).toHaveBeenCalledWith(9);
},
};
Expand All @@ -120,6 +125,7 @@ export const TestStepIncrease: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("11.40");

expect(args.change).toHaveBeenCalledWith(11.4);
expect(args.updateModelValue).toHaveBeenCalledWith(11.4);
},
};
Expand All @@ -141,6 +147,7 @@ export const TestDecreaseConsidersMin: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("10");

expect(args.change).toHaveBeenCalledWith(10);
expect(args.updateModelValue).toHaveBeenCalledWith(10);
},
};
Expand All @@ -162,6 +169,7 @@ export const TestIncreaseConsiderMax: MtNumberFieldStory = {
// Notice that the value is of type string and the value of the event is of type number
expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe("10");

expect(args.change).toHaveBeenCalledWith(10);
expect(args.updateModelValue).toHaveBeenCalledWith(10);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type MtNumberFieldMeta = SlottedMeta<
| "inheritanceRemove"
| "inheritanceRestore"
| "isInherited"
| "change"
| "updateModelValue"
| "modelValue"
| "hint"
Expand All @@ -26,6 +27,7 @@ export default {
<mt-number-field
v-bind="args"
v-model="currentValue"
@change="args.change"
@update:modelValue="args.updateModelValue"
@inheritance-restore="inheritanceRestoreWrapper"
@inheritance-remove="inheritanceRemoveWrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export default defineComponent({
// @ts-expect-error - target exists
this.computeValue(event.target.value);
/** @deprecated tag: 5.0 - Will be removed use update:model-value instead */
this.$emit("change", this.currentValue);
this.$emit("update:modelValue", this.currentValue);
},
Expand All @@ -260,6 +263,10 @@ export default defineComponent({
}
this.computeValue((this.currentValue + this.realStep).toString());
/** @deprecated tag: 5.0 - Will be removed use update:model-value instead */
this.$emit("change", this.currentValue);
this.$emit("update:modelValue", this.currentValue);
},
Expand All @@ -270,6 +277,10 @@ export default defineComponent({
// @ts-expect-error - wrong type because of component extends
this.computeValue((this.currentValue - this.realStep).toString());
/** @deprecated tag: 5.0 - Will be removed use update:model-value instead */
this.$emit("change", this.currentValue);
this.$emit("update:modelValue", this.currentValue);
},
Expand Down

0 comments on commit 8b4ac57

Please sign in to comment.