class RadioButtonMenuItem

Extends:
UIComponent, MenuItem

Description:

Radio button menu item UI component that extends MenuItem class.

RadioButton is a component used to select of multiple option by clicking on it.
Multiple RadioButton components must be grouped for selection to work as expected.
To group them pick one main RadioButtonMenuItem and group other RadioButtonMenuItem with it.
For example if you have three RadioButtonMenuItem components that you want to group, you must group second component with first one, then third component with any component that is already grouped (first or second).
Then to detect selection changes add onChange(e => {console.log(e.value);}) to only one of the grouped RadioButton components, and e.value will be the value of currently selected RadioButton.
See example below.

Constructor

constructor([text])

Constructor for Menu, MenuItem, CheckBoxMenuItem, and RadioButtonMenuItem.

Parameters:

Name Type Description

[text]

string

Text displayed in the menu item

Members

Methods

From this class:

Inherited from UIComponent:

Inherited from MenuItem:

Examples:

// Example how to group RadioButton components and detect when selected value of a group changes.

var fileMenu = new Menu("Options").addTo(menuBar);

// create first RadioButtonMenuItem and sets group value change handler function
mainForm.radio1 = new RadioButtonMenuItem("Option 1").addTo(fileMenu).onChange(e => {console.log(e.value);});

// create second RadioButtonMenuItem and group it with first one
mainForm.radio2 = new RadioButtonMenuItem("Option 2").addTo(fileMenu).groupWith(mainForm.radio1);

// create third RadioButtonMenuItem and group it with first one
mainForm.radio3 = new RadioButtonMenuItem("Option 3").addTo(fileMenu).groupWith(mainForm.radio1);

// now when user clicks on any of these radio buttons a new selected value will be logged in console.

Also See: