diff --git a/docs/docs/resources/changelog.md b/docs/docs/resources/changelog.md index d268f38f6..f9a0b4508 100644 --- a/docs/docs/resources/changelog.md +++ b/docs/docs/resources/changelog.md @@ -17,6 +17,7 @@ During the alpha period, things might break! We take breaking changes very serio - Simplified the internal structure and CSS properties of ``, removed `base` part. - Added `appearance` to `` and `` - Fixed a bug in `` where it would not properly change its "checked" state when its property changed. +- Fixed a bug in `` where the value would be incorrectly submitted as "on" when a value is provided and the switch is checked - Fixed a bug in the `wa-split` CSS utility that caused it to behave incorrectly - Improved performance of `` when using a large number of options - Updated the Japanese translation diff --git a/src/components/switch/switch.test.ts b/src/components/switch/switch.test.ts index cd7d8ee32..209d8a070 100644 --- a/src/components/switch/switch.test.ts +++ b/src/components/switch/switch.test.ts @@ -20,8 +20,7 @@ describe('', () => { const el = await fixture(html` `); expect(el.name).to.equal(null); - // TODO - fix default value - // expect(el.value).to.be.null; + expect(el.value).to.equal('on'); expect(el.title).to.equal(''); expect(el.disabled).to.be.false; expect(el.required).to.be.false; @@ -138,10 +137,7 @@ describe('', () => { }); describe('when submitting a form', () => { - // - // TODO - this test should pass, so this is likely a bug in the component - // - it.skip('should submit the correct value when a value is provided', async () => { + it('should submit the correct value when a value is provided', async () => { const form = await fixture(html`
@@ -215,10 +211,7 @@ describe('', () => { expect(waSwitch.checkValidity()).to.be.true; }); - // - // TODO - this test should pass, so this is likely a bug in the component - // - it.skip('should be present in form data when using the form attribute and located outside of a ', async () => { + it('should be present in form data when using the form attribute and located outside of a ', async () => { const el = await fixture(html`
diff --git a/src/components/switch/switch.ts b/src/components/switch/switch.ts index bb2834364..d412b1a32 100644 --- a/src/components/switch/switch.ts +++ b/src/components/switch/switch.ts @@ -212,16 +212,11 @@ export default class WaSwitch extends WebAwesomeFormAssociatedElement { setValue(value: string | File | FormData | null, stateValue?: string | File | FormData | null | undefined): void { if (!this.checked) { - this.value = null; this.internals.setFormValue(null, null); return; } - if (!value) { - value = 'on'; - } - - this.internals.setFormValue(value, stateValue); + this.internals.setFormValue(value ?? 'on', stateValue); } formResetCallback(): void {