<vega-radio-group
name="fruit"
value="apple"
label="Select a fruit"
>
<vega-radio value="apple">
Apple
</vega-radio>
<vega-radio value="orange">
Orange
</vega-radio>
</vega-radio-group>
const radios = document.querySelector("vega-radio-group");
radios.vegaFlexProp = {
gap: "size-8",
direction: "col",
breakpoint: "None",
alignItem: "start",
justifyContent: "start",
margin: "0",
};
Note: The above example uses Vanilla JS. If you would like to use React, Angular, or Vue, please consult Storybook.
The vega-radio
component provides a selection field on a form where only one item may be selected. There are two main tokens: vega-radio-group
, which specifies the grouping of the options, and vega-radio
, which refers to the individual selection options.
vega-radio
) PropertiesName | Description | Default |
---|---|---|
value | The value of the selected radio. text | "" |
name | The name of the input in each radio. string | |
checked | Boolean value - indicates whether the radio is pre-checked. boolean for radio | false |
disabled | Boolean value - indicating if the input field is disabled. boolean for radio | false |
size | Radio have two sizes: default or small. They should be chosen to fit the context of the specific form. string |
default |
vega-radio-group
) PropertiesName | Description | Default |
---|---|---|
value | The value of the selected radio. text | "" |
name | The name of the input in each radio. string | |
disabled | Boolean value - indicating if the input field is disabled. boolean for radio | false |
label | The label of radio group. text | "" |
required | This is a Boolean operator which indicates whether the vega-radio-group is required. boolean | false |
form-validation | Updating the value of this property triggers the validation process. number | 0 |
hint | A prompt message to supplement the expected value of the radio group. string | |
vega-flex-prop | All properties of vega-flex components, you can find a full list here: https://heartlandpayments.github.io/Vega/?path=/docs/container-flex-v2—child-items-in-the-same-width#properties |
<vega-radio-group onVegaChange="function">
<vega-radio name="xxx" value="xxx" checked="true|false">Label</vega-radio>
<vega-radio name="xxx" value="xxx">Label</vega-radio>
... ...
<vega-radio-group></vega-radio-group
></vega-radio-group>
You can modify various flex attributes such as gap, direction, breakpoint, alignment, justification, and margin using the vegaFlexProp
object on the vega-radio-group
element. For example, to change the display direction of the radio group, change the direction from row
to col
.
const radios = document.querySelector('vega-radio-group');
radios.vegaFlexProp = {
gap: 'size-8',
direction: 'col',
breakpoint: 'None',
alignItem: 'start',
justifyContent: 'start',
margin: '0',
};
To choose which radio button is selected through vega-checkbox-group
, you will need to set the value
atttribute to be the specific radio.
For example:
document.querySelector('vega-radio-group').value = ['apple'];
Alternately, you can set the checked
property for the individual vega-radio
to be true.
To retrieve the value of a selected radio, you can use either of the following two methods:
vega-radioo-group
:var group = document.getElementById('radio-group-id');
console.log(group.value);
document.querySelector('input[name=xxx]:checked').value;
The following events are available in vega-radio
or vega-radio-group
:
document.getElementById("radio_group_id").addEventListener("vegaChange", (e) =>
{console.log(e.currentTarget.value) }) document.getElementById("radio_id").addEventListener("vegaChange",
(e)=> { console.log(e.currentTarget.value) })
vega-radio
or vega-radio-group
.document.getElementById("radio_group_id").addEventListener("vegaFocus", (e)
=>{console.log(e.currentTarget.value) }) document.getElementById("radio_id").addEventListener("vegaFocus",
(e)=> { console.log(e.currentTarget.value) })
document.getElementById("radio_group_id").addEventListener("vegaBlur", (e)
=>{console.log(e.currentTarget.value) }) document.getElementById("radio_id").addEventListener("vegaBlur", (e)
=>{ console.log(e.currentTarget.value) })
For more details, including examples for React or view in Storybook.
Do
Don't