From eb57723785ce5b05585bf48bf9c8ae1b62235ba2 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 29 Jan 2020 14:01:27 -0500 Subject: [PATCH] fix(radio): set default radio value if undefined (#20329) --- core/src/components/radio/radio.tsx | 3 + core/src/components/radio/test/radio.spec.ts | 11 ++++ .../radio/test/standalone/index.html | 56 +++++++------------ 3 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 core/src/components/radio/test/radio.spec.ts diff --git a/core/src/components/radio/radio.tsx b/core/src/components/radio/radio.tsx index af50f63fc6..9059cfc171 100644 --- a/core/src/components/radio/radio.tsx +++ b/core/src/components/radio/radio.tsx @@ -67,6 +67,9 @@ export class Radio implements ComponentInterface { @Event() ionBlur!: EventEmitter; connectedCallback() { + if (this.value === undefined) { + this.value = this.inputId; + } const radioGroup = this.radioGroup = this.el.closest('ion-radio-group'); if (radioGroup) { this.updateState(); diff --git a/core/src/components/radio/test/radio.spec.ts b/core/src/components/radio/test/radio.spec.ts new file mode 100644 index 0000000000..0a1f71e38f --- /dev/null +++ b/core/src/components/radio/test/radio.spec.ts @@ -0,0 +1,11 @@ +import { Radio } from '../radio.tsx'; + +describe('ion-radio', () => { + it('should set a default value', async () => { + const radio = new Radio(); + + await radio.connectedCallback(); + + expect(radio.value).toEqual('ion-rb-0'); + }); +}); \ No newline at end of file diff --git a/core/src/components/radio/test/standalone/index.html b/core/src/components/radio/test/standalone/index.html index 1bc6d8e460..0c4420943c 100644 --- a/core/src/components/radio/test/standalone/index.html +++ b/core/src/components/radio/test/standalone/index.html @@ -13,9 +13,9 @@

Default

- - + +

Colors: Unchecked

@@ -30,49 +30,33 @@

Colors: Checked

- - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + +

Disabled

- - - + + +

Custom

- - - + + - - + + +