From b2cf3a550571d753fbf2c93cc24f1e188d983dce Mon Sep 17 00:00:00 2001 From: Alessandro Date: Tue, 28 Jun 2022 23:59:52 +0200 Subject: [PATCH] feat(form): add reset functionality (#799) * feat(form): add reset functionality * feat(interal): add defaultValue decorator * feat: add defaultValue and defaultChecked * chore: implement unit tests * chore: remove leftover --- docs/getting-started/form-controls.md | 4 + src/components/button/button.ts | 6 +- src/components/checkbox/checkbox.test.ts | 30 ++++++++ src/components/checkbox/checkbox.ts | 9 ++- .../color-picker/color-picker.test.ts | 32 +++++++- src/components/color-picker/color-picker.ts | 5 ++ src/components/input/input.test.ts | 32 +++++++- src/components/input/input.ts | 5 ++ .../radio-button/radio-button.test.ts | 32 ++++++++ src/components/radio-button/radio-button.ts | 9 ++- src/components/radio/radio.test.ts | 30 ++++++++ src/components/radio/radio.ts | 9 ++- src/components/range/range.test.ts | 74 +++++++++++++++++++ src/components/range/range.ts | 5 ++ src/components/select/select.test.ts | 29 ++++++++ src/components/select/select.ts | 5 ++ src/components/switch/switch.test.ts | 30 ++++++++ src/components/switch/switch.ts | 9 ++- src/components/textarea/textarea.test.ts | 32 +++++++- src/components/textarea/textarea.ts | 5 ++ src/internal/default-value.ts | 51 +++++++++++++ src/internal/form.ts | 41 ++++++++-- 22 files changed, 468 insertions(+), 16 deletions(-) create mode 100644 src/components/range/range.test.ts create mode 100644 src/internal/default-value.ts diff --git a/docs/getting-started/form-controls.md b/docs/getting-started/form-controls.md index 1065cc740..8c51f2f7f 100644 --- a/docs/getting-started/form-controls.md +++ b/docs/getting-started/form-controls.md @@ -65,6 +65,7 @@ To make a field required, use the `required` prop. The form will not be submitte
Check me before submitting

+ Reset Submit @@ -118,6 +119,7 @@ To restrict a value to a specific [pattern](https://developer.mozilla.org/en-US/

+ Reset Submit
@@ -161,6 +163,7 @@ Some input types will automatically trigger constraints, such as `email` and `ur

+ Reset Submit @@ -204,6 +207,7 @@ To create a custom validation error, pass a non-empty string to the `setCustomVa

+ Reset Submit
diff --git a/src/components/button/button.ts b/src/components/button/button.ts index 1000f496b..13e2d2eb1 100644 --- a/src/components/button/button.ts +++ b/src/components/button/button.ts @@ -83,7 +83,7 @@ export default class SlButton extends LitElement { * The type of button. When the type is `submit`, the button will submit the surrounding form. Note that the default * value is `button` instead of `submit`, which is opposite of how native `