Radio Button
Radio buttons are used when the user needs to select one option from a set.
This UI component is best used when there is enough space, since all the options are visible at once. If you need to save space, a better UI choice would be the Dropdown, which only shows the selected item and the others are hidden after the selection.
Basic Usage
The following example will render a simple Radio button with a label.
<mbsc-radio value="1" name="myRadio" label="One"></mbsc-radio>
Radio buttons can be used individually or can be grouped logically inside a Radio Group component. The Radio Group component, also helps to specify the group name only once, otherwise it needs to be added to every radio button.
<mbsc-radio-group name="gender">
<mbsc-radio value="f" label="Female"></mbsc-radio>
<mbsc-radio value="m" label="Male"></mbsc-radio>
<mbsc-radio value="o" label="Other"></mbsc-radio>
</mbsc-radio-group>
Value binding
Radio buttons can be bound to a string value using either the [(ngModel)]
or the formControlName
directives.
These directives can be used individually on every radio button component or can be applied to the radio group.
<div>
<mbsc-radio name="age" value="adult" label="Adult (18+)"></mbsc-radio>
<mbsc-radio name="age" value="teen" label="Teen (13-18)"></mbsc-radio>
<mbsc-radio value="age" value="child" label="Child (4-13)"></mbsc-radio>
<mbsc-radio value="age" value="toddler" label="Toddler (1-4)"></mbsc-radio>
<mbsc-radio value="age" value="baby" label="Baby (0-1)"></mbsc-radio>
</div>
<mbsc-radio-group name="eye-color">
<mbsc-radio value="blue" label="Blue"></mbsc-radio>
<mbsc-radio value="brown" label="Brown"></mbsc-radio>
<mbsc-radio value="green" label="Green"></mbsc-radio>
<mbsc-radio value="grey" label="Grey"></mbsc-radio>
</mbsc-radio-group>
For many more examples - simple and complex use-cases - check out the radio button demos for angular.
Options
Name | Type | Default value | Description |
---|---|---|---|
color | String | undefined |
A predefined color to style the component. Supported values are:
|
description | String | undefined |
A description that shows up under the label of the component. |
disabled | Boolean | false |
Initial disabled state of the component. This will take no effect in inline display mode. |
label | String | undefined |
Sets the label of component. |
position | String | 'end' |
Sets the position of the switch handle depending on the RTL setting. It can be 'start' or 'end' . When in LTR mode, the 'start' will set the handle position to the left (a.k.a. from left to right the switch will start with the handle) and the 'end' will set it to the right - so the handle goes to the end of the switch.In RTL mode, the 'start' will position the hande to the right. The 'end' will position the handle to the left in this case.
|
rtl | Boolean | false |
Right to left display. |
theme | String | undefined |
Sets the visual appearance of the component.
If it is
Make sure that the theme you set is included in the downloaded package.
|
themeVariant | String | undefined |
Controls which variant of the theme will be used (light or dark). Possible values:
To use the option with custom themes, make sure to create two custom themes,
where the dark version has the same name as the light one, suffixed with |
value | String | undefined |
The value attribute is a string containing the Radio button's value. |
Customizing the appearance
While the provided pre-built themes are enough in many use cases, most of the times on top of adapting to a specific platform, you'd also like to match a brand or color scheme. Mobiscroll provides various ways to achieve this:
- Create custom themes using the theme builder - the custom themes can be also built using out theme builder, on a graphical user interface, without any coding, or the need for Sass support in your project.
- Create custom themes using Sass - use this, if you need multiple themes with different color variatons, in case you have pages with different colors, or you'd like to users to customize the colors of your app.
- Override the Sass color variables - the straightforward way to change the colors in one place throughout the application.
Override the Sass Color Variables
A convenient way to customize the colors of the Mobiscroll components is to override the Sass color variables.
Let's say your branding uses a nice red accent color, and you'd like that color to appear on the Mobiscroll components as well,
while still using platform specific themes (e.g. ios
on iOS devices, material
on Android devices, and mobiscroll
on desktop).
You can override the accent color for every theme:
$mbsc-ios-accent: #e61d2a;
$mbsc-material-accent: #e61d2a;
$mbsc-mobiscroll-accent: #e61d2a;
@import "~@mobiscroll/Angular/dist/css/mobiscroll.angular.scss"
You can also customize the colors on many levels:
- Theme specific variables (ex.
$mbsc-material-background
,$mbsc-ios-dark-text
) are applied to all components in a theme. Complete list of variables here. - Component specific global variables (ex.
$mbsc-card-background-light
,$mbsc-listview-text-dark
) are applied to all themes for a specific component. - Component and theme specific variables (ex.
$mbsc-ios-dark-form-background
,$mbsc-material-input-text
) are applied to a specific theme and a specific component.
For many more examples - simple and complex use-cases - check out the radio button demos for angular.